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

Commit 482b73a

Browse files
committed
Added specific exceptions for Contacts feature
1 parent ac0baf8 commit 482b73a

5 files changed

Lines changed: 62 additions & 14 deletions

File tree

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
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.venafi.vcert.sdk.certificate.ChainOption;
66
import com.venafi.vcert.sdk.certificate.DataFormat;
77
import com.venafi.vcert.sdk.certificate.PEMCollection;
8+
import com.venafi.vcert.sdk.connectors.ConnectorException;
89
import com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreUnzipedFilesBytesSizeExceeded;
910
import com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreZipCompressionRatioExceeded;
1011
import com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreZipEntriesExceeded;
@@ -260,7 +261,7 @@ private static String[] resolveCloudOwnersNames(String policyName, String apiKey
260261

261262
Application app = cloud.applicationByName(zone.appName(), apiKey);
262263
if (app == null){
263-
throw new VCertException("Application "+ zone.appName() + " could not be found");
264+
throw new ConnectorException.VaaSApplicationNotFoundException(zone.appName());
264265
}
265266
List<String> usersList = new ArrayList<>();
266267
Teams tResponse = null;

src/main/java/com/venafi/vcert/sdk/connectors/tpp/AbstractTppConnector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ protected String[] resolveTPPContacts(String[] contacts) throws VCertException{
136136

137137
public IdentityEntry getTPPIdentity(String username) throws VCertException{
138138
if (username == null){
139-
throw new VCertException("Identity string cannot be null");
139+
throw new MissingTppIdentityException();
140140
}
141141

142142
BrowseIdentitiesResponse response = getTppAPI().browseIdentities(new BrowseIdentitiesRequest(username, 2,
143143
BrowseIdentitiesRequest.ALL_IDENTITIES));
144144

145145
if (response.identities().length > 1){
146-
throw new VCertException("Extraneous information returned in the identity response. "
147-
+ "Expected size: 1, found: 2\n" + response.identities()[1].toString());
146+
throw new IdentityExtraneousInformationException(response.identities());
148147
}
149148

150149
IdentityEntry identity = response.identities()[0];

src/main/java/com/venafi/vcert/sdk/connectors/tpp/TppConnectorUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.venafi.vcert.sdk.VCertException;
66
import com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails;
77
import com.venafi.vcert.sdk.certificate.SshCertificateRequest;
8+
import com.venafi.vcert.sdk.connectors.ConnectorException;
89
import com.venafi.vcert.sdk.connectors.tpp.endpoint.*;
910
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRequest;
1011
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest;
@@ -327,7 +328,7 @@ private static String[] retrieveUsernamesFromTPPContacts(String policyName, TppA
327328
throw new VCertException(e);
328329
}
329330
if (contactResponse != null && contactResponse.error() != null){
330-
throw new VCertException(contactResponse.error());
331+
throw new ConnectorException.TppContactException(policyName, contactResponse.error());
331332
}
332333
if (contactResponse.values() != null) {
333334
Object[] contacts = contactResponse.values();

src/test/java/com/venafi/vcert/sdk/connectors/tpp/TppTokenConnectorPolicyAT.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ public class TppTokenConnectorPolicyAT {
2323
@Test
2424
@DisplayName("TPP - Retrieve an Identity by username")
2525
public void browseIdentities() throws VCertException {
26-
try{
27-
IdentityEntry identity = connectorResource.connector().getTPPIdentity(username);
28-
Assertions.assertEquals(username, identity.name());
29-
prefixedUniversal = identity.prefixedUniversal();
30-
} catch (Exception e){
31-
System.out.println("");
32-
}
26+
IdentityEntry identity = connectorResource.connector().getTPPIdentity(username);
27+
Assertions.assertEquals(username, identity.name());
28+
prefixedUniversal = identity.prefixedUniversal();
3329
}
3430

3531
@Test

0 commit comments

Comments
 (0)