2016-09-23 6 views
0

Используя Spring SAML Security, я включил наше приложение в качестве поставщика услуг. Это отлично работает, я использую пользовательские WickedUserDetails (расширенные от GrailsUser), и все заполняется так, как должно.Нет доступа к UserDetailsService в LogoutController при входе в приложение Grails через SAML

Теперь я пытаюсь реализовать глобальный выход для SAML, но даже до того, как я смогу сделать что-нибудь «причудливое», я заметил, что когда я попадал на наш обычный LogoutController, у меня нет доступа к WickedUserDetails. У меня просто есть анонимный пользователь Grails.

Такое поведение возникает, когда я пытаюсь получить доступ/выход из системы/индекс и/выход из системы/специальный. Он работает как ожидается, когда я использую 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' 
] 

Это единственная ссылка у меня есть указанному в адресе:

"/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 
}