Search in sources :

Example 1 with PersistentLogin

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);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) PersistentLogin(org.craftercms.profile.api.PersistentLogin)

Example 2 with PersistentLogin

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);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) DisabledProfileException(org.craftercms.profile.exceptions.DisabledProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) PersistentLogin(org.craftercms.profile.api.PersistentLogin) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

Example 3 with PersistentLogin

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;
}
Also used : PersistentLogin(org.craftercms.profile.api.PersistentLogin)

Example 4 with PersistentLogin

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());
}
Also used : PersistentLogin(org.craftercms.profile.api.PersistentLogin) Test(org.junit.Test)

Example 5 with PersistentLogin

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);
}
Also used : PersistentLogin(org.craftercms.profile.api.PersistentLogin) Test(org.junit.Test)

Aggregations

PersistentLogin (org.craftercms.profile.api.PersistentLogin)19 Test (org.junit.Test)7 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)5 RememberMeException (org.craftercms.security.exception.rememberme.RememberMeException)4 MongoDataException (org.craftercms.commons.mongo.MongoDataException)3 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)3 Date (java.util.Date)2 InvalidCookieException (org.craftercms.security.exception.rememberme.InvalidCookieException)2 RememberMeAuthenticationException (org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException)2 CryptoException (org.craftercms.commons.crypto.CryptoException)1 Profile (org.craftercms.profile.api.Profile)1 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)1 NoSuchPersistentLoginException (org.craftercms.profile.exceptions.NoSuchPersistentLoginException)1 Authentication (org.craftercms.security.authentication.Authentication)1 AuthenticationException (org.craftercms.security.exception.AuthenticationException)1 CookieTheftException (org.craftercms.security.exception.rememberme.CookieTheftException)1 CookieTheftException (org.springframework.security.web.authentication.rememberme.CookieTheftException)1 InvalidCookieException (org.springframework.security.web.authentication.rememberme.InvalidCookieException)1