2012-01-20 154 views
1

我在Grails应用程序中使用spring security插件。为什么有登录页面获取显示grails spring security登录页面显示

  1. 用户导航到它直接
  2. 用户试图访问一个网页,只提供给注册用户

在这种情况下有两个原因我只想显示一条消息,如“您试图访问需要登录的页面”,但在登录页面的GSP代码中,我找不到区分(1)和(2)的方式), 这可能吗?

回答

0

您可以将各种弹簧安全配置的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'  
    } 
} 
1

当你重定向,春季安全存储在会话中的SavedRequestSPRING_SECURITY_SAVED_REQUEST_KEY项下,所以你可以检查的存在于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> 
相关问题