use of org.craftercms.profile.api.Ticket 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);
}
}
use of org.craftercms.profile.api.Ticket in project profile by craftercms.
the class AuthenticationServiceIT method testCreateTicket.
@Test
public void testCreateTicket() throws Exception {
String profileId = profileService.getProfileByUsername(DEFAULT_TENANT_NAME, ADMIN_USERNAME).getId().toString();
Ticket ticket = authenticationService.createTicket(profileId);
assertNotNull(ticket);
assertNotNull(ticket.getId());
assertEquals(profileId, ticket.getProfileId());
assertEquals(DEFAULT_TENANT_NAME, ticket.getTenant());
assertNotNull(ticket.getLastRequestTime());
authenticationService.invalidateTicket(ticket.getId());
}
use of org.craftercms.profile.api.Ticket in project profile by craftercms.
the class AuthenticationServiceIT method testAuthenticate.
@Test
public void testAuthenticate() throws Exception {
Ticket ticket = authenticationService.authenticate(DEFAULT_TENANT_NAME, ADMIN_USERNAME, ADMIN_PASSWORD);
assertNotNull(ticket);
assertNotNull(ticket.getId());
assertNotNull(ticket.getProfileId());
assertEquals(DEFAULT_TENANT_NAME, ticket.getTenant());
assertNotNull(ticket.getLastRequestTime());
authenticationService.invalidateTicket(ticket.getId());
}
use of org.craftercms.profile.api.Ticket in project profile by craftercms.
the class AuthenticationServiceIT method testGetExpiredTicket.
@Test
public void testGetExpiredTicket() throws Exception {
Ticket ticket = authenticationService.authenticate(DEFAULT_TENANT_NAME, ADMIN_USERNAME, ADMIN_PASSWORD);
assertNotNull(ticket);
Thread.sleep(TimeUnit.SECONDS.toMillis(4));
ticket = authenticationService.getTicket(ticket.getId());
assertNull(ticket);
}
use of org.craftercms.profile.api.Ticket in project profile by craftercms.
the class AuthenticationServiceImplTest method testGetTicket.
@Test
public void testGetTicket() throws Exception {
Ticket ticket = authenticationService.getTicket(TICKET_ID);
assertNotNull(ticket);
assertEquals(TICKET_ID, ticket.getId());
assertEquals(PROFILE1_ID.toString(), ticket.getProfileId());
assertNotNull(ticket.getLastRequestTime());
verify(ticketRepository).findByStringId(TICKET_ID);
verify(ticketRepository).save(ticket);
}
Aggregations