当前位置:   article > 正文

【Spring Security OAuth2】客户端授权模式(client credentials)~资源服务配置_oauth2授权(client credentials)

oauth2授权(client credentials)

例子基于Spring Boot 2.1.7.RELEASE ,使用mysql数据库
本例中资源服务为独立的应用

参考资源: Resource Server Configuration

  • 添加一个实现了ResourceServerConfigurer接口的实现类且使用@EnableResourceServer注解进行标注

ResourceServerConfigurer接口有一个实现类ResourceServerConfigurerAdapter,这里我们继承这个类


/**
 * Created by liuquan on 2019/8/13.
 */
@Configuration
@EnableResourceServer
public class CustomResourceServerConfigurer extends ResourceServerConfigurerAdapter {
   

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
   
    
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
   
    
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

@EnableResourceServer注解会导入一个配置类ResourceServerConfiguration

protected void configure(HttpSecurity http) throws Exception {
   
	ResourceServerSecurityConfigurer resources = new ResourceServerSecurityConfigurer();
	ResourceServerTokenServices services = resolveTokenServices();
	if (services != null) {
   
		resources.tokenServices(services);
	}
	else {
   
		if (tokenStore != null) {
   
			resources.tokenStore(tokenStore);
		}
		else if (endpoints != null) {
   
			resources.tokenStore(endpoints.getEndpointsConfigurer().getTokenStore()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/768516
推荐阅读
相关标签
  

闽ICP备14008679号