Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit dee891a

Browse files
authored
Merge pull request #105 from Venafi/contacts-support
Added ability to set Users as contact/owners of the policy when created/updated
2 parents 9e0c07e + 5abd6b1 commit dee891a

36 files changed

Lines changed: 793 additions & 468 deletions

src/main/java/com/venafi/vcert/sdk/connectors/Connector.java

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,17 @@
77
import com.venafi.vcert.sdk.certificate.PEMCollection;
88
import com.venafi.vcert.sdk.certificate.RenewalRequest;
99
import com.venafi.vcert.sdk.certificate.RevocationRequest;
10-
import com.venafi.vcert.sdk.certificate.SshCaTemplateRequest;
11-
import com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails;
12-
import com.venafi.vcert.sdk.certificate.SshCertificateRequest;
13-
import com.venafi.vcert.sdk.certificate.SshConfig;
1410
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException;
1511
import com.venafi.vcert.sdk.endpoint.Authentication;
1612
import com.venafi.vcert.sdk.endpoint.ConnectorType;
17-
import com.venafi.vcert.sdk.policy.domain.PolicySpecification;
1813

1914

2015
/**
2116
*
2217
* This represents the connector to TPP or Cloud
2318
*
2419
*/
25-
public interface Connector {
20+
public interface Connector extends ISSHConnector, IPMConnector{
2621

2722
Authentication getCredentials();
2823

@@ -66,7 +61,7 @@ public interface Connector {
6661
void ping() throws VCertException;
6762

6863
/**
69-
* This is the default implementation which provides an mechanism to authenticate the credentials
64+
* This is the default implementation which provides a mechanism to authenticate the credentials
7065
* provided in the {@link Authentication} object.
7166
* Behind the scene, it's validating if the credentials were provided calling the
7267
* {@link #isEmptyCredentials(Authentication)} method and if that returns true, then a {@link MissingCredentialsException}
@@ -177,62 +172,4 @@ String requestCertificate(CertificateRequest request, String zone)
177172
* @throws VCertException
178173
*/
179174
ImportResponse importCertificate(ImportRequest request) throws VCertException;
180-
181-
/**
182-
* Reads the policy configuration for a specific zone in Venafi
183-
*
184-
* @param zone
185-
* @return
186-
* @throws VCertException
187-
*/
188-
Policy readPolicyConfiguration(String zone) throws VCertException;
189-
190-
/**
191-
* Create/update a policy based on the policySpecification passed as argument.
192-
*
193-
* @param policyName
194-
* @param policySpecification
195-
* @throws VCertException
196-
*/
197-
void setPolicy(String policyName, PolicySpecification policySpecification) throws VCertException;
198-
199-
/**
200-
* Returns the policySpecification from the policy which matches with the policyName argument.
201-
*
202-
* @param policyName
203-
* @return
204-
* @throws VCertException
205-
*/
206-
PolicySpecification getPolicy(String policyName) throws VCertException;
207-
208-
/**
209-
* Request a new SSH Certificate.
210-
* @param sshCertificateRequest The {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest} instance needed to do the request.
211-
* For more information about of which properties should be filled, please review the documentation of
212-
* {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest}.
213-
* @return The DN of the created SSH certificate object. It can be used as pickup ID to retrieve the created SSH Certificate.
214-
* For more details review the {@link #retrieveSshCertificate(SshCertificateRequest) retrieveSshCertificate(SshCertificateRequest)} method.
215-
* @throws VCertException
216-
*/
217-
String requestSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException;
218-
219-
/**
220-
* Retrieve a requested SSH Certificate
221-
* @param sshCertificateRequest The {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest} instance needed to do the request.
222-
* <br>It's mandatory to set the PickUpID which is the value of the DN returned when the SSH Certificate was requested.
223-
* For more information about of which properties should be filled, please review the documentation of
224-
* {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest}.
225-
* @return A {@link com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails SshCertRetrieveDetails} containing the Certificate Data of the created Certificate.
226-
* @throws VCertException
227-
*/
228-
SshCertRetrieveDetails retrieveSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException;
229-
230-
/**
231-
* Retrieve the {@link com.venafi.vcert.sdk.certificate.SshConfig SshConfig} of the CA specified in the
232-
* {@link com.venafi.vcert.sdk.certificate.SshCaTemplateRequest SshCaTemplateRequest}.
233-
* @param sshCaTemplateRequest
234-
* @return A {@link com.venafi.vcert.sdk.certificate.SshConfig SshConfig}.
235-
* @throws VCertException
236-
*/
237-
SshConfig retrieveSshConfig(SshCaTemplateRequest sshCaTemplateRequest) throws VCertException;
238175
}

src/main/java/com/venafi/vcert/sdk/connectors/ConnectorException.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.venafi.vcert.sdk.VCertException;
1313
import com.venafi.vcert.sdk.certificate.CsrOriginOption;
14+
import com.venafi.vcert.sdk.connectors.tpp.endpoint.IdentityEntry;
1415

1516
/**
1617
* @author Marcos E. Albornoz Abud
@@ -307,8 +308,7 @@ public CertificateRejectedException(String pickupId, String status) {
307308
this.status = status;
308309
}
309310
}
310-
311-
311+
312312
public static class CertificateDNOrThumbprintWasNotProvidedException extends ConnectorException {
313313

314314
private static final long serialVersionUID = 1L;
@@ -492,4 +492,55 @@ public KeyStoreZipCompressionRatioExceeded(String certificateId, String fileName
492492
}
493493
}
494494

495+
public static class VaaSApplicationNotFoundException extends ConnectorException {
496+
497+
private static final long serialVersionUID = 1L;
498+
private static final String message = "Application with name %s could not be found on VaaS account";
499+
500+
public VaaSApplicationNotFoundException(String appName) {
501+
super(format(message, appName));
502+
}
503+
504+
}
505+
506+
public static class MissingTppIdentityException extends ConnectorException {
507+
508+
private static final long serialVersionUID = 1L;
509+
private static final String message = "TPP Identity cannot be null";
510+
511+
public MissingTppIdentityException() {
512+
super(message);
513+
}
514+
}
515+
516+
public static class IdentityExtraneousInformationException extends ConnectorException {
517+
518+
private static final long serialVersionUID = 1L;
519+
private static final String message = "Extraneous information returned in the identity response. Expected: 1, " +
520+
"found: %s.\t\n%s";
521+
522+
public IdentityExtraneousInformationException(IdentityEntry[] identityList) {
523+
super(format(message, identityList.length, get_bad_data(identityList)));
524+
}
525+
526+
private static String get_bad_data(IdentityEntry[] identityList) {
527+
StringBuilder bad_data = new StringBuilder();
528+
for (IdentityEntry entry : identityList) {
529+
bad_data.append(entry.toString()).append("\n");
530+
}
531+
532+
return bad_data.toString();
533+
}
534+
}
535+
536+
public static class TppContactException extends ConnectorException {
537+
538+
private static final long serialVersionUID = 1L;
539+
private static final String message = "Error while retrieving contact attribute from policy %s:\nError: %s";
540+
541+
public TppContactException(String policy, String error) {
542+
super(format(message, policy, error));
543+
}
544+
}
545+
495546
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.venafi.vcert.sdk.connectors;
2+
3+
import com.venafi.vcert.sdk.VCertException;
4+
import com.venafi.vcert.sdk.policy.domain.PolicySpecification;
5+
6+
public interface IPMConnector {
7+
8+
/**
9+
* Reads the policy configuration for a specific zone in Venafi
10+
*
11+
* @param zone
12+
* @return
13+
* @throws VCertException
14+
*/
15+
Policy readPolicyConfiguration(String zone) throws VCertException;
16+
17+
/**
18+
* Create/update a policy based on the policySpecification passed as argument.
19+
*
20+
* @param policyName
21+
* @param policySpecification
22+
* @throws VCertException
23+
*/
24+
void setPolicy(String policyName, PolicySpecification policySpecification) throws VCertException;
25+
26+
/**
27+
* Returns the policySpecification from the policy which matches with the policyName argument.
28+
*
29+
* @param policyName
30+
* @return
31+
* @throws VCertException
32+
*/
33+
PolicySpecification getPolicy(String policyName) throws VCertException;
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.venafi.vcert.sdk.connectors;
2+
3+
import com.venafi.vcert.sdk.VCertException;
4+
import com.venafi.vcert.sdk.certificate.SshCaTemplateRequest;
5+
import com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails;
6+
import com.venafi.vcert.sdk.certificate.SshCertificateRequest;
7+
import com.venafi.vcert.sdk.certificate.SshConfig;
8+
9+
public interface ISSHConnector {
10+
11+
/**
12+
* Request a new SSH Certificate.
13+
* @param sshCertificateRequest The {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest} instance needed to do the request.
14+
* For more information about of which properties should be filled, please review the documentation of
15+
* {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest}.
16+
* @return The DN of the created SSH certificate object. It can be used as pickup ID to retrieve the created SSH Certificate.
17+
* For more details review the {@link #retrieveSshCertificate(SshCertificateRequest) retrieveSshCertificate(SshCertificateRequest)} method.
18+
* @throws VCertException
19+
*/
20+
String requestSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException;
21+
22+
/**
23+
* Retrieve a requested SSH Certificate
24+
* @param sshCertificateRequest The {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest} instance needed to do the request.
25+
* <br>It's mandatory to set the PickUpID which is the value of the DN returned when the SSH Certificate was requested.
26+
* For more information about of which properties should be filled, please review the documentation of
27+
* {@link com.venafi.vcert.sdk.certificate.SshCertificateRequest SshCertificateRequest}.
28+
* @return A {@link com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails SshCertRetrieveDetails} containing the Certificate Data of the created Certificate.
29+
* @throws VCertException
30+
*/
31+
SshCertRetrieveDetails retrieveSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException;
32+
33+
/**
34+
* Retrieve the {@link com.venafi.vcert.sdk.certificate.SshConfig SshConfig} of the CA specified in the
35+
* {@link com.venafi.vcert.sdk.certificate.SshCaTemplateRequest SshCaTemplateRequest}.
36+
* @param sshCaTemplateRequest
37+
* @return A {@link com.venafi.vcert.sdk.certificate.SshConfig SshConfig}.
38+
* @throws VCertException
39+
*/
40+
SshConfig retrieveSshConfig(SshCaTemplateRequest sshCaTemplateRequest) throws VCertException;
41+
}

src/main/java/com/venafi/vcert/sdk/connectors/cloud/Cloud.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99

1010
import com.venafi.vcert.sdk.Config;
1111
import com.venafi.vcert.sdk.certificate.CertificateStatus;
12-
import com.venafi.vcert.sdk.connectors.cloud.domain.Application;
13-
import com.venafi.vcert.sdk.connectors.cloud.domain.CertificateDetails;
14-
import com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate;
15-
import com.venafi.vcert.sdk.connectors.cloud.domain.EdgeEncryptionKey;
16-
import com.venafi.vcert.sdk.connectors.cloud.domain.UserDetails;
12+
import com.venafi.vcert.sdk.connectors.cloud.domain.*;
1713
import com.venafi.vcert.sdk.connectors.cloud.endpoint.*;
1814
import com.venafi.vcert.sdk.utils.FeignUtils;
1915

@@ -110,6 +106,18 @@ Response retrieveCertificate(@Param("id") String id, @Param("apiKey") String api
110106
@RequestLine("POST /outagedetection/v1/certificates/{id}/keystore")
111107
Response retrieveKeystore(@Param("id") String id, KeystoreRequest keystoreRequest, @Param("apiKey") String apiKey);
112108

109+
@Headers({"tppl-api-key: {apiKey}", "Content-Type: application/json"})
110+
@RequestLine("GET /v1/users/username/{username}")
111+
UserResponse retrieveUser(@Param("username") String username, @Param("apiKey") String apiKey);
112+
113+
@Headers({"tppl-api-key: {apiKey}", "Content-Type: application/json"})
114+
@RequestLine("GET /v1/users/{id}")
115+
User retrieveUserById(@Param("id") String id, @Param("apiKey") String apiKey);
116+
117+
@Headers({"tppl-api-key: {apiKey}", "Content-Type: application/json"})
118+
@RequestLine("GET /v1/teams")
119+
Teams retrieveTeams(@Param("apiKey") String apiKey);
120+
113121
static Cloud connect() {
114122
return connect((Config)null);
115123
}

src/main/java/com/venafi/vcert/sdk/connectors/cloud/CloudConnector.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
import lombok.Getter;
5959

6060
public class CloudConnector implements Connector {
61-
62-
private static String APPLICATION_SERVER_TYPE_ID = "784938d1-ef0d-11eb-9461-7bb533ba575b";
6361

64-
private Cloud cloud;
62+
private static final String APPLICATION_SERVER_TYPE_ID = "784938d1-ef0d-11eb-9461-7bb533ba575b";
63+
64+
private final Cloud cloud;
6565

6666
@Getter
6767
private UserDetails user;
@@ -124,12 +124,8 @@ public boolean isEmptyCredentials(Authentication credentials) {
124124
if(credentials == null){
125125
return true;
126126
}
127-
128-
if( isBlank(credentials.apiKey())) {
129-
return true;
130-
}
131127

132-
return false;
128+
return isBlank(credentials.apiKey());
133129
}
134130

135131
/**
@@ -155,9 +151,9 @@ public void authorize(Authentication credentials) throws VCertException {
155151
@Override
156152
public ZoneConfiguration readZoneConfiguration(String zone) throws VCertException {
157153

158-
String valies[] = StringUtils.split(zone, "\\");
159-
String appName = valies[0];
160-
String citAlias = valies[1];
154+
String[] values = StringUtils.split(zone, "\\");
155+
String appName = values[0];
156+
String citAlias = values[1];
161157

162158
CertificateIssuingTemplate cit = null;
163159

@@ -584,7 +580,8 @@ public Policy readPolicyConfiguration(String zone) throws VCertException {
584580
public void setPolicy(String policyName, PolicySpecification policySpecification) throws VCertException {
585581
try {
586582
CloudPolicy cloudPolicy = CloudPolicySpecificationConverter.INSTANCE.convertFromPolicySpecification(policySpecification);
587-
CloudConnectorUtils.setCit(policyName, cloudPolicy.certificateIssuingTemplate(), cloudPolicy.caInfo(), credentials.apiKey(), cloud);
583+
CloudConnectorUtils.setCit(policyName, cloudPolicy.certificateIssuingTemplate(), cloudPolicy.caInfo(),
584+
cloudPolicy.owners(), credentials.apiKey(), cloud);
588585
} catch ( Exception e ) {
589586
throw new VCertException(e);
590587
}
@@ -641,7 +638,7 @@ private String[] parseZoneIdentifiers(String zone) throws VCertException {
641638
return new String[] {zone, null, null};
642639
} catch (IllegalArgumentException iae) {
643640
// The zone argument is not UUID, so we expect to be ProjectName\ZoneName
644-
String zoneParsed[] = zone.split(Pattern.quote("\\"));
641+
String[] zoneParsed = zone.split(Pattern.quote("\\"));
645642

646643
if (zoneParsed.length != 2) {
647644
throw new VCertException(format(
@@ -662,8 +659,6 @@ private String[] parseZoneIdentifiers(String zone) throws VCertException {
662659

663660
@Data
664661
public static class CertificateRequestsPayload {
665-
// private String companyId;
666-
// private String downloadFormat;
667662
@SerializedName("certificateSigningRequest")
668663
private String csr;
669664
private String zoneId;

0 commit comments

Comments
 (0)