我是Grails的新手,所以我可能会犯些错误,但也许你可以帮我弄明白。所以我有这个简单的Grails应用程序与Spring安全插件工作正常,我认为。问题是,上GSP页面春季安全标签不显示我期待的信息,例如场景:Grails Spring安全插件和GSP标签不能正常工作
我已经
/basket/placeOrder
端点保护,所以当我打它从浏览器,它表明了我的登录页面。我登录使用正确的凭据,并将其转发我预期的页面(所以看起来像认证成功)
- 当我的控制器之一,我用
println springSecurityService.currentUser.email
它打印在控制台上正确的数据。 但后来我尝试在GSP使用例如:
< sec:ifNotLoggedIn> NOT LOGGED < /sec:ifNotLoggedIn>
它显示
NOT LOGGED
。同样如果我尝试使用例如<sec:loggedInUserInfo field="email" />
检索某些用户信息,它不会显示任何字符串。就像Spring Security不与GSP绑定一样。
我做错了什么?缺少一些配置? 谢谢。
编辑
当我看着它使用springSecurityService.isLoggedIn()
SecurityTagLib
ifNotLoggedIn
功能。当我从控制器调用它时,它会返回预期的结果。当我在这两个控制器和GSP打印session
,它都是一样的:
SPRING_SECURITY_CONTEXT = org.springframework.security.core.c[email protected]: Authentication: org.springframew[email protected]46b66c80: Principal: [email protected]: Username: kamil; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]43458: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: AAB2217ABEE7EAF752573D44914B0005; Granted Authorities: ROLE_ADMIN
我设法在调试运行我的应用程序,它会变得更加怪异。首先我的控制器断点显示SpringSecurityService
对象,它的值为currentUser
正确设置。然后,同样的请求仍然处理我的断点设置在SecurityTagLib
(grails只是跟随流控制器 - >呈现),其中有同一个SpringSecurityService对象(这意味着它是相同的bean,没有重复等),但它只是缺少所有用户数据。奇怪的!
一定出事了,但不知道是什么...