目录
一、springsecurity权限管理
1、前言
a、整体框架spring-cloud-alibaba-nacos + spring-security + jwt + redis
2、认证服务器
a、pom.xml
<!-- Spring Security、OAuth2 和JWT等 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- nacos 客户端 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos 配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
b、bootstrap.yml和application.yml
spring:
application:
name: auth-server # 当前服务的应用名,与nacos中的dataid的前缀匹配
cloud:
nacos:
discovery:
server-addr: 172.21.25.56:8848 # 注册中心地址 nacos server
config:
server-addr: 172.21.25.56:8848 # 配置中心地址 nacos server
file-extension: yml # 配置中心的配置后缀
profiles:
active: dev # 指定环境为开发环境,即读取 auth-server-dev.yml
server:
port: 7001
servlet:
context-path: /auth # 上下文件路径,请求前缀 ip:port/article
spring:
redis:
host: 172.21.25.56
port: 6379
password: # redis不需要用户名
# 数据源配置
datasource:
username: root
password: 123456
url: jdbc:mysql://172.21.25.56:3306/dcy_blog_auth?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true
#mysql8版本以上驱动包指定新的驱动类
driver-class-name: com.mysql.cj.jdbc.Driver
# 数据源其他配置, 在 DruidConfig配置类中手动绑定
initialSize: 8
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
c、启动类
@EnableFeignClients // 扫描Feign接口
@EnableDiscoveryClient // 标识nacos客户端
@SpringBootApplication
public class AuthApplication {
public static void main(String[] args) {
SpringApplication.run(AuthApplication.class, args);
}
}
3、资源服务器