JWT 存储 token 通过 Nacos OpenFeign 实现远程调用
This commit is contained in:
		@@ -27,6 +27,16 @@
 | 
			
		||||
            <groupId>org.springframework.cloud</groupId>
 | 
			
		||||
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-security</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.cloud</groupId>
 | 
			
		||||
            <artifactId>spring-cloud-starter-oauth2</artifactId>
 | 
			
		||||
            <version>2.2.5.RELEASE</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-web</artifactId>
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package com.test.config;
 | 
			
		||||
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 | 
			
		||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: cong
 | 
			
		||||
 * Package: com.test.config
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/21 20:10
 | 
			
		||||
 */
 | 
			
		||||
@Configuration
 | 
			
		||||
public class ResourceConfiguration extends ResourceServerConfigurerAdapter { //继承此类进行高度自定义
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void configure(HttpSecurity http) throws Exception {  //这里也有HttpSecurity对象,方便我们配置SpringSecurity
 | 
			
		||||
        http
 | 
			
		||||
                .authorizeRequests()
 | 
			
		||||
                .anyRequest().access("#oauth2.hasScope('user')");  //添加自定义规则
 | 
			
		||||
        //Token必须要有我们自定义scope授权才可以访问此资源
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user