Author: markt
Date: Fri Jul 3 20:08:18 2015
New Revision: 1689082
URL: http://svn.apache.org/r1689082
Log:
Extracted saved authentication handling to separate method
Patch by fjodorver
Modified:
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
Modified:
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java?rev=1689082&r1=1689081&r2=1689082&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
(original)
+++
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
Fri Jul 3 20:08:18 2015
@@ -106,32 +106,8 @@ public class FormAuthModule extends Tomc
Request request = (Request) messageInfo.getRequestMessage();
HttpServletResponse response = (HttpServletResponse)
messageInfo.getResponseMessage();
- // Have we authenticated this user before but have caching disabled?
- if (!cachePrincipalsInSession) {
- Session session = request.getSessionInternal(true);
- if (log.isDebugEnabled()) {
- log.debug("Checking for reauthenticate in session " + session);
- }
- String username = (String)
session.getNote(Constants.SESS_USERNAME_NOTE);
- String password = (String)
session.getNote(Constants.SESS_PASSWORD_NOTE);
- if ((username != null) && (password != null)) {
- if (log.isDebugEnabled()) {
- log.debug("Reauthenticating username '" + username + "'");
- }
- Principal principal = realm.authenticate(username, password);
- if (principal == null) {
- forwardToErrorPage(request, response);
- return AuthStatus.FAILURE;
- }
-
- session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
- if (isMatchingSavedRequest(request)) {
- return submitSavedRequest(clientSubject, request,
response);
- }
-
- handlePrincipalCallbacks(clientSubject, principal);
- return AuthStatus.SUCCESS;
- }
+ if (!cachePrincipalsInSession && isUserAuthenicatedBefore(request)) {
+ return handleSavedCredentials(clientSubject, request, response);
}
// Is this the re-submit of the original request URI after
@@ -149,6 +125,43 @@ public class FormAuthModule extends Tomc
}
+ private AuthStatus handleSavedCredentials(Subject clientSubject, Request
request,
+ HttpServletResponse response) throws IOException,
UnsupportedCallbackException {
+ Session session = request.getSessionInternal(true);
+ if (log.isDebugEnabled()) {
+ log.debug("Checking for reauthenticate in session " + session);
+ }
+
+ String username = (String)
session.getNote(Constants.SESS_USERNAME_NOTE);
+ String password = (String)
session.getNote(Constants.SESS_PASSWORD_NOTE);
+ if (log.isDebugEnabled()) {
+ log.debug("Reauthenticating username '" + username + "'");
+ }
+
+ Principal principal = realm.authenticate(username, password);
+ if (principal == null) {
+ forwardToErrorPage(request, response);
+ return AuthStatus.FAILURE;
+ }
+
+ session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
+ if (isMatchingSavedRequest(request)) {
+ return submitSavedRequest(clientSubject, request, response);
+ }
+
+ handlePrincipalCallbacks(clientSubject, principal);
+ return AuthStatus.SUCCESS;
+ }
+
+
+ private boolean isUserAuthenicatedBefore(Request request) {
+ Session session = request.getSessionInternal(true);
+ String username = (String)
session.getNote(Constants.SESS_USERNAME_NOTE);
+ String password = (String)
session.getNote(Constants.SESS_PASSWORD_NOTE);
+ return username != null && password != null;
+ }
+
+
private AuthStatus submitSavedRequest(Subject clientSubject, Request
request,
HttpServletResponse response) throws IOException,
UnsupportedCallbackException {
Session session = request.getSessionInternal(true);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]