最近拿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 AuthorizationServerConfigurerAdapter {
@Autowired
Authentic

本文介绍了如何在SpringBoot2项目中集成OAuth2,详细讲述了服务端的配置要点,包括clientdetails与userdetails的继承关系,资源服务器的权限验证,以及如何避免session冲突。同时提到了客户端配置,参照官方教程并利用oauth2client拦截器实现自动授权重定向。
最低0.47元/天 解锁文章
2878

被折叠的 条评论
为什么被折叠?



