|
6 | 6 | import com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException; |
7 | 7 | import com.venafi.vcert.sdk.connectors.ConnectorException.MissingAccessTokenException; |
8 | 8 | import com.venafi.vcert.sdk.connectors.ConnectorException.MissingRefreshTokenException; |
| 9 | +import com.venafi.vcert.sdk.connectors.ConnectorException.NullAuthenticationException; |
9 | 10 | import com.venafi.vcert.sdk.connectors.TokenConnector; |
10 | 11 | import com.venafi.vcert.sdk.endpoint.Authentication; |
11 | 12 | import com.venafi.vcert.sdk.endpoint.ConnectorType; |
@@ -72,13 +73,17 @@ public void authorize(Authentication credentials) throws VCertException { |
72 | 73 | } |
73 | 74 |
|
74 | 75 | private boolean isEmptyTokens( Authentication credentials ){ |
75 | | - return isEmptyAccessToken(credentials) && isBlank(credentials.refreshToken()); |
| 76 | + return isEmptyAccessToken(credentials) && isEmptyRefreshToken(credentials); |
76 | 77 | } |
77 | 78 |
|
78 | 79 | private boolean isEmptyAccessToken(Authentication credentials){ |
79 | 80 | return credentials == null || isBlank(credentials.accessToken()); |
80 | 81 | } |
81 | 82 |
|
| 83 | + private boolean isEmptyRefreshToken(Authentication credentials){ |
| 84 | + return credentials == null || isBlank(credentials.refreshToken()); |
| 85 | + } |
| 86 | + |
82 | 87 | private void verifyAccessToken(Authentication credentials) throws VCertException { |
83 | 88 | if(!isBlank(credentials.accessToken())) { |
84 | 89 |
|
@@ -121,31 +126,35 @@ public TokenInfo getTokenInfo() throws VCertException { |
121 | 126 | @Override |
122 | 127 | public TokenInfo getAccessToken(Authentication auth) throws VCertException { |
123 | 128 |
|
124 | | - Authentication authTemp = null; |
125 | | - |
126 | 129 | if (auth != null) { |
127 | 130 |
|
128 | | - //creating a temp Authentication object based on the one passed as argument |
129 | | - // in order to avoid to modify that original given it's needed that |
130 | | - // the Authentication object to be passed to the authenticate() method needs |
131 | | - // that the accessToken and refreshToken doesn't set |
132 | | - authTemp = Authentication.builder() |
133 | | - .user(auth.user()) |
134 | | - .password(auth.password()) |
135 | | - .clientId(auth.clientId()) |
136 | | - .scope(auth.scope()) |
137 | | - .state(auth.state()) |
138 | | - .redirectUri(auth.redirectUri()) |
139 | | - .build(); |
140 | | - } |
141 | | - |
142 | | - authenticate(authTemp); |
143 | | - |
144 | | - //setting the auth object as the credentials and setting into it the accessToken |
145 | | - //and refreshToken hold by TokenInfo |
146 | | - setTokenCredentials(auth); |
147 | | - |
148 | | - return getTokenInfo(); |
| 131 | + Authentication authTemp = null; |
| 132 | + |
| 133 | + if (auth != null) { |
| 134 | + |
| 135 | + //creating a temp Authentication object based on the one passed as argument |
| 136 | + // in order to avoid to modify that original given it's needed that |
| 137 | + // the Authentication object to be passed to the authenticate() method needs |
| 138 | + // that the accessToken and refreshToken doesn't set |
| 139 | + authTemp = Authentication.builder() |
| 140 | + .user(auth.user()) |
| 141 | + .password(auth.password()) |
| 142 | + .clientId(auth.clientId()) |
| 143 | + .scope(auth.scope()) |
| 144 | + .state(auth.state()) |
| 145 | + .redirectUri(auth.redirectUri()) |
| 146 | + .build(); |
| 147 | + } |
| 148 | + |
| 149 | + authenticate(authTemp); |
| 150 | + |
| 151 | + //setting the auth object as the credentials and setting into it the accessToken |
| 152 | + //and refreshToken hold by TokenInfo |
| 153 | + setTokenCredentials(auth); |
| 154 | + |
| 155 | + return getTokenInfo(); |
| 156 | + } else |
| 157 | + throw new NullAuthenticationException(); |
149 | 158 | } |
150 | 159 |
|
151 | 160 | @Override |
|
0 commit comments