I am new to Grails, so probably I am making something wrong, but maybe you can help me to figure it out. So I have this simple Grails application with Spring Security plugin working fine I think. The problem is, that on GSP page Spring Security tags are not showing information I am expecting, example scenario:
I have
/basket/placeOrderendpoint secured, so when I hit it from browser it shows me login page.I log in using correct credentials, and it forwards me to expected page (so looks like authentication is successful)
- When in one of my controllers I use
println springSecurityService.currentUser.emailit prints correct data on the console. But Then I try to use on GSP for example:
< sec:ifNotLoggedIn> NOT LOGGED < /sec:ifNotLoggedIn>It shows
NOT LOGGED. Same if I try to retrieve some user info using for example<sec:loggedInUserInfo field="email" />it doesn't show any string. Just like Spring Security is not bind with GSP.
I am doing something wrong? Missing some configuration? Thanks.
EDIT
When I looked into SecurityTagLib ifNotLoggedIn function it uses springSecurityService.isLoggedIn(). When I call the same from controller it returns expected result. When I print session in both controller and GSP, it is all the same:
SPRING_SECURITY_CONTEXT = org.springframework.security.core.context.SecurityContextImpl@46b66c80: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@46b66c80: Principal: grails.plugin.springsecurity.userdetails.GrailsUser@611913a: Username: kamil; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@43458: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: AAB2217ABEE7EAF752573D44914B0005; Granted Authorities: ROLE_ADMIN
I managed to run my app on debug, and it gets even more weird. First my breakpoint on controller showed SpringSecurityService object and it has value currentUser set properly. Then, the same request still processing hit my breakpoint set in SecurityTagLib (grails is just following flow controller->rendering) which has THE SAME SpringSecurityService object (which means it is the same bean, no duplicate etc.) but it is just missing all user data. Weird!
Something must be wrong, but have no idea what...