我是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,沒有重複等),但它只是缺少所有用戶數據。奇怪的!
一定出事了,但不知道是什麼...