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

Commit 77b4b69

Browse files
committed
Changed the way the token is passed and used by the client. Now the token will be stored and reused by the client instead of being required for each method call.
1 parent c2fb02b commit 77b4b69

11 files changed

Lines changed: 189 additions & 181 deletions

File tree

src/main/java/com/venafi/vcert/sdk/VCertTknClient.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public class VCertTknClient implements TokenConnector {
2828
public VCertTknClient(Config config) throws VCertException {
2929
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
3030
switch (config.connectorType()) {
31-
case TPP_TOKEN:
31+
case TPP_TOKEN:{
3232
connector = new TppTokenConnector(Tpp.connect(config));
33+
((TppTokenConnector)connector).credentials(config.credentials());
3334
break;
35+
}
3436
default:
3537
throw new VCertException("ConnectorType is not defined");
3638
}
@@ -102,22 +104,22 @@ public TokenInfo getAccessToken(Authentication auth) throws VCertException{
102104
}
103105

104106
@Override
105-
public TokenInfo refreshAccessToken(String refreshToken, String applicationId) throws VCertException{
106-
return connector.refreshAccessToken(refreshToken, applicationId);
107+
public TokenInfo refreshAccessToken(String applicationId) throws VCertException{
108+
return connector.refreshAccessToken(applicationId);
107109
}
108110

109111
@Override
110-
public int revokeAccessToken(String accessToken) throws VCertException {
111-
return connector.revokeAccessToken(accessToken);
112+
public int revokeAccessToken() throws VCertException {
113+
return connector.revokeAccessToken();
112114
}
113115

114116
/**
115117
* {@inheritDoc}
116118
*/
117119
@Override
118-
public void ping(String accessToken) throws VCertException {
120+
public void ping() throws VCertException {
119121
try {
120-
connector.ping(accessToken);
122+
connector.ping();
121123
} catch (FeignException e) {
122124
throw VCertException.fromFeignException(e);
123125
} catch (Exception e) {
@@ -129,9 +131,9 @@ public void ping(String accessToken) throws VCertException {
129131
* {@inheritDoc}
130132
*/
131133
@Override
132-
public ZoneConfiguration readZoneConfiguration(String zone, String accessToken) throws VCertException {
134+
public ZoneConfiguration readZoneConfiguration(String zone) throws VCertException {
133135
try {
134-
return connector.readZoneConfiguration(zone, accessToken);
136+
return connector.readZoneConfiguration(zone);
135137
} catch (FeignException e) {
136138
throw VCertException.fromFeignException(e);
137139
} catch (Exception e) {
@@ -143,10 +145,10 @@ public ZoneConfiguration readZoneConfiguration(String zone, String accessToken)
143145
* {@inheritDoc}
144146
*/
145147
@Override
146-
public CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest request, String accessToken)
148+
public CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest request)
147149
throws VCertException {
148150
try {
149-
return connector.generateRequest(config, request, accessToken);
151+
return connector.generateRequest(config, request);
150152
} catch (FeignException e) {
151153
throw VCertException.fromFeignException(e);
152154
} catch (Exception e) {
@@ -155,9 +157,9 @@ public CertificateRequest generateRequest(ZoneConfiguration config, CertificateR
155157
}
156158

157159
@Override
158-
public String requestCertificate(CertificateRequest request, String zone, String accessToken) throws VCertException {
160+
public String requestCertificate(CertificateRequest request, String zone) throws VCertException {
159161
try {
160-
return connector.requestCertificate(request, zone, accessToken);
162+
return connector.requestCertificate(request, zone);
161163
} catch (FeignException e) {
162164
throw VCertException.fromFeignException(e);
163165
} catch (Exception e) {
@@ -169,10 +171,10 @@ public String requestCertificate(CertificateRequest request, String zone, String
169171
* {@inheritDoc}
170172
*/
171173
@Override
172-
public String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConfiguration, String accessToken)
174+
public String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConfiguration)
173175
throws VCertException {
174176
try {
175-
return connector.requestCertificate(request, zoneConfiguration, accessToken);
177+
return connector.requestCertificate(request, zoneConfiguration);
176178
} catch (FeignException e) {
177179
throw VCertException.fromFeignException(e);
178180
} catch (Exception e) {
@@ -184,9 +186,9 @@ public String requestCertificate(CertificateRequest request, ZoneConfiguration z
184186
* {@inheritDoc}
185187
*/
186188
@Override
187-
public PEMCollection retrieveCertificate(CertificateRequest request, String accessToken) throws VCertException {
189+
public PEMCollection retrieveCertificate(CertificateRequest request) throws VCertException {
188190
try {
189-
return connector.retrieveCertificate(request, accessToken);
191+
return connector.retrieveCertificate(request);
190192
} catch (FeignException e) {
191193
throw VCertException.fromFeignException(e);
192194
} catch (Exception e) {
@@ -198,9 +200,9 @@ public PEMCollection retrieveCertificate(CertificateRequest request, String acce
198200
* {@inheritDoc}
199201
*/
200202
@Override
201-
public void revokeCertificate(RevocationRequest request, String accessToken) throws VCertException {
203+
public void revokeCertificate(RevocationRequest request) throws VCertException {
202204
try {
203-
connector.revokeCertificate(request, accessToken);
205+
connector.revokeCertificate(request);
204206
} catch (FeignException e) {
205207
throw VCertException.fromFeignException(e);
206208
} catch (Exception e) {
@@ -212,9 +214,9 @@ public void revokeCertificate(RevocationRequest request, String accessToken) thr
212214
* {@inheritDoc}
213215
*/
214216
@Override
215-
public String renewCertificate(RenewalRequest request, String accessToken) throws VCertException {
217+
public String renewCertificate(RenewalRequest request) throws VCertException {
216218
try {
217-
return connector.renewCertificate(request, accessToken);
219+
return connector.renewCertificate(request);
218220
} catch (FeignException e) {
219221
throw VCertException.fromFeignException(e);
220222
} catch (Exception e) {
@@ -226,9 +228,9 @@ public String renewCertificate(RenewalRequest request, String accessToken) throw
226228
* {@inheritDoc}
227229
*/
228230
@Override
229-
public ImportResponse importCertificate(ImportRequest request, String accessToken) throws VCertException {
231+
public ImportResponse importCertificate(ImportRequest request) throws VCertException {
230232
try {
231-
return connector.importCertificate(request, accessToken);
233+
return connector.importCertificate(request);
232234
} catch (FeignException e) {
233235
throw VCertException.fromFeignException(e);
234236
} catch (Exception e) {
@@ -240,9 +242,9 @@ public ImportResponse importCertificate(ImportRequest request, String accessToke
240242
* {@inheritDoc}
241243
*/
242244
@Override
243-
public Policy readPolicyConfiguration(String zone, String accessToken) throws VCertException {
245+
public Policy readPolicyConfiguration(String zone) throws VCertException {
244246
try {
245-
return connector.readPolicyConfiguration(zone, accessToken);
247+
return connector.readPolicyConfiguration(zone);
246248
} catch (FeignException e) {
247249
throw VCertException.fromFeignException(e);
248250
} catch (Exception e) {

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ public interface TokenConnector {
5454

5555
/**
5656
* this is for refreshing a token.
57-
* @param refreshToken the refresh token.
5857
* @param applicationId the application id.
5958
* @return a complete info about the new access token, refresh token, expires.
6059
*/
61-
TokenInfo refreshAccessToken( String refreshToken, String applicationId ) throws VCertException;
60+
TokenInfo refreshAccessToken(String applicationId ) throws VCertException;
6261

6362
/**
6463
*
6564
* @return 1 if the access token was revoked and 0 if not.
6665
*/
67-
int revokeAccessToken( String accessToken ) throws VCertException;
66+
int revokeAccessToken() throws VCertException;
6867

6968
/**
7069
* VedAuth method.
@@ -73,19 +72,18 @@ public interface TokenConnector {
7372
*
7473
* @throws VCertException
7574
*/
76-
void ping(String accessToken) throws VCertException;
75+
void ping() throws VCertException;
7776

7877
/**
7978
* VedAuth method.
8079
* Reads the zone configuration needed for generating and requesting a certificate
8180
*
8281
* @param zone ID (e.g. 2ebd4ec1-57f7-4994-8651-e396b286a3a8) or zone path (e.g.
8382
* "ProjectName\ZoneName")
84-
* @param accessToken The authentication token.
8583
* @return
8684
* @throws VCertException
8785
*/
88-
ZoneConfiguration readZoneConfiguration(String zone, String accessToken) throws VCertException;
86+
ZoneConfiguration readZoneConfiguration(String zone) throws VCertException;
8987

9088
/**
9189
* VedAuth method.
@@ -94,11 +92,10 @@ public interface TokenConnector {
9492
* the user data
9593
*
9694
* @param config
97-
* @param accessToken The authentication token
9895
* @return the zone configuration
9996
* @throws VCertException
10097
*/
101-
CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest request, String accessToken)
98+
CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest request)
10299
throws VCertException;
103100

104101
/**
@@ -108,11 +105,10 @@ CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest
108105
*
109106
* @param request
110107
* @param zoneConfiguration
111-
* @param accessToken the authentication token.
112108
* @return request id to track the certificate status.
113109
* @throws VCertException
114110
*/
115-
String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConfiguration, String accessToken)
111+
String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConfiguration)
116112
throws VCertException, UnsupportedOperationException;
117113

118114
/**
@@ -122,11 +118,10 @@ String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConf
122118
*
123119
* @param request
124120
* @param zone
125-
* @param accessToken the authentication token.
126121
* @return request id to track the certificate status.
127122
* @throws VCertException
128123
*/
129-
String requestCertificate(CertificateRequest request, String zone, String accessToken)
124+
String requestCertificate(CertificateRequest request, String zone)
130125
throws VCertException, UnsupportedOperationException;
131126

132127
/**
@@ -135,46 +130,42 @@ String requestCertificate(CertificateRequest request, String zone, String access
135130
* Retrives the certificate for the specific ID
136131
*
137132
* @param request
138-
* @param accessToken the authentication token.
139133
* @return A collection of PEM files including certificate, chain and potentially a private key.
140134
* @throws VCertException
141135
*/
142-
PEMCollection retrieveCertificate(CertificateRequest request, String accessToken) throws VCertException;
136+
PEMCollection retrieveCertificate(CertificateRequest request) throws VCertException;
143137

144138
/**
145139
* VedAuth method.
146140
*
147141
* Attempts to revoke a certificate
148142
*
149143
* @param request
150-
* @param accessToken the authentication token.
151144
* @throws VCertException
152145
*/
153-
void revokeCertificate(RevocationRequest request, String accessToken) throws VCertException;
146+
void revokeCertificate(RevocationRequest request) throws VCertException;
154147

155148
/**
156149
* VedAuth method.
157150
*
158151
* Attempts to renew a certificate
159152
*
160153
* @param request
161-
* @param accessToken the authentication token.
162154
* @return
163155
* @throws VCertException
164156
*/
165-
String renewCertificate(RenewalRequest request, String accessToken) throws VCertException;
157+
String renewCertificate(RenewalRequest request) throws VCertException;
166158

167159
/**
168160
* VedAuth method.
169161
*
170162
* Import an external certificate into Venafi.
171163
*
172164
* @param request
173-
* @param accessToken the authentication token.
174165
* @return
175166
* @throws VCertException
176167
*/
177-
ImportResponse importCertificate(ImportRequest request, String accessToken) throws VCertException;
168+
ImportResponse importCertificate(ImportRequest request) throws VCertException;
178169

179170
/**
180171
* VedAuth method.
@@ -185,5 +176,5 @@ String requestCertificate(CertificateRequest request, String zone, String access
185176
* @return
186177
* @throws VCertException
187178
*/
188-
Policy readPolicyConfiguration(String zone, String accessToken) throws VCertException;
179+
Policy readPolicyConfiguration(String zone) throws VCertException;
189180
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public abstract class AbstractTppConnector {
1818
protected static final Pattern POLICY_REGEX = Pattern.compile("^\\\\VED\\\\Policy");
1919
protected static final String HEADER_VALUE_AUTHORIZATION = "Bearer %s";
2020

21-
protected static final String MISSING_CREDENTIALS_MESSAGE = "failed to authenticate: missing credentials";
22-
21+
protected static final String FAILED_TO_AUTHENTICATE_MESSAGE = "failed to authenticate: ";
22+
protected static final String MISSING_CREDENTIALS_MESSAGE = FAILED_TO_AUTHENTICATE_MESSAGE + "missing credentials";
23+
protected static final String MISSING_REFRESH_TOKEN_MESSAGE = FAILED_TO_AUTHENTICATE_MESSAGE + "missing refresh token";
24+
protected static final String MISSING_ACCESS_TOKEN_MESSAGE = FAILED_TO_AUTHENTICATE_MESSAGE + "missing access token";
2325

2426
protected final Tpp tpp;
2527

src/main/java/com/venafi/vcert/sdk/connectors/tpp/ResfreshTokenResponse.java renamed to src/main/java/com/venafi/vcert/sdk/connectors/tpp/RefreshTokenResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.Data;
66

77
@Data
8-
public class ResfreshTokenResponse {
8+
public class RefreshTokenResponse {
99

1010
@SerializedName("access_token")
1111
private String accessToken;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ CertificateRetrieveResponse certificateRetrieve(
6666
AuthorizeTokenResponse authorizeToken(AbstractTppConnector.AuthorizeTokenRequest authorizeRequest);
6767

6868
@RequestLine("POST /vedauth/authorize/token")
69-
@Headers("Content-Type: application/json")
70-
ResfreshTokenResponse refreshToken(AbstractTppConnector.RefreshTokenRequest request);
69+
@Headers("Content-Type: application/json") RefreshTokenResponse refreshToken(AbstractTppConnector.RefreshTokenRequest request);
7170

7271
@RequestLine("GET /vedauth/revoke/token")
7372
@Headers("Authorization: {token}")

0 commit comments

Comments
 (0)