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

Commit aa21fa1

Browse files
Standardize the authentication process for different VCert clients
The way that the Authetication can be acchieved is not standardized and that depends completely if the client will be a VCertClient or a VCertTknClient or for this last mentioned even if the accessToken was provided or user&password. For VCertTknClient exists 2 ways to have the client ready to use. The first one is when the access token is provided; then it will required to set it to an Authentication object which will be set to the Config that will be passed to the VCertTknClient Constructor. The second one is when the user and password is provided, then firstly it will be required to create the VCertTknClient object with a Config object with the Authentication object set and after that those values will be set to an Authentication object that will be passed as argument to the VCertTknClient.getAccessToken(Authentication) method. For VCertClient, no matter if it's type TPP or Cloud, similar to the second case of VCertTknClient, firstly it will required to create the VCertClient passing a Config object without the Authentication object set and then after create the Authentication object setting into it the required credentials(user&password for TPP and APIKey for VaaS) in order to call the VCertClient.authenticate(Authentication) method. With this refactoring, the sdk provides the following features which applies for both VCertClient and VCertTknClient: 1. Ability to have the client authenticated at the creation time, setting the Authentication object to the Config object which is passed to the constructor of the client. 2. Ability to authenticate the client after it was created. If for some reason it was not possible to set the Authentication object to the client when it was created, then the authenticate(Authenticate) method of the client can be called.
1 parent a1f1284 commit aa21fa1

16 files changed

Lines changed: 1164 additions & 297 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<junit.version>5.3.1</junit.version>
7070
<mockito.version>2.25.1</mockito.version>
7171
<wiremock.version>2.22.0</wiremock.version>
72-
<assertj.version>3.12.2</assertj.version>
72+
<assertj.version>3.22.0</assertj.version>
7373
<ini4j.version>0.5.4</ini4j.version>
7474
<commonslang3.version>3.11</commonslang3.version>
7575
<jarName>${project.artifactId}-${project.version}</jarName>

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public VCertClient(Config config) throws VCertException {
3535
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
3636

3737
this.connector = createConnector(config);
38+
39+
if(config.credentials() != null) {
40+
this.connector.authenticate(config.credentials());
41+
}
3842

3943
connector.setVendorAndProductName(isBlank(config.appInfo()) ? VCertConstants.DEFAULT_VENDOR_AND_PRODUCT_NAME :
4044
config.appInfo());
@@ -64,6 +68,11 @@ protected Connector createConnector(Config config) throws VCertException {
6468
VCertClient(Connector connector) {
6569
this.connector = connector;
6670
}
71+
72+
@Override
73+
public Authentication getCredentials() {
74+
return connector.getCredentials();
75+
}
6776

6877
/**
6978
* {@inheritDoc}
@@ -124,13 +133,33 @@ public void ping() throws VCertException {
124133
* {@inheritDoc}
125134
*/
126135
@Override
127-
public void authenticate(Authentication auth) throws VCertException {
136+
public void authenticate(Authentication credentials) throws VCertException {
128137
try {
129-
connector.authenticate(auth);
138+
connector.authenticate(credentials);
130139
} catch (FeignException e) {
131140
throw VCertException.fromFeignException(e);
132141
}
133142
}
143+
144+
/**
145+
* {@inheritDoc}
146+
*/
147+
@Override
148+
public boolean isEmptyCredentials(Authentication credentials) {
149+
return connector.isEmptyCredentials(credentials);
150+
}
151+
152+
/**
153+
* {@inheritDoc}
154+
*/
155+
@Override
156+
public void authorize(Authentication credentials) throws VCertException {
157+
try {
158+
connector.authorize(credentials);
159+
} catch (FeignException e) {
160+
throw VCertException.fromFeignException(e);
161+
}
162+
}
134163

135164
/**
136165
* {@inheritDoc}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected Connector createConnector(Config config) throws VCertException {
2323
switch (config.connectorType()) {
2424
case TPP_TOKEN:{
2525
connector = new TppTokenConnector(Tpp.connect(config));
26-
((TppTokenConnector) connector).credentials(config.credentials());
26+
//((TppTokenConnector) connector).credentials(config.credentials());
2727
break;
2828
}
2929
default:

0 commit comments

Comments
 (0)