springboot 2.0 使用 spring-security-oauth2 (对比 spring boot1.0 变化 记录踩过的坑)
一、 SecurityConfig extends WebSecurityConfigurerAdapter 中的变化
1、声明 bean AuthenticationManager 给容器
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean() ;
}
2 、声明 bean PasswordEncoder 给容器
@Bean
public
BCryptPasswordEncoder passwordEncoder() {
return
new
BCryptPasswordEncoder();
}
二、AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter 授权服务的变化
1、声明 bean AuthenticationManager 给容器
public
void
configure(ClientDetailsServiceConfigurer
clients
)
throws
Exception {
clients
.inMemory().withClient(
"android"
).scopes(
"aa"
)
.secret(
"$2a$10$d8z2cFCo5laSRpT1EPZB7OWLk/rk2Hk1QJAJt542CkTgKNnAvlHTC"
)
.authorizedGrantTypes(
"password"
,
"authorization_code"
,
"refresh_token"
,
"implicit"
)
.and().withClient(
"webapp"
).scopes(
"read"
,
"write"
).authorizedGrantTypes(
"implicit"
);
}
注意:.secret("$2a$10$d8z2cFCo5laSRpT1EPZB7OWLk/rk2Hk1QJAJt542CkTgKNnAvlHTC") 上一步声明的加密器,同样适用于通过client_id 和client_secret 验证。
2、关于 TOKET存放REDIS, SimpleGrantedAuthority 不能反序列化问题,暂时将toket 存放在内存中
org.springframework.security.core.authority.SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 420, local class serialVersionUID = 500