如何转换<;oauth:授权服务器>;到Java配置?
我相信所有这些都只是使用默认值,我们使用jdbc作为令牌存储,客户机详细信息是默认的变量。看起来我们有一个自定义的userApprovalHandler如何转换<;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">
<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());
}
}