Skip to content

Commit

Permalink
update session
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Sep 21, 2015
1 parent 104cb6a commit a6a7b78
Showing 1 changed file with 12 additions and 0 deletions.
Expand Up @@ -6,8 +6,11 @@
import org.wyona.yanel.core.ResourceConfiguration;
import org.wyona.yanel.impl.resources.BasicXMLResource;

import org.wyona.security.core.api.Identity;
import org.wyona.security.core.api.User;

import org.wyona.yanel.servlet.YanelServlet;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -243,6 +246,7 @@ protected boolean updateProfile(String email) throws Exception {
user.setName(getEnvironment().getRequest().getParameter("userName"));
user.setLanguage(getEnvironment().getRequest().getParameter("user-profile-language"));
user.save();
updateSession(user);

String previousEmailAddress = user.getEmail();
if (!previousEmailAddress.equals(email)) {
Expand All @@ -262,6 +266,7 @@ protected boolean updateProfile(String email) throws Exception {
if (hasAlias(user, previousEmailAddress)) {
userManager.removeAlias(previousEmailAddress);
log.warn("Previous alias '" + previousEmailAddress + "' removed, which means user needs to use new email '" + email + "' to login.");
// TODO: Logout user and send email to new and previous email address
}
} else {
log.warn("Previous email '" + previousEmailAddress + "' was not used as alias, hence we also use new email '" + email + "' not as alias.");
Expand All @@ -283,6 +288,13 @@ protected boolean updateProfile(String email) throws Exception {
}
}

/**
* Update identity attached to session
*/
private void updateSession(User user) throws Exception {
YanelServlet.setIdentity(new Identity(user, user.getEmail()), getEnvironment().getRequest().getSession(true), getRealm());
}

/**
* Check whether user has a specific alias
* @return true when user has a specific alias
Expand Down

0 comments on commit a6a7b78

Please sign in to comment.