use of org.craftercms.profile.exceptions.DisabledProfileException 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());
}
}
use of org.craftercms.profile.exceptions.DisabledProfileException in project profile by craftercms.
the class AuthenticationServiceImpl method createPersistentLogin.
@Override
public PersistentLogin createPersistentLogin(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 {
PersistentLogin login = new PersistentLogin();
login.setId(UUID.randomUUID().toString());
login.setTenant(tenantName);
login.setProfileId(profileId);
login.setToken(UUID.randomUUID().toString());
login.setTimestamp(new Date());
persistentLoginRepository.insert(login);
logger.debug(LOG_KEY_PERSISTENT_LOGIN_CREATED, profile.getId(), login);
return login;
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_CREATE_PERSISTENT_LOGIN_ERROR, profile.getId());
}
} else {
throw new NoSuchProfileException.ById(profileId);
}
}
use of org.craftercms.profile.exceptions.DisabledProfileException 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);
}
}
Aggregations