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

Commit d98b165

Browse files
Replacing the NullAuthenticationException by MissingCredentialsException
1 parent fbf89fe commit d98b165

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ public TppPingException(int status, String reason) {
6464
}
6565
}
6666

67-
public static class NullAuthenticationException extends ConnectorException {
68-
69-
private static final long serialVersionUID = 1L;
70-
71-
public NullAuthenticationException() {
72-
super("Authentication object is null");
73-
}
74-
}
75-
7667
public static class MissingCredentialsException extends ConnectorException {
7768

7869
private static final long serialVersionUID = 1L;

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.concurrent.TimeUnit;
2424

2525
import com.google.common.annotations.VisibleForTesting;
26-
import com.google.common.io.CharStreams;
2726
import com.venafi.vcert.sdk.VCertException;
2827
import com.venafi.vcert.sdk.certificate.CertificateRequest;
2928
import com.venafi.vcert.sdk.certificate.ChainOption;
@@ -47,6 +46,7 @@
4746
import com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException;
4847
import com.venafi.vcert.sdk.connectors.ConnectorException.CertificatePendingException;
4948
import com.venafi.vcert.sdk.connectors.ConnectorException.CouldNotParseRevokeReasonException;
49+
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException;
5050
import com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException;
5151
import com.venafi.vcert.sdk.connectors.ConnectorException.RenewFailureException;
5252
import com.venafi.vcert.sdk.connectors.ConnectorException.RetrieveCertificateTimeoutException;
@@ -57,18 +57,7 @@
5757
import com.venafi.vcert.sdk.connectors.Policy;
5858
import com.venafi.vcert.sdk.connectors.ServerPolicy;
5959
import com.venafi.vcert.sdk.connectors.ZoneConfiguration;
60-
import com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRenewalResponse;
61-
import com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRequestResponse;
62-
import com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRetrieveResponse;
63-
import com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRevokeResponse;
64-
import com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateSearchResponse;
65-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.*;
66-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCaTemplateRequest;
67-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCaTemplateResponse;
68-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRequest;
6960
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRequestResponse;
70-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest;
71-
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveResponse;
7261
import com.venafi.vcert.sdk.endpoint.Authentication;
7362
import com.venafi.vcert.sdk.endpoint.ConnectorType;
7463
import com.venafi.vcert.sdk.policy.api.domain.TPPPolicy;
@@ -143,7 +132,8 @@ public void ping() throws VCertException {
143132
* @throws VCertException if the call to {@link Tpp#authorize(AuthorizeRequest)} throws a {@link Unauthorized} or {@link BadRequest}
144133
*/
145134
@Override
146-
public void authorize(Authentication credentials) throws VCertException {
135+
public void authorize(Authentication credentials) throws VCertException {
136+
if (credentials != null) {
147137
try {
148138
AuthorizeResponse response = tpp.authorize(new AuthorizeRequest(credentials.user(), credentials.password()));
149139
apiKey = response.apiKey();
@@ -153,6 +143,9 @@ public void authorize(Authentication credentials) throws VCertException {
153143
} catch(Unauthorized | BadRequest e){
154144
throw VCertException.fromFeignException(e);
155145
}
146+
} else {
147+
throw new MissingCredentialsException();
148+
}
156149
}
157150

158151
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.venafi.vcert.sdk.VCertException;
66
import com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException;
77
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingAccessTokenException;
8+
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException;
89
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingRefreshTokenException;
9-
import com.venafi.vcert.sdk.connectors.ConnectorException.NullAuthenticationException;
1010
import com.venafi.vcert.sdk.connectors.TokenConnector;
1111
import com.venafi.vcert.sdk.endpoint.Authentication;
1212
import com.venafi.vcert.sdk.endpoint.ConnectorType;
@@ -64,11 +64,15 @@ public boolean isEmptyCredentials(Authentication credentials){
6464
*/
6565
@Override
6666
public void authorize(Authentication credentials) throws VCertException {
67-
//If the AccessToken or RefreshToken were provided then only verify the accessToken is still valid
68-
if(!isEmptyTokens(credentials)) {
69-
verifyAccessToken(credentials);
70-
} else { // The user and password were provided so then generate an accessToken from them
71-
authorizeToken(credentials);
67+
if(credentials != null) {
68+
//If the AccessToken or RefreshToken were provided then only verify the accessToken is still valid
69+
if(!isEmptyTokens(credentials)) {
70+
verifyAccessToken(credentials);
71+
} else { // The user and password were provided so then generate an accessToken from them
72+
authorizeToken(credentials);
73+
}
74+
} else {
75+
throw new MissingCredentialsException();
7276
}
7377
}
7478

@@ -149,7 +153,7 @@ public TokenInfo getAccessToken(Authentication auth) throws VCertException {
149153

150154
return getTokenInfo();
151155
} else
152-
throw new NullAuthenticationException();
156+
throw new MissingCredentialsException();
153157
}
154158

155159
@Override

src/test/java/com/venafi/vcert/sdk/VCertTknClientAuthenticationAT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.junit.jupiter.api.Test;
1414

1515
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException;
16-
import com.venafi.vcert.sdk.connectors.ConnectorException.NullAuthenticationException;
1716
import com.venafi.vcert.sdk.connectors.tpp.TokenInfo;
1817
import com.venafi.vcert.sdk.endpoint.Authentication;
1918
import com.venafi.vcert.sdk.endpoint.ConnectorType;
@@ -220,7 +219,7 @@ void invalidAuthenticationMissingCredentialsInAccessToken() {
220219
VCertTknClient client = getClientUnauthenticated();
221220

222221
//asserting that the credentials were not provided
223-
assertThrows(NullAuthenticationException.class, () -> client.getAccessToken());
222+
assertThrows(MissingCredentialsException.class, () -> client.getAccessToken());
224223

225224
//asserting that the credentials were not provided
226225
assertThrows(MissingCredentialsException.class, () -> client.getAccessToken(getAuthenticationMissingAccessToken()));

0 commit comments

Comments
 (0)