Really valuable information!
Thank you very much! I'll try it!

Best Regards,
Takahiko Kawasaki

On 2014/03/21, at 17:35, Dominic Farr <[email protected]> wrote:

Without a controller or extending the authc filter you only have what shiro
give you on login failure....just the page.

There is a failureKeyAttribute (default:shiroLoginFailure) which is added
to the page request on login failure. This will tell you what the error was
via an exception. Like Unknown account, or IncorrectCredentials, etc.

<%=request.getAttribute("shiroLoginFailure")%> to show it in its raw
format. Although, I wouldn't use jsp expressions or expose this type of
granular information on a log in form.

You could extend AuthenticationFormFilter and override setFailureAttribute
method and extend it for your requirements.

public class PreserveFormOnFailureFormAuthenticationFilter extends
FormAuthenticationFilter {
    @Override
    protected void setFailureAttribute(ServletRequest request,
AuthenticationException ae) {
        super.setFailureAttribute(request, ae);
        request.setAttribute("username", request.getParameter("username"));
    }
}

[main]
authc = PreserveFormOnFailureFormAuthenticationFilter


You can see it working in this demo app. See the readme section Extensions.

https://github.com/dominicfarr/skybird-shiro


On 21 March 2014 02:13, Takahiko Kawasaki <[email protected]> wrote:

> Hello,
>
> How can I set values to 'username' input field and 'rememberMe' checkbox
> in a login form when a user returns to the login page after login failure?
>
> My shiro.ini contains the following.
>
>     [main]
>     shiro.loginUrl = /sign_in.jsp
>
>     [urls]
>     /sign_in.jsp = authc
>
> And sign_in.jsp contains a form like below.
>
>     <form action="" method="POST" accept-charset="UTF-8">
>       <!-- Login ID or Email -->
>       <input placeholder="Login ID or Email"
>              value="What should be here?"
>              name="username" type="text" size="40"/>
>       <br/><br/>
>
>       <!-- Password -->
>       <input placeholder="Password"
>              value="" name="password"
>              type="password" value="" size="30"/>
>       <br/><br/>
>
>       <!-- Remember Me -->
>       <input name="rememberMe" type="checkbox" checked/>
>       Remember Me
>       <br/><br/>
>
>       <!-- Sign In -->
>       <input type="submit" value="Sign In">
>     </form>
>
> 'authc' filter works as documented. It does everything (= redirects to
> /sign_in.jsp on login failure) without intermediation of any controller.
> However, I don't know how to make authc set the values which the user
> input during the last login trial to the 'username' input field and the '
> rememberMe' checkbox (as to 'rememberMe', 'checked' should be added or
> removed accordingly).
>
> How should I write the form in sign_in.jsp?
>
> Best Regards,
> Takahiko Kawasaki
>

Reply via email to