2016-09-23 37 views
0

使用Spring SAML安全性,我已將我們的應用程序作爲服務提供者啓用。這很好,我使用了一個自定義的WickedUserDetails(從GrailsUser擴展而來),並且所有東西都按照它應該填充。通過SAML登錄到Grails應用程序時,無法訪問LogoutController中的UserDetailsS​​ervice

現在我試圖爲SAML實現全局註銷,但即使在我可以做任何「幻想」之前,我注意到當我打開常規的LogoutController時,我無法訪問WickedUserDetails。我只有一個匿名的grails用戶。

當我嘗試訪問/ logout/index和/ logout/special時,會發生此行爲。當我使用SlogoutController時,它按預期工作。

class LogoutController { 

    def springSecurityService 

    /** 
    * Index action. Redirects to the Spring security logout uri. 
    */ 
    def index = { 
     // Populates with ANONYMOUS GRAILS USER when logged in via SAML 
     // but with WickedUserDetails when logged in via the "normal" Spring Security mechanism 
     def check = springSecurityService.principal 

     redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' 
    } 

    def special = { 
     // Populates with ANONYMOUS GRAILS USER when logged in via SAML 
     // but with WickedUserDetails when logged in via the "normal" Spring Security mechanism 
     def check = springSecurityService.principal 

     redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' 
    } 
} 

class SlogoutController { 

    def springSecurityService 

    def special = { 
     // Populates with WickedUserDetails 
     def check = springSecurityService.principal 

     redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' 
    } 

    // Populates with WickedUserDetails 
    def index = { 
     def check = springSecurityService.principal 

     redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' 
    } 

} 

在我Config.groovy中,我沒有設置任何特殊攔截的URL,我必須註銷URL唯一的參考是:

grails.plugin.springsecurity.secureChannel.definition = [ 
    '/login/**' :  'REQUIRES_SECURE_CHANNEL', 
    '/logout/**' :  'REQUIRES_INSECURE_CHANNEL' 
] 

這是我唯一的參考設置在UrlMappings:

"/logout/$action?"(controller: "logout")  

有人可以請向我解釋爲什麼會發生這種情況?我可以在我的應用程序中提出解決方法,但我對發生的事情非常好奇。

回答

0

好的,問題是我的捷徑。在最初的身份驗證提供程序中,我沒有使用SAML憑據更新定製令牌

Authentication authenticate(Authentication authentication) { 

    if (authentication instanceof SAMLAuthenticationToken) { 

     def samlToken = super.authenticate(authentication) 
     if (samlToken) { 
      String username = samlToken.principal 
      LightweightContact contact = new LightweightContact(username: username)       

      contact = contact.findByUsername() 

      boolean isContactValid = contactValid(contact, samlToken) 

      if (isContactValid) { 
       WickedAuthenticationToken wickedToken = MyNormalSpringCustomWickedAuthenticationProvider.getWickedAuthenticationToken(contact) 
       // -------- I needed to explicitly set the credentials here ----------------------- 
       wickedToken.setCredentials(samlToken.credentials) 
       return wickedToken 
      } 
     } 
    } 

    // the authentication token was not of the correct class 
    // or no user was found for it 
    return null 
} 
相關問題