11package com .venafi .vcert .sdk ;
22
33import static org .apache .commons .lang3 .StringUtils .isBlank ;
4+
45import java .security .Security ;
6+
57import com .google .common .annotations .VisibleForTesting ;
8+
69import feign .FeignException ;
10+
711import com .venafi .vcert .sdk .certificate .CertificateRequest ;
812import com .venafi .vcert .sdk .certificate .ImportRequest ;
913import com .venafi .vcert .sdk .certificate .ImportResponse ;
@@ -28,9 +32,11 @@ public class VCertTknClient implements TokenConnector {
2832 public VCertTknClient (Config config ) throws VCertException {
2933 Security .addProvider (new org .bouncycastle .jce .provider .BouncyCastleProvider ());
3034 switch (config .connectorType ()) {
31- case TPP_TOKEN :
35+ case TPP_TOKEN :{
3236 connector = new TppTokenConnector (Tpp .connect (config ));
37+ ((TppTokenConnector ) connector ).credentials (config .credentials ());
3338 break ;
39+ }
3440 default :
3541 throw new VCertException ("ConnectorType is not defined" );
3642 }
@@ -102,22 +108,33 @@ public TokenInfo getAccessToken(Authentication auth) throws VCertException{
102108 }
103109
104110 @ Override
105- public TokenInfo refreshAccessToken (String refreshToken , String applicationId ) throws VCertException {
106- return connector .refreshAccessToken (refreshToken , applicationId );
111+ public TokenInfo getAccessToken () throws VCertException {
112+ try {
113+ return connector .getAccessToken ();
114+ } catch (FeignException e ) {
115+ throw VCertException .fromFeignException (e );
116+ } catch (Exception e ) {
117+ throw new VCertException ("Unexpected exception" , e );
118+ }
119+ }
120+
121+ @ Override
122+ public TokenInfo refreshAccessToken (String applicationId ) throws VCertException {
123+ return connector .refreshAccessToken (applicationId );
107124 }
108125
109126 @ Override
110- public int revokeAccessToken (String accessToken ) throws VCertException {
111- return connector .revokeAccessToken (accessToken );
127+ public int revokeAccessToken () throws VCertException {
128+ return connector .revokeAccessToken ();
112129 }
113130
114131 /**
115132 * {@inheritDoc}
116133 */
117134 @ Override
118- public void ping (String accessToken ) throws VCertException {
135+ public void ping () throws VCertException {
119136 try {
120- connector .ping (accessToken );
137+ connector .ping ();
121138 } catch (FeignException e ) {
122139 throw VCertException .fromFeignException (e );
123140 } catch (Exception e ) {
@@ -129,9 +146,9 @@ public void ping(String accessToken) throws VCertException {
129146 * {@inheritDoc}
130147 */
131148 @ Override
132- public ZoneConfiguration readZoneConfiguration (String zone , String accessToken ) throws VCertException {
149+ public ZoneConfiguration readZoneConfiguration (String zone ) throws VCertException {
133150 try {
134- return connector .readZoneConfiguration (zone , accessToken );
151+ return connector .readZoneConfiguration (zone );
135152 } catch (FeignException e ) {
136153 throw VCertException .fromFeignException (e );
137154 } catch (Exception e ) {
@@ -143,10 +160,10 @@ public ZoneConfiguration readZoneConfiguration(String zone, String accessToken)
143160 * {@inheritDoc}
144161 */
145162 @ Override
146- public CertificateRequest generateRequest (ZoneConfiguration config , CertificateRequest request , String accessToken )
163+ public CertificateRequest generateRequest (ZoneConfiguration config , CertificateRequest request )
147164 throws VCertException {
148165 try {
149- return connector .generateRequest (config , request , accessToken );
166+ return connector .generateRequest (config , request );
150167 } catch (FeignException e ) {
151168 throw VCertException .fromFeignException (e );
152169 } catch (Exception e ) {
@@ -155,9 +172,9 @@ public CertificateRequest generateRequest(ZoneConfiguration config, CertificateR
155172 }
156173
157174 @ Override
158- public String requestCertificate (CertificateRequest request , String zone , String accessToken ) throws VCertException {
175+ public String requestCertificate (CertificateRequest request , String zone ) throws VCertException {
159176 try {
160- return connector .requestCertificate (request , zone , accessToken );
177+ return connector .requestCertificate (request , zone );
161178 } catch (FeignException e ) {
162179 throw VCertException .fromFeignException (e );
163180 } catch (Exception e ) {
@@ -169,10 +186,10 @@ public String requestCertificate(CertificateRequest request, String zone, String
169186 * {@inheritDoc}
170187 */
171188 @ Override
172- public String requestCertificate (CertificateRequest request , ZoneConfiguration zoneConfiguration , String accessToken )
189+ public String requestCertificate (CertificateRequest request , ZoneConfiguration zoneConfiguration )
173190 throws VCertException {
174191 try {
175- return connector .requestCertificate (request , zoneConfiguration , accessToken );
192+ return connector .requestCertificate (request , zoneConfiguration );
176193 } catch (FeignException e ) {
177194 throw VCertException .fromFeignException (e );
178195 } catch (Exception e ) {
@@ -184,9 +201,9 @@ public String requestCertificate(CertificateRequest request, ZoneConfiguration z
184201 * {@inheritDoc}
185202 */
186203 @ Override
187- public PEMCollection retrieveCertificate (CertificateRequest request , String accessToken ) throws VCertException {
204+ public PEMCollection retrieveCertificate (CertificateRequest request ) throws VCertException {
188205 try {
189- return connector .retrieveCertificate (request , accessToken );
206+ return connector .retrieveCertificate (request );
190207 } catch (FeignException e ) {
191208 throw VCertException .fromFeignException (e );
192209 } catch (Exception e ) {
@@ -198,9 +215,9 @@ public PEMCollection retrieveCertificate(CertificateRequest request, String acce
198215 * {@inheritDoc}
199216 */
200217 @ Override
201- public void revokeCertificate (RevocationRequest request , String accessToken ) throws VCertException {
218+ public void revokeCertificate (RevocationRequest request ) throws VCertException {
202219 try {
203- connector .revokeCertificate (request , accessToken );
220+ connector .revokeCertificate (request );
204221 } catch (FeignException e ) {
205222 throw VCertException .fromFeignException (e );
206223 } catch (Exception e ) {
@@ -212,9 +229,9 @@ public void revokeCertificate(RevocationRequest request, String accessToken) thr
212229 * {@inheritDoc}
213230 */
214231 @ Override
215- public String renewCertificate (RenewalRequest request , String accessToken ) throws VCertException {
232+ public String renewCertificate (RenewalRequest request ) throws VCertException {
216233 try {
217- return connector .renewCertificate (request , accessToken );
234+ return connector .renewCertificate (request );
218235 } catch (FeignException e ) {
219236 throw VCertException .fromFeignException (e );
220237 } catch (Exception e ) {
@@ -226,9 +243,9 @@ public String renewCertificate(RenewalRequest request, String accessToken) throw
226243 * {@inheritDoc}
227244 */
228245 @ Override
229- public ImportResponse importCertificate (ImportRequest request , String accessToken ) throws VCertException {
246+ public ImportResponse importCertificate (ImportRequest request ) throws VCertException {
230247 try {
231- return connector .importCertificate (request , accessToken );
248+ return connector .importCertificate (request );
232249 } catch (FeignException e ) {
233250 throw VCertException .fromFeignException (e );
234251 } catch (Exception e ) {
@@ -240,9 +257,9 @@ public ImportResponse importCertificate(ImportRequest request, String accessToke
240257 * {@inheritDoc}
241258 */
242259 @ Override
243- public Policy readPolicyConfiguration (String zone , String accessToken ) throws VCertException {
260+ public Policy readPolicyConfiguration (String zone ) throws VCertException {
244261 try {
245- return connector .readPolicyConfiguration (zone , accessToken );
262+ return connector .readPolicyConfiguration (zone );
246263 } catch (FeignException e ) {
247264 throw VCertException .fromFeignException (e );
248265 } catch (Exception e ) {
0 commit comments