Default spring 3 login page translation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Default spring 3 login page translation

nano31
Hi everybody

it would maybe very useful for newcomer to provide with the "Thymeleaf + Spring 3" sample the Thymeleaf version of the default spring 3 login jsp page...
It is not so obvious for beginner to translate it and also remove jsp & fully switch to Thymeleaf...

I mean this login page:

<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt' %>
<%@ page import="org.springframework.security.ui.AbstractProcessingFilter" %>
<%@ page import="org.springframework.security.ui.webapp.AuthenticationProcessingFilter" %>
<%@ page import="org.springframework.security.AuthenticationException" %>
 
<html>
  <head>
    <title>Login</title>
  </head>

  <body>
    <c:if test="${not empty param.login_error}">
        Your login attempt was not successful, try again.<br/><br/>
        Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
    </c:if>
 
    <form name="f" action="<c:url value='j_spring_security_check'/>" method="POST">
                               
                     
User:<input type='text' name='j_username' value='<c:if test="${not empty param.login_error}"><c:out value="${SPRING_SECURITY_LAST_USERNAME}"/></c:if>'/>
Password:<input type='password' name='j_password'>
<input type="checkbox" name="_spring_security_remember_me">Don't ask for my password for two weeks
<input name="submit" type="submit">
<input name="reset" type="reset">
    </form>
    <a href="<c:url value="/j_spring_security_logout"/>">Logout
  </body>
</html>

Can you help me ?

Best regards
Nano
Reply | Threaded
Open this post in threaded view
|

Re: Default spring 3 login page translation

Zemi
Administrator
Hello,

are you using Spring-Security or JAAS?

My Spring-Security configuration is:
    ...
    <beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
        <beans:property name="defaultTargetUrl" value="/login.html" />
    </beans:bean>
    <beans:bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
        <beans:property name="defaultFailureUrl" value="/login-error.html" />
    </beans:bean>   
    ...

Then I need to map "login.html" and "login-error.html" inside a Spring Controller:
    @RequestMapping("/login.html")
    public String login() {
         return "login.html";
    }

    @RequestMapping("/login-error.html")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        return "login.html";
    }

Finally, this is my (simplified) login.html code:
        <p th:if="${loginError}">Invalid user or password</p>
        <form th:action="@{/j_spring_security_check}" method="post">
            <label for="j_username">Username</label>:
            <input type="text" id="j_username" name="j_username" /> 
            <label for="j_password">Password</label>:
            <input type="password" id="j_password" name="j_password" /> 
            <input type="submit" value="Log in" />
        </form>

Tell me if you need additional help.
Reply | Threaded
Open this post in threaded view
|

Re: Default spring 3 login page translation

nano31
Hello,

thank you very much for your quick answers, your response is very clear & useful !!!
I m trying to implement a custom spring-security AuthenticationProvider
and will post the full configuration as soon as it will works !!

Best regards
nano31