incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r956797 - in /sling/trunk/bundles/extensions/formauth/src: main/java/org/apache/sling/formauth/ test/java/org/apache/sling/formauth/
Date Tue, 22 Jun 2010 07:31:45 GMT
Author: fmeschbe
Date: Tue Jun 22 07:31:44 2010
New Revision: 956797

URL: http://svn.apache.org/viewvc?rev=956797&view=rev
Log:
SLING-1116 Improve FormReason to convey the human-readable message by toString()

Modified:
    sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/AuthenticationFormServlet.java
    sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormAuthenticationHandler.java
    sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormReason.java
    sling/trunk/bundles/extensions/formauth/src/test/java/org/apache/sling/formauth/FormReasonTest.java

Modified: sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/AuthenticationFormServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/AuthenticationFormServlet.java?rev=956797&r1=956796&r2=956797&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/AuthenticationFormServlet.java
(original)
+++ sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/AuthenticationFormServlet.java
Tue Jun 22 07:31:44 2010
@@ -144,10 +144,13 @@ public class AuthenticationFormServlet e
         final String reason = request.getParameter(FormAuthenticationHandler.PAR_J_REASON);
         if (reason != null) {
             try {
-                return FormReason.valueOf(reason).getMessage();
+                return FormReason.valueOf(reason).toString();
             } catch (IllegalArgumentException iae) {
                 // thrown if the reason is not an expected value, assume none
             }
+            
+            // no valid FormReason value, use raw value
+            return reason;
         }
 
         return "";

Modified: sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormAuthenticationHandler.java?rev=956797&r1=956796&r2=956797&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormAuthenticationHandler.java
(original)
+++ sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormAuthenticationHandler.java
Tue Jun 22 07:31:44 2010
@@ -58,22 +58,14 @@ import org.slf4j.LoggerFactory;
  *               value="Apache Sling Form Based Authentication Handler"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  * @scr.property nameRef="AuthenticationHandler.PATH_PROPERTY" value="/"
+ * @scr.property nameRef="AuthenticationHandler.TYPE_PROPERTY" value="FORM"
+ *               private="true"
  * @scr.service
  */
 public class FormAuthenticationHandler implements AuthenticationHandler,
         AuthenticationFeedbackHandler {
 
     /**
-     * The request parameter causing a 401/UNAUTHORIZED status to be sent back
-     * in the {@link #authenticate(HttpServletRequest, HttpServletResponse)}
-     * method if no credentials are present in the request (value is
-     * "sling:authRequestLogin").
-     *
-     * @see #requestCredentials(HttpServletRequest, HttpServletResponse)
-     */
-    static final String REQUEST_LOGIN_PARAMETER = "sling:authRequestLogin";
-
-    /**
      * The name of the parameter providing the login form URL.
      *
      * @scr.property valueRef="AuthenticationFormServlet.SERVLET_PATH"
@@ -276,6 +268,7 @@ public class FormAuthenticationHandler i
                 } else {
                     // signal the requestCredentials method a previous login failure
                     request.setAttribute(PAR_J_REASON, FormReason.TIMEOUT);
+                    info = AuthenticationInfo.FAIL_AUTH;
                 }
             }
         }
@@ -337,7 +330,11 @@ public class FormAuthenticationHandler i
 
         // append indication of previous login failure
         if (request.getAttribute(PAR_J_REASON) != null) {
-            final String reason = String.valueOf(request.getAttribute(PAR_J_REASON));
+            final Object jReason = request.getAttribute(PAR_J_REASON);
+            @SuppressWarnings("unchecked")
+            final String reason = (jReason instanceof Enum)
+                    ? ((Enum) jReason).name()
+                    : jReason.toString();
             targetBuilder.append(parSep).append(PAR_J_REASON);
             targetBuilder.append("=").append(URLEncoder.encode(reason, "UTF-8"));
         }

Modified: sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormReason.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormReason.java?rev=956797&r1=956796&r2=956797&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormReason.java
(original)
+++ sling/trunk/bundles/extensions/formauth/src/main/java/org/apache/sling/formauth/FormReason.java
Tue Jun 22 07:31:44 2010
@@ -24,27 +24,34 @@ enum FormReason {
      * The login form is request because the credentials previously entered very
      * not valid to login to the repository.
      */
-    INVALID_CREDENTIALS {
-        @Override
-        public String getMessage() {
-            return "Username and Password do not match";
-        }
-    },
+    INVALID_CREDENTIALS("Username and Password do not match"),
 
     /**
      * The login form is requested because an existing session has timed out and
      * the credentials have to be entered again.
      */
-    TIMEOUT {
-        @Override
-        public String getMessage() {
-            return "Session timed out, please login again";
-        }
-    };
+    TIMEOUT("Session timed out, please login again");
 
     /**
-     * Returns an english indicative message of the reason to request the login
-     * form.
+     * The user-friendly message returned by {@link #toString()}
      */
-    abstract String getMessage();
+    private final String message;
+
+    /**
+     * Creates an instance of the reason conveying the given descriptive reason.
+     *
+     * @param message The descriptive reason.
+     */
+    private FormReason(String message) {
+        this.message = message;
+    }
+
+    /**
+     * Returns the message set when constructing this instance. To get the
+     * official name call the <code>name()</code> method.
+     */
+    @Override
+    public String toString() {
+        return message;
+    }
 }

Modified: sling/trunk/bundles/extensions/formauth/src/test/java/org/apache/sling/formauth/FormReasonTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/formauth/src/test/java/org/apache/sling/formauth/FormReasonTest.java?rev=956797&r1=956796&r2=956797&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/formauth/src/test/java/org/apache/sling/formauth/FormReasonTest.java
(original)
+++ sling/trunk/bundles/extensions/formauth/src/test/java/org/apache/sling/formauth/FormReasonTest.java
Tue Jun 22 07:31:44 2010
@@ -24,12 +24,12 @@ public class FormReasonTest extends Test
 
     public void test_TIMEOUT() {
         assertEquals(FormReason.TIMEOUT,
-            FormReason.valueOf(FormReason.TIMEOUT.toString()));
+            FormReason.valueOf(FormReason.TIMEOUT.name()));
     }
 
     public void test_INVALID_CREDENTIALS() {
         assertEquals(FormReason.INVALID_CREDENTIALS,
-            FormReason.valueOf(FormReason.INVALID_CREDENTIALS.toString()));
+            FormReason.valueOf(FormReason.INVALID_CREDENTIALS.name()));
     }
 
     public void test_INVALID() {



Mime
View raw message