[英]grails spring security login page display
我在Grails應用程序中使用spring安全插件。 顯示登錄頁面有兩個原因
僅在(2)的情況下,我想顯示一條消息,例如“您試圖訪問需要登錄的頁面”,但是在登錄頁面的GSP代碼中,我找不到區分(1)的方法。 (2),這可能嗎?
重定向后,Spring Security在會話中的SPRING_SECURITY_SAVED_REQUEST_KEY
密鑰下存儲了一個SavedRequest
,因此您可以在auth.gsp
檢查其是否存在:
<g:if test='${session.SPRING_SECURITY_SAVED_REQUEST_KEY}'>
// display "you attempted to access a page that requires login"
</g:if>
<g:else>
// direct access to login
</g:else>
您可以更改各種spring安全配置的url以指向控制器,然后根據會話中的信息將其分支。 在1.3.7項目中做了類似
security {
authenticationFailureUrl = '/logout/doLogout'
afterLogoutUrl = '/logout/doLogout'
}
然后有
class LogoutController {
def doLogout = {
def wasHere = session.getAttribute('some-attribute-you-set')
if (wasHere) render view: 'requirelogin'
else render view: 'normallogin'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.