apparently Chad doesn't like user feedback; well I'll show him! (fixes SIDP-42....
authorwnorris <wnorris@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 8 Nov 2007 19:40:18 +0000 (19:40 +0000)
committerwnorris <wnorris@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 8 Nov 2007 19:40:18 +0000 (19:40 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2456 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/authn/provider/UsernamePasswordLoginServlet.java

index 92a07bc..73bfe28 100644 (file)
@@ -18,6 +18,8 @@ package edu.internet2.middleware.shibboleth.idp.authn.provider;
 
 import java.io.IOException;
 import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
 import javax.security.auth.Subject;
@@ -34,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.opensaml.util.URLBuilder;
 import org.opensaml.xml.util.DatatypeHelper;
+import org.opensaml.xml.util.Pair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,6 +60,9 @@ public class UsernamePasswordLoginServlet extends HttpServlet {
 
     /** Login page name. */
     private final String loginPage = "login.jsp";
+    
+    /** Parameter name to indicate login failure. */
+    private final String failureParam = "loginFailed";
 
     /** HTTP request parameter containing the user name. */
     private final String usernameAttribute = "j_username";
@@ -71,14 +77,16 @@ public class UsernamePasswordLoginServlet extends HttpServlet {
         String password = DatatypeHelper.safeTrimOrNullString(request.getParameter(passwordAttribute));
 
         if (username == null || password == null) {
-            redirectToLoginPage(request, response);
+            redirectToLoginPage(request, response, null);
             return;
         }
 
         if (authenticateUser(request)) {
             AuthenticationEngine.returnToAuthenticationEngine(request, response);
         } else {
-            redirectToLoginPage(request, response);
+            List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>();
+            queryParams.add(new Pair<String, String>(failureParam, "true"));
+            redirectToLoginPage(request, response, queryParams);
             return;
         }
     }
@@ -88,8 +96,10 @@ public class UsernamePasswordLoginServlet extends HttpServlet {
      * 
      * @param request current request
      * @param response current response
+     * @param queryParams query parameters to pass to the login page
      */
-    protected void redirectToLoginPage(HttpServletRequest request, HttpServletResponse response) {
+    protected void redirectToLoginPage(HttpServletRequest request, HttpServletResponse response,
+            List<Pair<String, String>> queryParams) {
         try {
             StringBuilder pathBuilder = new StringBuilder();
             pathBuilder.append(request.getContextPath());
@@ -101,6 +111,9 @@ public class UsernamePasswordLoginServlet extends HttpServlet {
             urlBuilder.setHost(request.getLocalName());
             urlBuilder.setPort(request.getLocalPort());
             urlBuilder.setPath(pathBuilder.toString());
+            if (queryParams != null) {
+                urlBuilder.getQueryParams().addAll(queryParams);
+            }
 
             log.debug("Redirecting to login page {}", urlBuilder.buildURL());
             response.sendRedirect(urlBuilder.buildURL());