Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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
如何转换<;oauth:授权服务器>;到Java配置?_Java_Spring_Spring Security_Spring Security Oauth2_Spring Java Config - Fatal编程技术网

如何转换<;oauth:授权服务器>;到Java配置?

如何转换<;oauth:授权服务器>;到Java配置?,java,spring,spring-security,spring-security-oauth2,spring-java-config,Java,Spring,Spring Security,Spring Security Oauth2,Spring Java Config,我相信所有这些都只是使用默认值,我们使用jdbc作为令牌存储,客户机详细信息是默认的变量。看起来我们有一个自定义的userApprovalHandler <oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler">

我相信所有这些都只是使用默认值,我们使用jdbc作为令牌存储,客户机详细信息是默认的变量。看起来我们有一个自定义的userApprovalHandler

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

因为这似乎只是一个小片段,如果您能提供一个完整的配置类示例,并提供这些选项,那么java配置应该不会太大。

请在下面找到一个示例代码:-

    @Configuration
    @EnableAuthorizationServer
    public class OAuth2CustomConfig extends
            AuthorizationServerConfigurerAdapter {

        @Autowired
        private AuthenticationManager authenticationManager;

        @Bean
        public JwtAccessTokenConverter jwtAccessTokenConverter() {
            JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
            KeyPair keyPair = new KeyStoreKeyFactory(new ClassPathResource(
                    "keystore.jks"), "foo".toCharArray()).getKeyPair("bar");
            converter.setKeyPair(keyPair);
            return converter;
        }

        @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer)
                throws Exception {
            oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess(
                    "isAuthenticated()");
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients)
                throws Exception {
            clients.inMemory()
                    .withClient("xxxx")
                    .secret("xxxxsecret")
                    .authorizedGrantTypes("authorization_code",
                            "refresh_token", "password").scopes("openid");
        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {
            endpoints.authenticationManager(authenticationManager)
                    .accessTokenConverter(jwtAccessTokenConverter());
        }

    }
    @Configuration
    @EnableAuthorizationServer
    public class OAuth2CustomConfig extends
            AuthorizationServerConfigurerAdapter {

        @Autowired
        private AuthenticationManager authenticationManager;

        @Bean
        public JwtAccessTokenConverter jwtAccessTokenConverter() {
            JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
            KeyPair keyPair = new KeyStoreKeyFactory(new ClassPathResource(
                    "keystore.jks"), "foo".toCharArray()).getKeyPair("bar");
            converter.setKeyPair(keyPair);
            return converter;
        }

        @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer)
                throws Exception {
            oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess(
                    "isAuthenticated()");
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients)
                throws Exception {
            clients.inMemory()
                    .withClient("xxxx")
                    .secret("xxxxsecret")
                    .authorizedGrantTypes("authorization_code",
                            "refresh_token", "password").scopes("openid");
        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {
            endpoints.authenticationManager(authenticationManager)
                    .accessTokenConverter(jwtAccessTokenConverter());
        }

    }