Grails Ldap 记住我 IllegalArgumentException

Posted

技术标签:

【中文标题】Grails Ldap 记住我 IllegalArgumentException【英文标题】:Grails Ldap Remember Me IllegalArgumentException 【发布时间】:2014-03-13 22:08:02 【问题描述】:

我不得不再次尝试解决 Ldap 的这个问题——记住我的功能,但又是它引起的问题。

目前我有支持 Ldap 身份验证的 Grails 2.2.4 应用程序,但检查记住我选项会导致错误如下:

java.lang.IllegalArgumentException: Dynamic method get<Artefact>Class(artefactName) requires a single String parameter
    at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.invokeMethod(DefaultGrailsApplication.java:673)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at grails.plugin.springsecurity.userdetails.GormUserDetailsService.loadUserByUsername(GormUserDetailsService.groovy:57)
    at grails.plugin.springsecurity.userdetails.GormUserDetailsService.loadUserByUsername(GormUserDetailsService.groovy:82)
    at org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices.onLoginSuccess(TokenBasedRememberMeServices.java:178)
    at org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.loginSuccess(AbstractRememberMeServices.java:258)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.successfulAuthentication(AbstractAuthenticationProcessingFilter.java:324)
    at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.successfulAuthentication(RequestHolderAuthenticationFilter.java)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.successfulAuthentication(AbstractAuthenticationProcessingFilter.java:298)
    at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.successfulAuthentication(RequestHolderAuthenticationFilter.java)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:235)
    at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:66)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:701)

我尝试了各种方法来解决这个问题,但我只是不了解它的本质。它给了我关于可能出错的完全零信息。 如果有人遇到类似的问题,我会很感激一些线索。我想“记住我”来使用 cookie。

记住我的 Ldap 配置:

grails.plugin.springsecurity.ldap.rememberMe.detailsManager.groupSearchBase='ou=LALALAL,O=LALALAL,C=LALALAL'
grails.plugin.springsecurity.ldap.rememberMe.usernameMapper.userDnBase='O=LALALAL,C=LALALAL'
grails.plugin.springsecurity.ldap.rememberMe.usernameMapper.usernameAttribute="SOME ID"

为可能需要的人编辑:

问题出在 PersistentTokenBasedRememberMeService 中的一行

UserDetails user = getUserDetailsService().loadUserByUsername(token.getUsername());

它想使用 GormUserDetailsS​​ervice 来检索有关用户的数据,但是由于 Ldap 失败了。没有可从中获取数据的数据库。

可能的解决方法是将 UserDetailsS​​ervice 替换为自定义类。

【问题讨论】:

你能举例说明 UserDetailsS​​ervice 类在哪里以及用什么替换它吗? 【参考方案1】:

使用自定义 UserDetails 类和 CustomPersistentTokenBasedRememberMeService 修复。

【讨论】:

以上是关于Grails Ldap 记住我 IllegalArgumentException的主要内容,如果未能解决你的问题,请参考以下文章

Grails,Spring Security LDAP 插件

在带有 CAS 和 LDAP 的 Grails 中使用 Spring Security

未分配 Grails Spring Security LDAP“defaultRole”

如何使用 spring-security-core-ldap 插件在 grails 中实现 LDAP 身份验证?

带有 SpringSecurity、本地用户和 LDAP 的 Grails

Grails spring security LDAP 从 LDAP 基础获取 ROLE