Search in sources :

Example 6 with CryptoException

use of org.craftercms.commons.crypto.CryptoException in project profile by craftercms.

the class RememberMeManagerImpl method deserializeLogin.

protected PersistentLogin deserializeLogin(String serializedLogin) throws RememberMeException {
    String decryptedLogin;
    try {
        decryptedLogin = encryptor.decrypt(serializedLogin);
    } catch (CryptoException e) {
        throw new RememberMeException("Unable to decrypt remember me cookie", e);
    }
    String[] splitSerializedLogin = StringUtils.split(decryptedLogin, SERIALIZED_LOGIN_SEPARATOR);
    if (ArrayUtils.isNotEmpty(splitSerializedLogin) && splitSerializedLogin.length == 3) {
        PersistentLogin login = new PersistentLogin();
        login.setId(splitSerializedLogin[0]);
        login.setProfileId(splitSerializedLogin[1]);
        login.setToken(splitSerializedLogin[2]);
        return login;
    } else {
        throw new InvalidCookieException("Invalid format of remember me cookie");
    }
}
Also used : InvalidCookieException(org.craftercms.security.exception.rememberme.InvalidCookieException) CryptoException(org.craftercms.commons.crypto.CryptoException) PersistentLogin(org.craftercms.profile.api.PersistentLogin) RememberMeException(org.craftercms.security.exception.rememberme.RememberMeException)

Aggregations

CryptoException (org.craftercms.commons.crypto.CryptoException)6 GeneralSecurityException (java.security.GeneralSecurityException)3 RememberMeException (org.craftercms.security.exception.rememberme.RememberMeException)2 KeyStore (java.security.KeyStore)1 KeySpec (java.security.spec.KeySpec)1 SecretKey (javax.crypto.SecretKey)1 SecretKeyFactory (javax.crypto.SecretKeyFactory)1 PBEKeySpec (javax.crypto.spec.PBEKeySpec)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 PersistentLogin (org.craftercms.profile.api.PersistentLogin)1 InvalidCookieException (org.craftercms.security.exception.rememberme.InvalidCookieException)1