diff options
author | James Moger <james.moger@gitblit.com> | 2014-01-28 13:16:37 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-01-28 13:16:37 -0500 |
commit | 7ab32b65fcb20ca68d7afc357befb3a34de662bf (patch) | |
tree | df393fe15adcc63a8adf0330219e6bec981ba761 /src/main/java/com/gitblit/wicket/pages/SessionPage.java | |
parent | 158242228266af84aa14b7e13b43d2825626c446 (diff) | |
download | gitblit-7ab32b65fcb20ca68d7afc357befb3a34de662bf.tar.gz gitblit-7ab32b65fcb20ca68d7afc357befb3a34de662bf.zip |
issue-361: Reset user cookie after administrative password change
Cookies were not reset on administrative password change of a user
account. This allowed accounts with changed passwords to continue
authenticating. Cookies are now reset on password changes, they are
validated on each page request, AND they will now expire 7 days after
generation.
Diffstat (limited to 'src/main/java/com/gitblit/wicket/pages/SessionPage.java')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/SessionPage.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/SessionPage.java b/src/main/java/com/gitblit/wicket/pages/SessionPage.java index d2fcfa0d..22ae6e2e 100644 --- a/src/main/java/com/gitblit/wicket/pages/SessionPage.java +++ b/src/main/java/com/gitblit/wicket/pages/SessionPage.java @@ -16,6 +16,7 @@ package com.gitblit.wicket.pages;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
@@ -24,6 +25,7 @@ import org.apache.wicket.protocol.http.WebResponse; import com.gitblit.Keys;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebApp;
import com.gitblit.wicket.GitBlitWebSession;
@@ -53,6 +55,24 @@ public abstract class SessionPage extends WebPage { // already have a session, refresh usermodel to pick up
// any changes to permissions or roles (issue-186)
UserModel user = app().users().getUserModel(session.getUser().username);
+
+ // validate cookie during session (issue-361)
+ if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, true)) {
+ HttpServletRequest request = ((WebRequest) getRequestCycle().getRequest())
+ .getHttpServletRequest();
+ String requestCookie = app().authentication().getCookie(request);
+ if (!StringUtils.isEmpty(requestCookie) && !StringUtils.isEmpty(user.cookie)) {
+ if (!requestCookie.equals(user.cookie)) {
+ // cookie was changed during our session
+ HttpServletResponse response = ((WebResponse) getRequestCycle().getResponse())
+ .getHttpServletResponse();
+ app().authentication().logout(response, user);
+ session.setUser(null);
+ session.invalidateNow();
+ return;
+ }
+ }
+ }
session.setUser(user);
return;
}
|