在Spring Security OAuth中,如何将passwordEncoder用于客户端机密?

加里·F

我正在尝试使用我的Spring Security Oauth2 BCrypt存储在数据库中的客户端机密。我可以看到JdbcClientDetailsService有一个setPasswordEncoder方法(如本问题所述)。但是,“ClientDetailsServiceConfigurerAuthorizationServerConfigurerAdapter”没有显示任何明显的设置密码编码器的方法。有谁知道如何做到这一点?我包括了授权服务器配置:

@Configuration
@EnableAuthorizationServer
public static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private DataSource dataSource;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private TokenStore tokenStore;
    @Autowired
    private UserApprovalHandler userApprovalHandler;
    @Autowired
    private ClientDetailsService clientDetailsService;
    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.jdbc(dataSource);
    }

    @Bean
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }

    @Bean
    public TokenApprovalStore tokenApprovalStore() {
        TokenApprovalStore tokenApprovalStore = new TokenApprovalStore();
        tokenApprovalStore.setTokenStore(tokenStore);
        return tokenApprovalStore;
    }

    @Bean
    public UserApprovalHandler userApprovalHandler() {
        LocalUserApprovalHandler handler = new LocalUserApprovalHandler();
        handler.setApprovalStore(tokenApprovalStore());
        handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
        handler.setClientDetailsService(clientDetailsService);
        handler.setUseApprovalStore(true);
        return handler;
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
        endpoints.tokenStore(tokenStore)
                .userApprovalHandler(userApprovalHandler)
                .authenticationManager(authenticationManager);
    }


    @Override
    public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
        oauthServer.realm("abcdefgh/client");
    }

}
加里·F

从版本2.0.5中,passwordEncoder(...)方法现在上都可用ClientDetailsServiceConfigurerAuthorizationServerSecurityConfigurer延伸时被提供AuthorizationServerConfigurerAdapterPasswordEncoder两者都使用相同的实现,并且配置相对容易。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将Spring Security OAuth 2.0客户端存储配置为数据库

Spring Security OAuth 2.0-授权代码授予始终需要客户端机密

我如何将凭证从Rest客户端发布到Spring Security Rest API?

用于Spring Security OAuth2的Web和移动客户端

弃用spring-security-oauth作为客户端

Spring Security,OAUTH2,动态客户端秘密

Spring Security OAuth 2和客户端凭证流

Spring Security中如何调用PasswordEncoder?

Spring Security OAuth 2:如何在JavaScript客户端中使用访问令牌

Spring Security oauth2客户端-如何获取JWT令牌

Spring Security中具有密码授予权限的oAuth2客户端

使用Spring Security的PasswordEncoder

用于2足(客户端凭据)OAuth2服务器的Spring-security上下文设置

Spring Boot 2.0 M6 (Spring Security 5.0) 中的 oAuth2 REST 客户端

将javafx客户端与Spring Boot和Spring Security结合使用

如何使用Spring Security的新PasswordEncoder

Spring Security OAuth2客户端-重定向过多

带有自定义提供程序的 Spring Boot + Security OAuth2.0 客户端

Spring Security 5 OAuth2客户端密码授予类型

Spring security Oauth2 客户端凭据水平扩展

如何配置Spring Security

Spring Security中的NoSuchBeanDefinitionException

Spring Security中的AuthenticationSuccessHandler

Spring Security 中的 PostMapping

CAS客户端(spring boot + spring security)如何从CAS Server获取更多字段?

无法使用角度客户端注销Spring Security

带有Keycloak的Spring Security客户端PKCE

Spring Security 5.1.1 OAuth2客户端连接到spring-security-oauth2身份验证服务器

客户端机密+在Spring OAuth2中刷新访问令牌