【问题标题】:Grails 4 with spring-security-oauth2-provider:4.0.0-RC1带有 spring-security-oauth2-provider:4.0.0-RC1 的 Grails 4
【发布时间】:2020-06-22 21:47:50
【问题描述】:

我用这个插件创建了一个 Grails 4.0.2 应用程序:

compile 'org.grails.plugins:spring-security-core:4.0.0'
compile 'org.grails.plugins:spring-security-oauth2-provider:4.0.0-RC1'

我遵循了文档:https://bluesliverx.github.io/grails-spring-security-oauth2-provider/v3/manual/index.html

在我尝试通过以下方式使用身份验证后:

curl -X POST \
     -d "client_id=my-client" \
     -d "grant_type=password" \
     -d "username=my-user" \
     -d "password=my-password" \
     -d "scope=read" http://localhost:8080/oauth/token

但我收到此错误:

    URI
/oauth/token
Class
java.lang.IllegalArgumentException
Message
There is no PasswordEncoder mapped for the id "null"
Trace
    Line | Method
->>  244 | matches                        in org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    198 | matches                        in org.springframework.security.crypto.password.DelegatingPasswordEncoder
|     90 | additionalAuthenticationChecks in org.springframework.security.authentication.dao.DaoAuthenticationProvider
|    166 | authenticate                   in org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider
|    175 | authenticate . . . . . . . . . in org.springframework.security.authentication.ProviderManager
|    123 | attemptAuthentication          in org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter
|    212 | doFilter . . . . . . . . . . . in org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
|    334 | doFilter                       in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    105 | doFilter . . . . . . . . . . . in org.springframework.security.web.context.SecurityContextPersistenceFilter
|    334 | doFilter                       in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     58 | doFilter . . . . . . . . . . . in grails.plugin.springsecurity.web.SecurityRequestHolderFilter
|    334 | doFilter                       in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    215 | doFilterInternal . . . . . . . in org.springframework.security.web.FilterChainProxy
|    178 | doFilter                       in     ''
|    193 | internalDoFilter . 

我找到了这个解决方案:

https://mkyong.com/spring-boot/spring-security-there-is-no-passwordencoder-mapped-for-the-id-null/

但我不知道如何将解决方案应用到 grails 项目中。

谁能帮帮我?

谢谢, 克里斯蒂安

【问题讨论】:

    标签: spring grails oauth-2.0


    【解决方案1】:

    我通过设置 resources.groovy 暂时解决了我的问题

    beans = {
        userSecPasswordEncoderListener(UserSecPasswordEncoderListener)
         passwordEncoder(NoOpPasswordEncoder) {
    
        }
    

    【讨论】:

      【解决方案2】:

      我也遇到过这个问题,但我相信我找到了答案。

      将此添加到 oauth 插件初始化脚本生成的 Client 类中:

         static mapping = {
             autowire true
         }
      

      或者将这个添加到runtime.groovy,默认启用服务注入到所有域类 grails-app/conf/runtime.groovy

      grails.gorm.default.mapping = {
              autowire true
      }
      

      至于发生这种情况的原因。客户端域类在插入之前尝试调用此代码:

      protected void encodeClientSecret() {
              clientSecret = clientSecret ?: NO_CLIENT_SECRET
              clientSecret = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(clientSecret) : clientSecret
      }
      

      但由于 spring 安全服务为空,它无法正确编码密码。 Grails 文档提到,从 Grails 3.3.0 开始,服务不再默认注入到域类中,需要注入该映射。

      【讨论】:

        猜你喜欢
        • 2012-06-27
        • 2013-12-31
        • 1970-01-01
        • 2015-07-15
        • 2015-11-23
        • 2018-06-27
        • 2017-12-16
        • 1970-01-01
        • 2017-10-02
        相关资源
        最近更新 更多