hi,
I'm using spring security 2.0 in combination with JSF.
There is a real strange behaviour when I'm trying to use the final step of the remember-me feature. Let me explain in more detail:
1. I log in to my application successfully via a form; this brings me to the secured area
2. I close the browser
3. I successfully check that the cookie is set
4a. I reopen the browser and try to get access to the secured area => this works
LOG:
Code:
Authentication event AuthenticationSuccessEvent: user@test.com; details: org.springframework.security.ui.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null
Authentication event InteractiveAuthenticationSuccessEvent: user@test.com; details: org.springframework.security.ui.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null
Security authorized for authenticated principal: org.springframework.security.providers.rememberme.RememberMeAuthenticationToken@4f2c9185: Principal: org.springframework.security.userdetails.User@b07ed00: Username: user@test.com; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER, user; Password: [PROTECTED]; Authenticated: true; Details: org.springframework.security.ui.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_USER, user; secure object: FilterInvocation: URL: /profiles/index.jsf; configuration attributes: [ROLE_USER]
5a. BUT: i have a managed bean that gets the username for me, so that i can write sth like this in facelet *.xhtml files of the secured area:
Code:
<p>Hello #{authenticationController.user.username}</p>
The beans method is like this:
Code:
public User getUser() {
final HttpServletRequest request = getRequest();
SecurityContextImpl securityContextHolder = (SecurityContextImpl) request.getSession().getAttribute( HttpSessionContextIntegrationFilter.SPRING_SECURITY_CONTEXT_KEY );
Authentication auth = securityContextHolder.getAuthentication();
return (User) auth.getPrincipal();
}
AND THIS delivers a NullPointerException (on securityContextHolder.getAuthentication()
.
Note, that it does work when i do a normal login and then go to this page (Steps 1+2)
4b. And here is another strange thing:
After reopening the browser I tried to go to the public area first and then go to the secured area => Now this works (NO NullPointer anymore)
really strange and I can't really figuere out why.
I'd appreciate any hints!
Thanks in advance
My Securitycontext is like this:
Code:
<http auto-config="false" >
<intercept-url pattern="/profiles/**" access="ROLE_USER"/>
<form-login login-page="/login.jsf"/>
<logout />
<remember-me key="rememberMeKey" user-service-ref="userService" />
</http>
...