Search in sources :

Example 1 with DisabledUserException

use of org.craftercms.security.exception.DisabledUserException in project profile by craftercms.

the class AuthenticationManagerImpl method authenticateUser.

@Override
public Authentication authenticateUser(String tenant, String username, String password) {
    try {
        Ticket ticket = authenticationService.authenticate(tenant, username, password);
        Profile profile = profileService.getProfile(ticket.getProfileId());
        if (profile == null) {
            throw new AuthenticationSystemException("No profile found for ID '" + ticket.getProfileId() + "'");
        }
        String ticketId = ticket.getId();
        DefaultAuthentication auth = new DefaultAuthentication(ticketId, profile);
        authenticationCache.putAuthentication(auth);
        logger.debug("Authentication successful for user '{}' (ticket ID = '{}')", ticket.getProfileId(), ticketId);
        return auth;
    } catch (ProfileRestServiceException e) {
        switch(e.getErrorCode()) {
            case DISABLED_PROFILE:
                throw new DisabledUserException("User is disabled", e);
            case BAD_CREDENTIALS:
                throw new BadCredentialsException("Invalid username and/or password", e);
            default:
                throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
        }
    } catch (ProfileException e) {
        throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) ProfileRestServiceException(org.craftercms.profile.exceptions.ProfileRestServiceException) AuthenticationSystemException(org.craftercms.security.exception.AuthenticationSystemException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) BadCredentialsException(org.craftercms.security.exception.BadCredentialsException) Profile(org.craftercms.profile.api.Profile) DisabledUserException(org.craftercms.security.exception.DisabledUserException)

Example 2 with DisabledUserException

use of org.craftercms.security.exception.DisabledUserException in project profile by craftercms.

the class AuthenticationManagerImpl method authenticateUser.

@Override
public Authentication authenticateUser(Profile profile, boolean remembered) throws AuthenticationException {
    try {
        Ticket ticket = authenticationService.createTicket(profile.getId().toString());
        String ticketId = ticket.getId();
        DefaultAuthentication auth = new DefaultAuthentication(ticketId, profile, remembered);
        authenticationCache.putAuthentication(auth);
        logger.debug("Authentication successful for user '{}' (ticket ID = '{}')", ticket.getProfileId(), ticketId);
        return auth;
    } catch (ProfileRestServiceException e) {
        if (e.getErrorCode() == ErrorCode.DISABLED_PROFILE) {
            throw new DisabledUserException("User is disabled", e);
        } else {
            throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
        }
    } catch (ProfileException e) {
        throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) ProfileRestServiceException(org.craftercms.profile.exceptions.ProfileRestServiceException) AuthenticationSystemException(org.craftercms.security.exception.AuthenticationSystemException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) DisabledUserException(org.craftercms.security.exception.DisabledUserException)

Aggregations

Ticket (org.craftercms.profile.api.Ticket)2 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)2 ProfileRestServiceException (org.craftercms.profile.exceptions.ProfileRestServiceException)2 AuthenticationSystemException (org.craftercms.security.exception.AuthenticationSystemException)2 DisabledUserException (org.craftercms.security.exception.DisabledUserException)2 Profile (org.craftercms.profile.api.Profile)1 BadCredentialsException (org.craftercms.security.exception.BadCredentialsException)1