Search in sources :

Example 1 with Ticket

use of org.craftercms.profile.api.Ticket in project profile by craftercms.

the class AuthenticationManagerImplTest method getTicket1.

private Ticket getTicket1() {
    Ticket ticket = new Ticket();
    ticket.setId(TICKET_ID1);
    ticket.setTenant(TENANT1);
    ticket.setProfileId(PROFILE_ID1.toString());
    ticket.setLastRequestTime(new Date());
    return ticket;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) Date(java.util.Date)

Example 2 with Ticket

use of org.craftercms.profile.api.Ticket in project profile by craftercms.

the class AuthenticationManagerImplTest method getTicket2.

private Ticket getTicket2() {
    Ticket ticket = new Ticket();
    ticket.setId(TICKET_ID2);
    ticket.setTenant(TENANT2);
    ticket.setProfileId(PROFILE_ID2.toString());
    ticket.setLastRequestTime(new Date());
    return ticket;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) Date(java.util.Date)

Example 3 with Ticket

use of org.craftercms.profile.api.Ticket in project profile by craftercms.

the class AuthenticationServiceImpl method invalidateTicket.

@Override
public void invalidateTicket(String ticketId) throws ProfileException {
    try {
        Ticket ticket = ticketRepository.findByStringId(ticketId);
        if (ticket != null) {
            checkIfManageTicketsIsAllowed(ticket.getTenant());
            ticketRepository.removeByStringId(ticketId);
            logger.debug(LOG_KEY_TICKET_INVALIDATED, ticketId);
        }
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_TICKET_ERROR, ticketId);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 4 with Ticket

use of org.craftercms.profile.api.Ticket in project profile by craftercms.

the class AuthenticationServiceImpl method authenticate.

@Override
public Ticket authenticate(String tenantName, String username, String password) throws ProfileException {
    checkIfManageTicketsIsAllowed(tenantName);
    Profile profile = profileService.getProfileByUsername(tenantName, username, ProfileConstants.NO_ATTRIBUTE);
    if (profile == null) {
        // Invalid username
        throw new BadCredentialsException();
    }
    if (!profile.isEnabled()) {
        throw new DisabledProfileException(profile.getId().toString(), tenantName);
    }
    if (isProfileInTimeOut(profile)) {
        throw new ProfileLockedException();
    }
    try {
        if (!CryptoUtils.matchPassword(profile.getPassword(), password)) {
            // Invalid password
            countAsFail(profile);
            throw new BadCredentialsException();
        }
        clearAllLoginAttempts(profile);
        Ticket ticket = new Ticket();
        ticket.setId(UUID.randomUUID().toString());
        ticket.setTenant(tenantName);
        ticket.setProfileId(profile.getId().toString());
        ticket.setLastRequestTime(new Date());
        ticketRepository.insert(ticket);
        logger.debug(LOG_KEY_AUTHENTICATION_SUCCESSFUL, profile.getId(), ticket);
        return ticket;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_TICKET_ERROR, profile.getId());
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) ProfileLockedException(org.craftercms.profile.exceptions.ProfileLockedException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) DisabledProfileException(org.craftercms.profile.exceptions.DisabledProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) BadCredentialsException(org.craftercms.profile.exceptions.BadCredentialsException) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

Example 5 with Ticket

use of org.craftercms.profile.api.Ticket in project profile by craftercms.

the class AuthenticationServiceImpl method createTicket.

@Override
public Ticket createTicket(String profileId) throws ProfileException {
    Profile profile = profileService.getProfile(profileId, ProfileConstants.NO_ATTRIBUTE);
    if (profile != null) {
        String tenantName = profile.getTenant();
        checkIfManageTicketsIsAllowed(tenantName);
        if (!profile.isEnabled()) {
            throw new DisabledProfileException(profile.getId().toString(), tenantName);
        }
        try {
            Ticket ticket = new Ticket();
            ticket.setId(UUID.randomUUID().toString());
            ticket.setTenant(tenantName);
            ticket.setProfileId(profile.getId().toString());
            ticket.setLastRequestTime(new Date());
            ticketRepository.insert(ticket);
            logger.debug(LOG_KEY_TICKET_CREATED, profile.getId(), ticket);
            return ticket;
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_CREATE_TICKET_ERROR, profile.getId());
        }
    } else {
        throw new NoSuchProfileException.ById(profileId);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) DisabledProfileException(org.craftercms.profile.exceptions.DisabledProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

Aggregations

Ticket (org.craftercms.profile.api.Ticket)19 Test (org.junit.Test)9 Date (java.util.Date)8 MongoDataException (org.craftercms.commons.mongo.MongoDataException)4 Profile (org.craftercms.profile.api.Profile)4 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)4 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)2 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)2 ProfileRestServiceException (org.craftercms.profile.exceptions.ProfileRestServiceException)2 AuthenticationSystemException (org.craftercms.security.exception.AuthenticationSystemException)2 DisabledUserException (org.craftercms.security.exception.DisabledUserException)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 BadCredentialsException (org.craftercms.profile.exceptions.BadCredentialsException)1 ProfileLockedException (org.craftercms.profile.exceptions.ProfileLockedException)1 BadCredentialsException (org.craftercms.security.exception.BadCredentialsException)1