|
19 | 19 | import org.apache.commons.lang3.StringUtils; |
20 | 20 | import org.apache.commons.lang3.Strings; |
21 | 21 | import org.apache.hc.core5.http.HttpEntityContainer; |
| 22 | +import org.apache.hc.core5.http.HttpResponse; |
22 | 23 | import org.apache.hc.core5.http.HttpStatus; |
23 | 24 | import org.apache.hc.core5.http.io.entity.EntityUtils; |
24 | 25 | import org.springframework.http.HttpHeaders; |
@@ -192,26 +193,30 @@ public boolean unlockAccount(final Credential credential) throws Throwable { |
192 | 193 | } |
193 | 194 |
|
194 | 195 | @Override |
195 | | - public boolean isAnswerValidForSecurityQuestion(final PasswordManagementQuery query, final String question, |
196 | | - final String knownAnswer, final String givenAnswer) { |
197 | | - val url = Strings.CI.appendIfMissing( |
198 | | - SpringExpressionLanguageValueResolver.getInstance().resolve( |
199 | | - casProperties.getAuthn().getPm().getSyncope().getUrl()), |
200 | | - "/rest/users/verifySecurityAnswer"); |
201 | | - val exec = HttpExecutionRequest.builder() |
202 | | - .method(HttpMethod.POST) |
203 | | - .url(url) |
204 | | - .basicAuthUsername(casProperties.getAuthn().getPm().getSyncope().getBasicAuthUsername()) |
205 | | - .basicAuthPassword(casProperties.getAuthn().getPm().getSyncope().getBasicAuthPassword()) |
206 | | - .headers(Map.of( |
207 | | - SyncopeUtils.SYNCOPE_HEADER_DOMAIN, casProperties.getAuthn().getPm().getSyncope().getDomain(), |
208 | | - HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE, |
209 | | - HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) |
210 | | - .parameters(Map.of("username", query.getUsername())) |
211 | | - .entity(givenAnswer) |
212 | | - .build(); |
213 | | - val response = Objects.requireNonNull(HttpUtils.execute(exec)); |
214 | | - return org.springframework.http.HttpStatus.resolve(response.getCode()).is2xxSuccessful(); |
| 196 | + public boolean isAnswerValidForSecurityQuestion(final PasswordManagementQuery query, final String question, final String knownAnswer, final String givenAnswer) { |
| 197 | + HttpResponse response = null; |
| 198 | + try { |
| 199 | + val userSecurityAnswerUrl = Strings.CI.appendIfMissing(SpringExpressionLanguageValueResolver.getInstance() |
| 200 | + .resolve(casProperties.getAuthn().getPm().getSyncope().getUrl()), |
| 201 | + "/rest/users/verifySecurityAnswer"); |
| 202 | + |
| 203 | + LOGGER.debug("Check security answer validity for user [{}]", query.getUsername()); |
| 204 | + val exec = HttpExecutionRequest.builder().method(HttpMethod.POST).url(userSecurityAnswerUrl) |
| 205 | + .basicAuthUsername(casProperties.getAuthn().getPm().getSyncope().getBasicAuthUsername()) |
| 206 | + .basicAuthPassword(casProperties.getAuthn().getPm().getSyncope().getBasicAuthPassword()) |
| 207 | + .headers(Map.of( |
| 208 | + SyncopeUtils.SYNCOPE_HEADER_DOMAIN, casProperties.getAuthn().getPm().getSyncope().getDomain(), |
| 209 | + HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE, |
| 210 | + HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) |
| 211 | + .parameters(Map.of("username", query.getUsername())) |
| 212 | + .entity(givenAnswer) |
| 213 | + .maximumRetryAttempts(casProperties.getAuthn().getSyncope().getMaxRetryAttempts()) |
| 214 | + .build(); |
| 215 | + response = Objects.requireNonNull(HttpUtils.execute(exec)); |
| 216 | + return org.springframework.http.HttpStatus.resolve(response.getCode()).is2xxSuccessful(); |
| 217 | + } finally { |
| 218 | + HttpUtils.close(response); |
| 219 | + } |
215 | 220 | } |
216 | 221 |
|
217 | 222 | protected String fetchSyncopeUserKey(final String username) { |
|
0 commit comments