[java-shib-idp2 COMMIT] /branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/Username...

noreply at shibboleth.net noreply at shibboleth.net
Tue Oct 11 21:32:19 BST 2011


Author: lajoie
Date: Tue Oct 11 21:32:19 2011
New Revision: 3078

URL: http://svn.shibboleth.net/view/java-shib-idp2?rev=3078&view=rev
Log:
Allow authentication method be overridden via a config parameter

Modified:
    branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java

Modified: branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java
URL: http://svn.shibboleth.net/view/java-shib-idp2/branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java?rev=3078&r1=3077&r2=3078&view=diff
==============================================================================
--- branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java (original)
+++ branches/REL_2/src/main/java/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java Tue Oct 11 21:32:19 2011
@@ -47,6 +47,10 @@
 /**
  * This Servlet authenticates a user via JAAS. The user's credential is always added to the returned {@link Subject} as
  * a {@link UsernamePasswordCredential} within the subject's private credentials.
+ * 
+ * By default, this Servlet assumes that the authentication method {@value AuthnContext#PPT_AUTHN_CTX} to be returned to
+ * the authentication engine. This can be override by setting the servlet configuration parameter
+ * {@value LoginHandler#AUTHENTICATION_METHOD_KEY}.
  */
 public class UsernamePasswordLoginServlet extends HttpServlet {
 
@@ -55,6 +59,9 @@
 
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(UsernamePasswordLoginServlet.class);
+    
+    /** The authentication method returned to the authentication engine. */
+    private String authenticationMethod;
 
     /** Name of JAAS configuration used to authenticate users. */
     private String jaasConfigName = "ShibUserPassAuth";
@@ -90,6 +97,14 @@
         }
         if (!loginPage.startsWith("/")) {
             loginPage = "/" + loginPage;
+        }
+        
+        String method =
+                DatatypeHelper.safeTrimOrNullString(config.getInitParameter(LoginHandler.AUTHENTICATION_METHOD_KEY));
+        if (method != null) {
+            authenticationMethod = method;
+        } else {
+            authenticationMethod = AuthnContext.PPT_AUTHN_CTX;
         }
     }
 
@@ -174,11 +189,7 @@
 
             Subject userSubject = new Subject(false, principals, publicCredentials, privateCredentials);
             request.setAttribute(LoginHandler.SUBJECT_KEY, userSubject);
-            if(request.isSecure()){
-                request.setAttribute(LoginHandler.AUTHENTICATION_METHOD_KEY, AuthnContext.PPT_AUTHN_CTX);
-            }else{
-                request.setAttribute(LoginHandler.AUTHENTICATION_METHOD_KEY, AuthnContext.PASSWORD_AUTHN_CTX);
-            }
+            request.setAttribute(LoginHandler.AUTHENTICATION_METHOD_KEY, authenticationMethod);
         } catch (LoginException e) {
             log.debug("User authentication for " + username + " failed", e);
             throw e;



More information about the commits mailing list