SpringCloud-OAuth2(二):实战篇

这篇讲的内容是:Oauth2在SpringBoot/SpringCloud中的实战。

SpringBoot版本:2.2.5.Release
SpringCloud版本:Hoxton.SR9
JDK版本:1.8

1:POM配置

    
        
        
            spring-cloud-starter-oauth2
            org.springframework.cloud
        
        
        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
        
            org.jasypt
            jasypt
            1.9.2
        
    

2:关键配置

2.1:认证服务配置-WebAuthorizationConfig

@Configuration
@EnableAuthorizationServer
public class WebAuthorizationConfig extends AuthorizationServerConfigurerAdapter {

    private final AuthenticationManager authenticationManager;
    private final UserDetailsService userDetailsService;
    private final PasswordEncoder passwordEncoder;
    private final TokenStore tokenStore;
    private final AuthorizationCodeServices authorizationCodeServices;
    private final AuthTokenExceptionHandler authTokenExceptionHandler;

    public WebAuthorizationConfig(AuthenticationManager authenticationManager,
                                  UserDetailsService userDetailsService,
                                  PasswordEncoder passwordEncoder,
                                  TokenStore tokenStore,
                                  AuthorizationCodeServices authorizationCodeServices,
                                  AuthTokenExceptionHandler authTokenExceptionHandler) {
        this.authenticationManager = authenticationManager;
        this.userDetailsService = userDetailsService;
        this.passwordEncoder = passwordEncoder;
        this.tokenStore = tokenStore;
        this.authorizationCodeServices = authorizationCodeServices;
        this.authTokenExceptionHandler = authTokenExceptionHandler;
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        String secret = Passw

你可能感兴趣的:(spring,cloud,spring,boot,java)