通过SAML

时间:2016-09-23 14:10:21

标签: grails spring-security spring-saml

使用Spring SAML Security,我已将我们的应用程序作为服务提供商启用。这很好用,我使用自定义的WickedUserDetails(从GrailsUser扩展),并且所有内容都应该填充。

现在我正在尝试为SAML实施全局注销,但即使在我可以做任何事情之前,我都会尝试#34; fancy,"我注意到当我点击常规的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")    

有人可以向我解释为什么会出现这种情况吗?我可以在我的应用程序中找到一种解决方法,但我对于发生了什么感到非常好奇。

1 个答案:

答案 0 :(得分: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
}