use of org.craftercms.profile.api.PersistentLogin in project profile by craftercms.
the class AuthenticationServiceImpl method deletePersistentLogin.
@Override
public void deletePersistentLogin(String loginId) throws ProfileException {
try {
PersistentLogin login = persistentLoginRepository.findByStringId(loginId);
if (login != null) {
checkIfManageTicketsIsAllowed(login.getTenant());
persistentLoginRepository.removeByStringId(loginId);
logger.debug(LOG_KEY_PERSISTENT_LOGIN_DELETED, loginId);
}
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_DELETE_PERSISTENT_LOGIN_ERROR, loginId);
}
}
use of org.craftercms.profile.api.PersistentLogin 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.api.PersistentLogin in project profile by craftercms.
the class RememberMeManagerImplTest method getLogin.
protected PersistentLogin getLogin() {
PersistentLogin login = new PersistentLogin();
login.setId(LOGIN_ID);
login.setToken(LOGIN_TOKEN);
login.setProfileId(PROFILE_ID.toString());
return login;
}
use of org.craftercms.profile.api.PersistentLogin in project profile by craftercms.
the class AuthenticationServiceIT method testCreatePersistentLogin.
@Test
public void testCreatePersistentLogin() throws Exception {
String profileId = profileService.getProfileByUsername(DEFAULT_TENANT_NAME, ADMIN_USERNAME).getId().toString();
PersistentLogin login = authenticationService.createPersistentLogin(profileId);
assertNotNull(login);
assertNotNull(login.getId());
assertEquals(profileId, login.getProfileId());
assertEquals(DEFAULT_TENANT_NAME, login.getTenant());
assertNotNull(login.getToken());
assertNotNull(login.getTimestamp());
authenticationService.invalidateTicket(login.getId());
}
use of org.craftercms.profile.api.PersistentLogin in project profile by craftercms.
the class AuthenticationServiceIT method testDeletePersistentLogin.
@Test
public void testDeletePersistentLogin() throws Exception {
String profileId = profileService.getProfileByUsername(DEFAULT_TENANT_NAME, ADMIN_USERNAME).getId().toString();
PersistentLogin login = authenticationService.createPersistentLogin(profileId);
assertNotNull(login);
authenticationService.deletePersistentLogin(login.getId());
login = authenticationService.getPersistentLogin(login.getId());
assertNull(login);
}
Aggregations