最近拿oauth2练手,搭了oauth2的demo。
服务端配置
/**
* oauth2配置
* @author hao
* @Date 2018-04-19
*/
public class OAuth2ServerConfig {
/**
* oauth2资源服务器配置
* @author kdlq-hao
*/
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/auth/**", "/user/me")// 由oauth2拦截检验,根据token验证登录
.and()
.authorizeRequests()
.antMatchers("/auth/**")// /auth路径的资源需要token
.authenticated();
}
}
/**
* oauth2授权服务器配置
* @author kdlq-hao
*/
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends Au