Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added error handling to login page.

  • Loading branch information...
commit 630d959b089b75f3a4c53bf125ef002f3881eb5c 1 parent 76f685b
meri authored
View
16 .../java/org/meri/simpleshirosecuredapplication/servlet/VerboseFormAuthenticationFilter.java
@@ -0,0 +1,16 @@
+package org.meri.simpleshirosecuredapplication.servlet;
+
+import javax.servlet.ServletRequest;
+
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
+
+public class VerboseFormAuthenticationFilter extends FormAuthenticationFilter {
+
+ @Override
+ protected void setFailureAttribute(ServletRequest request, AuthenticationException ae) {
+ String message = ae.getMessage();
+ request.setAttribute(getFailureKeyAttribute(), message);
+ }
+
+}
View
5 src/main/resources/Shiro.ini
@@ -4,7 +4,10 @@ sha256Matcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
sha256Matcher.hashAlgorithmName=SHA-256
iniRealm.credentialsMatcher = $sha256Matcher
-# authc filter configuration
+# replace form authentication filter with verbose filter
+authc = org.meri.simpleshirosecuredapplication.servlet.VerboseFormAuthenticationFilter
+# request parameter with login error information; if not present filter assumes 'shiroLoginFailure'
+authc.failureKeyAttribute=simpleShiroApplicationLoginFailure
# specify login page
authc.loginUrl = /simpleshirosecuredapplication/account/login.jsp
# name of request parameter with username; if not present filter assumes 'username'
View
9 src/main/webapp/simpleshirosecuredapplication/account/login.jsp
@@ -8,7 +8,14 @@
</head>
<body>
<%@include file="/simpleshirosecuredapplication/common/commonformstuff.jsp" %>
-<form name="loginform" action="" method="post">
+<%
+ String errorDescription = (String) request.getAttribute("simpleShiroApplicationLoginFailure");
+ if (errorDescription!=null) {
+%>
+Login attempt was unsuccessful: <%=errorDescription%>
+<%
+ }
+%><form name="loginform" action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Username:</td>
Please sign in to comment.
Something went wrong with that request. Please try again.