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");
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations