Skip to content

Commit

Permalink
Refactor change of session ID to reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Dec 7, 2019
1 parent 38ec82c commit 0fded7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
29 changes: 16 additions & 13 deletions java/org/apache/catalina/authenticator/AuthenticatorBase.java
Expand Up @@ -46,7 +46,6 @@
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Manager;
import org.apache.catalina.Realm;
import org.apache.catalina.Session;
import org.apache.catalina.TomcatPrincipal;
Expand Down Expand Up @@ -1128,18 +1127,8 @@ private void register(Request request, HttpServletResponse response, Principal p
if (session != null) {
// If the principal is null then this is a logout. No need to change
// the session ID. See BZ 59043.
if (changeSessionIdOnAuthentication && principal != null) {
String oldId = null;
if (log.isDebugEnabled()) {
oldId = session.getId();
}
Manager manager = request.getContext().getManager();
manager.changeSessionId(session);
request.changeSessionId(session.getId());
if (log.isDebugEnabled()) {
log.debug(sm.getString("authenticator.changeSessionId",
oldId, session.getId()));
}
if (getChangeSessionIdOnAuthentication() && principal != null) {
changeSessionID(request, session);
}
} else if (alwaysUseSession) {
session = request.getSessionInternal(true);
Expand Down Expand Up @@ -1226,6 +1215,20 @@ private void register(Request request, HttpServletResponse response, Principal p

}


protected String changeSessionID(Request request, Session session) {
String oldId = null;
if (log.isDebugEnabled()) {
oldId = session.getId();
}
String newId = request.changeSessionId();
if (log.isDebugEnabled()) {
log.debug(sm.getString("authenticator.changeSessionId", oldId, newId));
}
return newId;
}


@Override
public void login(String username, String password, Request request) throws ServletException {
Principal principal = doLogin(request, username, password);
Expand Down
Expand Up @@ -28,7 +28,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.Manager;
import org.apache.catalina.Realm;
import org.apache.catalina.Session;
import org.apache.catalina.connector.Request;
Expand Down Expand Up @@ -397,9 +396,7 @@ protected void forwardToLoginPage(Request request,
if (getChangeSessionIdOnAuthentication()) {
Session session = request.getSessionInternal(false);
if (session != null) {
Manager manager = request.getContext().getManager();
manager.changeSessionId(session);
request.changeSessionId(session.getId());
changeSessionID(request, session);
}
}

Expand Down

0 comments on commit 0fded7d

Please sign in to comment.