English 中文(简体)
Spring Security Custom freemarker form
原标题:

I m currently working on a project were we use freemarker as a template language. Instead of using the defualt login form I have created a custom controller and a custom freemarker view which goes along with that controller

Code:

@Controller
public class LoginController {
private static finaal String LOGIN = "components/security/login";

@RequestMapping("/security/login")
public String login(){

    return LOGIN;
   }
}

my freemarker template:

HTML Code:

<form action="${rc.contextPath}/j_spring_security_check" method="post">
    <label for="username">Username</label><input type="text" id="username" name="j_username"><br/>
    <label for="password">Password</label><input type="text" id="password" name="j_password"><br/>
   <input type="submit" value="Login!">
</form>

my applicationContext-security.xml

  <http>
    <logout/>
        <intercept-url pattern="/*" access="ROLE_ADMIN, ROLE_GUEST"/>
        <intercept-url pattern="/security/login" filters="none"/>
        <form-login login-page="/security/login" />
    </http>

the login works like a charm BUT, when a user enters a wrong username or password no error messages are shown and I can t figure out how to do it. Could you please help me with that.

最佳回答

The code for those who wonder how i did it:

<#if Session.SPRING_SECURITY_LAST_EXCEPTION?? && Session.SPRING_SECURITY_LAST_EXCEPTION.message?has_content>
    <@spring.message "login.bad.credentials"/>
</#if>
问题回答

You need to set the error page:

<http>
   ...
   <form-login authentication-failure-url="/loginError.jsp" default-target-url="/start.jsp" />
   ...
</http>

In loginError.jsp:

...
Login error. Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
...




相关问题
Spring Security Encrypt MD5

I have a java web application using spring framework and spring security for its login. In my database I have my passwords encrypted to MD5 before being saved. I added in my application-config.xml ...

Grails security [closed]

Which is the best security solution for grails among acegi, jsecurity and Stark security?

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

Spring Security Custom freemarker form

I m currently working on a project were we use freemarker as a template language. Instead of using the defualt login form I have created a custom controller and a custom freemarker view which goes ...

Spring Security - Different Filter Entry Points based on Role

I m developing a webapp which allows for two types for users - User and Admin. There s are two parts of the site - the User side, and the Admin side. I m using Spring Security to secure both sites ...

热门标签