Search in sources :

Example 1 with UserTO

use of org.apache.syncope.common.lib.to.UserTO in project cas by apereo.

the class SyncopeAuthenticationHandler method authenticateUsernamePasswordInternal.

@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential c, final String originalPassword) throws GeneralSecurityException {
    try {
        final String syncopeUrl = StringUtils.appendIfMissing(this.syncopeUrl, "/rest/users/self");
        final HttpResponse response = HttpUtils.executeGet(syncopeUrl, c.getUsername(), c.getPassword(), new HashMap<>(), CollectionUtils.wrap("X-Syncope-Domain", this.syncopeDomain));
        LOGGER.debug("Received http response status as [{}]", response.getStatusLine());
        if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            final String result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
            LOGGER.debug("Received user object as [{}]", result);
            final UserTO user = this.objectMapper.readValue(result, UserTO.class);
            if (user.isSuspended()) {
                throw new AccountDisabledException("Could not authenticate forbidden account for " + c.getUsername());
            }
            if (user.isMustChangePassword()) {
                throw new AccountPasswordMustChangeException("Account password must change for " + c.getUsername());
            }
            final Principal principal = this.principalFactory.createPrincipal(user.getUsername(), buildSyncopeUserAttributes(user));
            return createHandlerResult(c, principal, new ArrayList<>());
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    throw new FailedLoginException("Could not authenticate account for " + c.getUsername());
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) UserTO(org.apache.syncope.common.lib.to.UserTO) HttpResponse(org.apache.http.HttpResponse) AccountPasswordMustChangeException(org.apereo.cas.authentication.exceptions.AccountPasswordMustChangeException) AccountDisabledException(org.apereo.cas.authentication.exceptions.AccountDisabledException) Principal(org.apereo.cas.authentication.principal.Principal) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException) AccountDisabledException(org.apereo.cas.authentication.exceptions.AccountDisabledException) AccountPasswordMustChangeException(org.apereo.cas.authentication.exceptions.AccountPasswordMustChangeException)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 HttpResponse (org.apache.http.HttpResponse)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 AccountDisabledException (org.apereo.cas.authentication.exceptions.AccountDisabledException)1 AccountPasswordMustChangeException (org.apereo.cas.authentication.exceptions.AccountPasswordMustChangeException)1 Principal (org.apereo.cas.authentication.principal.Principal)1