开发者

Spring Login pages works but my login page dont?

Spring Login pages works but my login page dont?

I am building a system in Spring3 with MySQL. if I use the Spring login page everything works great but I did not like the design so I made a login.jsp and change my context.xml file but I cant get my login.jsp to display??

[CODE]<http auto-config="true" use-expressions="true" >
        <intercept-url pattern="/friends/**" access="hasRole('ROLE_USER')" />

    <form-login login-processing-url="/EPA/j_spring_security_check"
                login-page="/login"
                authentication-failure-url="/login?login_error=t"/>
</http>[/CODE]

Below is the error

[CODE][DEBUG,FilterChainProxy] Converted URL to lowercase, from: '/spring_security_login'; to: '/spring_security_login'
[DEBUG,FilterChainProxy] Candidate is: '/spring_security_login'; pattern is /**; matched=true
[DEBUG,FilterChainProxy] /spring_security_login at position 1 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
[DEBUG,HttpSessionSecurityContextRepository] Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@bbe24eac: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bbe24eac: Principal: org.springframework.security.core.userdetails.User@5e22dd8: Username: guest; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@ffff4c9c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: BD1B281579EB6F9693C81DD20B0B4E9E; Granted Authorities: ROLE_USER'
[DEBUG,FilterChainProxy] /spring_security_login at position 2 of 10 in additional filter chain; firing Filter: 'LogoutFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 3 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 4 of 10 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 5 of 10 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 7 of 10 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
[DEBUG,AnonymousAuthenticationFilter] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bbe24eac: Principal: org.springframework.security.core.userdetails.User@5e22dd8: Username: guest; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@ffff4c9c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: BD1B281579EB6F9693C81DD20B0B4E9E; Granted Authorities: ROLE_USER'
[DEBUG,FilterChainProxy] /spring_security_login at position 8 of 10 in additional filter chain; firing Filter: 'SessionManagementFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
[DEBUG,FilterChainProxy] /spring_security_login at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityIntercept开发者_开发技巧or'
[DEBUG,ExpressionBasedFilterInvocationSecurityMetadataSource] Converted URL to lowercase, from: '/spring_security_login'; to: '/spring_security_login'
[DEBUG,ExpressionBasedFilterInvocationSecurityMetadataSource] Candidate is: '/spring_security_login'; pattern is /friends/**; matched=false
[DEBUG,FilterSecurityInterceptor] Public object - authentication not attempted
[DEBUG,FilterChainProxy] /spring_security_login reached end of additional filter chain; proceeding with original chain
[DEBUG,ExceptionTranslationFilter] Chain processed normally
[DEBUG,SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed[/CODE]


Spring security may not be finding your login.jsp and hence going to the default login page.

Do you have mapping somewhere which converts /login to the login.jsp in the appropriate location in your webapp? Something like

!-- View Resolver for JSPs -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>


Your form-login has login-processing-url="/EPA/j_spring_security_check but the request coming in is for /j_spring_security_check with no /EPA.


Value of login-page attribute is not a view name.

You need to do 2 things:
1. Map login-page attribute value to a controller. Example:

XML:

<form-login login-page="/mylogin.do" ...  />

Controller:

    @RequestMapping("/mylogin.do")
public String showLoginForm() { 
/* return a view name that will be used by your Viewresolver 
   if you return "login" then view resolver will resolve it to login.jsp
*/
... 
}  

2. Grant access to login page:

<intercept-url patter="/mylogin.do" access="permitAll" />  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜