*/
protected void loadUserInformation() {
if (getUserInformation() != null) {
return;
}
UserInformation infoWithoutSecretKey = (UserInformation) getRequest().getSession()
.getAttribute(USER_INFORMATION_SESSION_ATTRIBUTE);
if (infoWithoutSecretKey != null) {
Cookie secretKeyCookie = null;
Cookie[] allCookies = getRequest().getCookies();
for (Cookie c : allCookies) {
if (SECRET_KEY_COOKIE_NAME.equals(c.getName())) {
secretKeyCookie = c;
break;
}
}
if (secretKeyCookie != null) {
// important : no end of line, else the cookie contains control
// characters,
// and it doesn't work
Base64 base64 = new Base64(-1);
byte[] encryptedSecretKey = base64.decode(secretKeyCookie.getValue());
byte[] cookieEncryptionKeyAsBytes =
(byte[]) getRequest().getSession().getAttribute(COOKIE_ENCRYPTION_KEY_SESSION_ATTRIBUTE);
SecretKey cookieEncryptionKey = cryptoEngine.bytesToSecretKey(cookieEncryptionKeyAsBytes);
byte[] secretKeyAsBytes =
cryptoEngine.decrypt(encryptedSecretKey,
cookieEncryptionKey,
cryptoEngine.buildInitializationVector(cookieEncryptionKeyAsBytes));
SecretKey secretKey = cryptoEngine.bytesToSecretKey(secretKeyAsBytes);
UserInformation userInformation = infoWithoutSecretKey.withSecretKey(secretKey);
setUserInformation(userInformation);
}
}
}