2015-04-14 64 views
0

我使用的是Spring-Security-Rest,spring-security-core和spring-security-ui插件的Grails v2.4.2。自定义UserDetailsS​​ervice不被调用 - Grails和Spring安全性核心

我写了一个自定义UserDetailsS​​ervice使用户名不区分大小写。所有我做的只是试图覆盖

UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException 

com.example.core.CaseInsensitiveUserDetailsS​​ervice类定义为:

class CaseInsensitiveUserDetailsService extends GormUserDetailsService { 

    /** 
    * Make The Username Case Insensitive 
    */ 
    UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException { 
     Person.withTransaction { status -> 

      log.debug "Case Insensitive User Details Service" 

      // Find The Username 
      def user = Person.findByUsernameIlike(username) 

      // If User Not Found, Throw Exception 
      if (!user) { 
       log.warn "User not found: $username" 
       throw new UsernameNotFoundException('User not found', username) 
      } 

      Collection<GrantedAuthority> authorities = loadAuthorities(user, username, loadRoles) 
      createUserDetails user, authorities 
     } 
    } 
} 

resources.groovy包含:

beans = { 

    userDetailsService(com.example.core.CaseInsensitiveUserDetailsService) 

    credentialsExtractor(Grails24CredentialExtractor) 

    // Some Custom Filters Are Also Defined (securityContextRepository, securityContextPersistenceFilter, multipartResolver) 

} 

它编译成功,但它从来没有实际运行我的自定义CaseInsensitiveUserDetailsS​​ervice。在控制台中,我从实际的GormUserDetailsS​​ervice中看到调试语句,而不是我自定义的调试语句。可以做些什么来使用我的自定义UserDetailsS​​ervice?

** 注:我一直在关注这两个教程:

  1. http://www.stevideter.com/2012/11/17/case-insensitive-usernames-using-spring-security-core-plugin-for-grails/
  2. http://grails-plugins.github.io/grails-spring-security-core/guide/userDetailsService.html
+0

您是否将其创建为插件,然后将其安装到应用程序中? – John

+0

不,它只是一个类 –

+0

你可以显示你的配置(对安全和日志记录部分感兴趣)以及请求和响应的输出吗? –

回答

0

做了不同的插件类似的,当我有一个类似的问题, Spring Security和布线需要明确地按名称排列。尝试在resources.groovy

userDetailsService(com.example.core.CaseInsensitiveUserDetailsService) { bean-> 
    bean.autowire = "byName" 
} 
+0

这没有意义。自动装配更方便,因为你不需要明确定义每一个,但是你可以随时做到这一点 –

相关问题