Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java配置中带有自定义身份验证管理器的Oauth授权服务器_Java_Spring_Spring Security_Oauth 2.0_Spring Security Oauth2 - Fatal编程技术网

Java配置中带有自定义身份验证管理器的Oauth授权服务器

Java配置中带有自定义身份验证管理器的Oauth授权服务器,java,spring,spring-security,oauth-2.0,spring-security-oauth2,Java,Spring,Spring Security,Oauth 2.0,Spring Security Oauth2,我在应用程序中有多个身份验证管理器。我用豆名来区分它们。与oauth authorization server相关的部分xml配置看起来很好: <oauth:expression-handler id="oauthExpressionHandler" /> <oauth:web-expression-handler id="oauthWebExpressionHandler" /> <oauth:authorization-server client-detail

我在应用程序中有多个身份验证管理器。我用豆名来区分它们。与oauth authorization server相关的部分xml配置看起来很好:

<oauth:expression-handler id="oauthExpressionHandler" />
<oauth:web-expression-handler id="oauthWebExpressionHandler" />

<oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler" >
    <oauth:authorization-code disabled="true" />
    <oauth:implicit disabled="false" />
    <oauth:refresh-token disabled="false" />
    <oauth:client-credentials disabled="false" />
    <oauth:password authentication-manager-ref="authenticationManager" />
</oauth:authorization-server>

<oauth:resource-server id="resourceServerFilter" resource-id="resource-id" token-services-ref="tokenServices" />

<sec:authentication-manager id="clientAuthenticationManager">
    <sec:authentication-provider user-service-ref="clientDetailsUserService" />
</sec:authentication-manager>

<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager"
      xmlns="http://www.springframework.org/schema/security">
    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
    <anonymous enabled="false" />
    <http-basic entry-point-ref="clientAuthenticationEntryPoint" />
    <!-- include this only if you need to authenticate clients via request parameters -->
    <custom-filter ref="oauthClientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
    <access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
然而,它仍然抱怨有多个身份验证管理器,尽管我显式地设置了
端点。authenticationManager(authenticationManager)

通过一些调试,我可以看到它试图在类WebSecurityConfigureAdapter中配置它,并且它在
authenticationManager()
中遇到多个身份验证管理器。我能覆盖它吗?或者我遗漏了什么

  • AuthorizationServer—这里有一种防止Spring在上失败的方法
    org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter#authenticationManager
    通过简单重写方法
    org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)
    -
  • ResourceServer—不幸的是,没有类似的方法来处理相应的问题。您所能做的最好的事情是将全局身份验证管理器的实例数减少到正好一个
  • @Configuration
    @EnableAuthorizationServer
    protected static class OAuth2AuthConfig extends AuthorizationServerConfigurerAdapter {
    
        @Resource(name = "authenticationManager")
        private AuthenticationManager authenticationManager;
    
        @Resource
        private OAuth2AuthenticationEntryPoint authenticationEntryPoint;
    
        @Resource(name = "clientDetails")
        private ClientDetailsService clientDetailsService;
    
        @Resource
        private TokenStore tokenStore;
    
        @Resource
        private TokenStoreUserApprovalHandler userApprovalHandler;
    
        @Override
        public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
            security.authenticationEntryPoint(authenticationEntryPoint);
        }
    
        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints.authenticationManager(authenticationManager)
                    .userApprovalHandler(userApprovalHandler)
                    .tokenStore(tokenStore);
        }
    
        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.withClientDetails(clientDetailsService);
        }
    }
    
    @Configuration
    @EnableResourceServer
    protected static class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter {
    
        @Resource
        private DefaultTokenServices tokenServices;
    
        @Resource(name = "authenticationManager")
        private AuthenticationManager authenticationManager;
    
        @Override
        public void configure(ResourceServerSecurityConfigurer resources) {
            resources.resourceId(RESOURCE_ID).tokenServices(tokenServices).authenticationManager(authenticationManager);
        }
    }