use of org.apereo.cas.authentication.soap.generated.ObjectFactory in project cas by apereo.
the class SoapAuthenticationHandler method authenticateUsernamePasswordInternal.
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential, final String originalPassword) throws GeneralSecurityException {
soapAuthenticationClient.setCredentials(credential);
val request = new ObjectFactory().createGetSoapAuthenticationRequest();
request.setUsername(credential.getUsername());
val response = soapAuthenticationClient.sendRequest(request);
if (response.getStatus() == HttpStatus.OK.value()) {
val attributes = new LinkedHashMap<String, List<Object>>();
response.getAttributes().forEach(item -> attributes.put(item.getKey().toString(), CollectionUtils.toCollection(item.getValue(), ArrayList.class)));
val principal = principalFactory.createPrincipal(response.getUsername(), attributes);
return createHandlerResult(credential, principal, new ArrayList<>(0));
}
val httpStatus = HttpStatus.valueOf(response.getStatus());
if (httpStatus.equals(HttpStatus.FORBIDDEN)) {
throw new AccountDisabledException("Could not authenticate forbidden account for " + credential.getUsername());
}
if (httpStatus.equals(HttpStatus.UNAUTHORIZED)) {
throw new FailedLoginException("Could not authenticate account for " + credential.getUsername());
}
if (httpStatus.equals(HttpStatus.NOT_FOUND)) {
throw new AccountNotFoundException("Could not locate account for " + credential.getUsername());
}
if (httpStatus.equals(HttpStatus.LOCKED)) {
throw new AccountLockedException("Could not authenticate locked account for " + credential.getUsername());
}
if (httpStatus.equals(HttpStatus.PRECONDITION_FAILED)) {
throw new AccountExpiredException("Could not authenticate expired account for " + credential.getUsername());
}
if (httpStatus.equals(HttpStatus.PRECONDITION_REQUIRED)) {
throw new AccountPasswordMustChangeException("Account password must change for " + credential.getUsername());
}
throw new FailedLoginException("SOAP endpoint returned an unknown status code " + httpStatus + " for " + credential.getUsername());
}
Aggregations