Search code examples
spring-securitystruts-1

Spring security form-login for struts


We have struts MVC in our app and want to now integrate spring security. I am able to integrate it successfully and able to deploy application.

In order to get custom login page we must add form-login to spring security xml file. I am having difficulty in integrating custom login pages.

Struts global forward

<global-forwards>
    <forward name="login" path="/" redirect="true"/>
</global-forwards>

When not logged in it will take us to login page Web xml login config

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.vm</form-login-page>
        <form-error-page>/loginError.vm</form-error-page>
    </form-login-config>
</login-config>

Above section in web.xml is removed as part of integrating with spring security. Rather I have following section in spring security

<intercept-url pattern="/**" access="hasRole('ROLE')" />
<form-login login-page="/login.vm" 
            authentication-failure-url="/loginError.vm" />

But when I try to login I won't get custom login page rather it just points url to IP:PORT/APP/login.vm and page is not present.

Login form has j_spring_security

action="j_spring_security_check"

What changes are required in order to get custom login? Should strut config be changed?


Solution

  • I'm guessing here, but I suspect that you are getting this as Spring Security does not understand/know about Velocity. I had a similair problem when I intergrated Spring Security into my Struts app using .jsp pages. In the end, I pointed login-page and authentication-failure-url to point to actions and loaded the jsp pages from there. I suggest that you try the same.