Search in sources :

Example 11 with Ticket

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

the class ProfileServiceIT method testGetProfileByTicket.

@Test(expected = ProfileRestServiceException.class)
public void testGetProfileByTicket() throws Exception {
    Ticket ticket = authenticationService.authenticate(DEFAULT_TENANT, ADMIN_USERNAME, ADMIN_PASSWORD);
    assertNotNull(ticket);
    Profile profile = profileService.getProfileByTicket(ticket.getId());
    assertAdminProfile(profile);
    authenticationService.invalidateTicket(ticket.getId());
    // Try with invalid ticket
    profileService.getProfileByTicket("507c7f79bcf86cd7994f6c0e");
}
Also used : Ticket(org.craftercms.profile.api.Ticket) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 12 with Ticket

use of org.craftercms.profile.api.Ticket 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)

Example 13 with Ticket

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

the class AuthenticationServiceImpl method getTicket.

@Override
public Ticket getTicket(String ticketId) throws ProfileException {
    Ticket ticket;
    try {
        ticket = ticketRepository.findByStringId(ticketId);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_TICKET_ERROR, e, ticketId);
    }
    if (ticket != null) {
        checkIfManageTicketsIsAllowed(ticket.getTenant());
        ticket.setLastRequestTime(new Date());
        try {
            ticketRepository.save(ticket);
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TICKET_ERROR, ticketId);
        }
        logger.debug(LOG_KEY_TICKET_REQUESTED, ticketId);
        return ticket;
    }
    return null;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Date(java.util.Date)

Example 14 with Ticket

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

the class AuthenticationServiceImplTest method testCreateTicket.

@Test
public void testCreateTicket() throws Exception {
    Ticket ticket = authenticationService.createTicket(PROFILE1_ID.toString());
    assertNotNull(ticket);
    assertEquals(PROFILE1_ID.toString(), ticket.getProfileId());
    assertNotNull(ticket.getLastRequestTime());
    verify(profileService).getProfile(PROFILE1_ID.toString(), ProfileConstants.NO_ATTRIBUTE);
    verify(ticketRepository).insert(ticket);
}
Also used : Ticket(org.craftercms.profile.api.Ticket) Test(org.junit.Test)

Example 15 with Ticket

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

the class AuthenticationServiceImplTest method getTicket.

private Ticket getTicket() {
    Ticket ticket = new Ticket();
    ticket.setId(TICKET_ID);
    ticket.setProfileId(PROFILE1_ID.toString());
    ticket.setLastRequestTime(new Date());
    return ticket;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) 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