Skip to content

Commit

Permalink
feat: [CO-486] Add Domain SSL certificate info SOAP API Endpoint (#136)
Browse files Browse the repository at this point in the history
* feat: [CO-486] add GetDomainCertRequest, GetDomainCertResponse, modify CertInfo

* feat: [CO-486] add constants to CertMgrConstants, format request and response

* feat: [CO-486] add setters in CertInfo

* feat: [CO-486] code format

* feat: [CO-486] changed domain name for domain id in GetDomainCertRequest
  • Loading branch information
aheeva-yuliya authored Jan 13, 2023
1 parent 584ae51 commit fb303c5
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 16 deletions.
11 changes: 11 additions & 0 deletions common/src/main/java/com/zimbra/common/soap/CertMgrConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public final class CertMgrConstants {
// ZimbraCertMgrService
public static final String E_INSTALL_CERT_REQUEST = "InstallCertRequest";
public static final String E_INSTALL_CERT_RESPONSE = "InstallCertResponse";
public static final String E_GET_DOMAIN_CERT_REQUEST = "GetDomainCertRequest";
public static final String E_GET_DOMAIN_CERT_RESPONSE = "GetDomainCertResponse";
public static final String E_GET_CERT_REQUEST = "GetCertRequest";
public static final String E_GET_CERT_RESPONSE = "GetCertResponse";
public static final String E_GEN_CSR_REQUEST = "GenCSRRequest";
Expand All @@ -30,6 +32,10 @@ public final class CertMgrConstants {

public static final QName INSTALL_CERT_REQUEST = QName.get(E_INSTALL_CERT_REQUEST, NAMESPACE);
public static final QName INSTALL_CERT_RESPONSE = QName.get(E_INSTALL_CERT_RESPONSE, NAMESPACE);
public static final QName GET_DOMAIN_CERT_REQUEST =
QName.get(E_GET_DOMAIN_CERT_REQUEST, NAMESPACE);
public static final QName GET_DOMAIN_CERT_RESPONSE =
QName.get(E_GET_DOMAIN_CERT_RESPONSE, NAMESPACE);
public static final QName GET_CERT_REQUEST = QName.get(E_GET_CERT_REQUEST, NAMESPACE);
public static final QName GET_CERT_RESPONSE = QName.get(E_GET_CERT_RESPONSE, NAMESPACE);
public static final QName GEN_CSR_REQUEST = QName.get(E_GEN_CSR_REQUEST, NAMESPACE);
Expand Down Expand Up @@ -71,6 +77,11 @@ public final class CertMgrConstants {
// GetCert
public static final String A_OPTION = "option";

//GetDomainCert
public static final String E_ISSUER = "issuer";
public static final String E_NOT_BEFORE = "notBefore";
public static final String E_NOT_AFTER = "notAfter";

// GetCSR
public static final String A_csr_exists = "csr_exists";
public static final String A_isComm = "isComm";
Expand Down
2 changes: 2 additions & 0 deletions soap/src/main/java/com/zimbra/soap/JaxbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ public final class JaxbUtil {
com.zimbra.soap.admin.message.GetDistributionListMembershipResponse.class,
com.zimbra.soap.admin.message.GetDistributionListRequest.class,
com.zimbra.soap.admin.message.GetDistributionListResponse.class,
com.zimbra.soap.admin.message.GetDomainCertRequest.class,
com.zimbra.soap.admin.message.GetDomainCertResponse.class,
com.zimbra.soap.admin.message.GetDomainInfoRequest.class,
com.zimbra.soap.admin.message.GetDomainInfoResponse.class,
com.zimbra.soap.admin.message.GetDomainRequest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.zimbra.soap.admin.message;

import com.google.common.base.MoreObjects;
import com.zimbra.common.soap.AdminConstants;
import com.zimbra.common.soap.CertMgrConstants;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
* @zm-api-command-auth-required true
* @zm-api-command-admin-auth-required true
* @zm-api-command-description Get Domain Certificate <br>
* Gets the certificate of a requested domain.
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = CertMgrConstants.E_GET_DOMAIN_CERT_REQUEST)
public class GetDomainCertRequest {

/**
* @zm-api-field-tag domain id
* @zm-api-field-description a domain id whose cert is to be got
*/
@XmlAttribute(name = AdminConstants.A_DOMAIN /* domain */, required = true)
private String domain;

/** no-argument constructor wanted by JAXB */
@SuppressWarnings("unused")
private GetDomainCertRequest() {
this(null);
}

public GetDomainCertRequest(String domain) {
this.domain = domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

public String getDomain() {
return domain;
}

public MoreObjects.ToStringHelper addToStringInfo(MoreObjects.ToStringHelper helper) {
return helper.add("domain", domain);
}

@Override
public String toString() {
return addToStringInfo(MoreObjects.toStringHelper(this)).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.zimbra.soap.admin.message;

import com.google.common.base.MoreObjects;
import com.zimbra.common.soap.AdminConstants;
import com.zimbra.common.soap.CertMgrConstants;
import com.zimbra.soap.admin.type.CertInfo;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = CertMgrConstants.E_GET_DOMAIN_CERT_RESPONSE)
@XmlType(propOrder = {})
public class GetDomainCertResponse {

/**
* @zm-api-field-description Certificate information
*/
@XmlElement(name = CertMgrConstants.E_cert /* cert */, required = false)
private CertInfo cert;

/**
* @zm-api-field-tag domain-name
* @zm-api-field-description Domain name
*/
@XmlAttribute(name = AdminConstants.A_DOMAIN /* domain */, required = false)
private String domain;

public GetDomainCertResponse() {}

public void setCert(CertInfo cert) {
this.cert = cert;
}

public void setDomain(String domain) {
this.domain = domain;
}

public CertInfo getCert() {
return cert;
}

public String getDomain() {
return domain;
}

public MoreObjects.ToStringHelper addToStringInfo(MoreObjects.ToStringHelper helper) {
return helper
.add(AdminConstants.A_DOMAIN, domain)
.add(CertMgrConstants.E_cert, cert);
}

@Override
public String toString() {
return addToStringInfo(MoreObjects.toStringHelper(this)).toString();
}
}
35 changes: 19 additions & 16 deletions soap/src/main/java/com/zimbra/soap/admin/type/CertInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import com.zimbra.common.soap.CertMgrConstants;
import java.util.Collections;
import java.util.List;

Expand All @@ -27,49 +28,49 @@ public class CertInfo {
* @zm-api-field-tag server-name
* @zm-api-field-description Server name
*/
@XmlAttribute(name=AdminConstants.A_SERVER /* server */, required=true)
private final String server;
@XmlAttribute(name=AdminConstants.A_SERVER /* server */, required=false)
private String server;

/**
* @zm-api-field-tag type
* @zm-api-field-description type - 1 of <b>mta|ldap|mailboxd|proxy|staged</b>
*/
@XmlAttribute(name=AdminConstants.A_TYPE /* type */, required=true)
private final String type;
@XmlAttribute(name=AdminConstants.A_TYPE /* type */, required=false)
private String type;

/**
* @zm-api-field-tag subject
* @zm-api-field-description C, ST, L, O, OU, CN of current cert
*/
@XmlElement(name="subject", required=false)
@XmlElement(name= CertMgrConstants.E_SUBJECT, required=false)
private String subject;

/**
* @zm-api-field-tag issuer
* @zm-api-field-description C, ST, L, O, OU, CN of issuer cert
*/
@XmlElement(name="issuer", required=false)
@XmlElement(name=CertMgrConstants.E_ISSUER, required=false)
private String issuer;

/**
* @zm-api-field-tag notBefore
* @zm-api-field-description Certificate validation start time
*/
@XmlElement(name="notBefore", required=false)
@XmlElement(name=CertMgrConstants.E_NOT_BEFORE, required=false)
private String notBefore;

/**
* @zm-api-field-tag notAfter
* @zm-api-field-description Certificate validation end time
*/
@XmlElement(name="notAfter", required=false)
@XmlElement(name=CertMgrConstants.E_NOT_AFTER, required=false)
private String notAfter;

/**
* @zm-api-field-tag SubjectAltName
* @zm-api-field-description Current cert's subject alternative name (as x509v3 Extension)
*/
@XmlElement(name="SubjectAltName", required=false)
@XmlElement(name=CertMgrConstants.E_SUBJECT_ALT_NAME, required=false)
private String SubjectAltName;

// Expect elements with text content only
Expand All @@ -92,6 +93,8 @@ public CertInfo(String server, String type) {
this.type = type;
}

public void setServer(String server) { this.server = server; }
public void setType(String type) { this.type = type; }
public void setSubject(String subject) { this.subject = subject; }
public void setIssuer(String issuer) { this.issuer = issuer; }
public void setNotBefore(String notBefore) { this.notBefore = notBefore; }
Expand Down Expand Up @@ -122,13 +125,13 @@ public List<org.w3c.dom.Element> getCertInfos() {
public MoreObjects.ToStringHelper addToStringInfo(
MoreObjects.ToStringHelper helper) {
return helper
.add("server", server)
.add("type", type)
.add("subject", subject)
.add("issuer", issuer)
.add("notBefore", notBefore)
.add("notAfter", notAfter)
.add("SubjectAltName", SubjectAltName)
.add(AdminConstants.A_SERVER, server)
.add(AdminConstants.A_TYPE, type)
.add(CertMgrConstants.E_SUBJECT, subject)
.add(CertMgrConstants.E_ISSUER, issuer)
.add(CertMgrConstants.E_NOT_BEFORE, notBefore)
.add(CertMgrConstants.E_NOT_AFTER, notAfter)
.add(CertMgrConstants.E_SUBJECT_ALT_NAME, SubjectAltName)
.add("certInfos", certInfos);
}

Expand Down

0 comments on commit fb303c5

Please sign in to comment.