解决冲突11
This commit is contained in:
commit
765b8b5e91
@ -0,0 +1,41 @@
|
||||
package cn.gzkx.apidemo.config;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.filter.SaServletFilter;
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
||||
// registry.addInterceptor(new SaInterceptor().setAuth(obj->{
|
||||
// StpUtil.checkLogin();
|
||||
// })).addPathPatterns("/**");
|
||||
registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
|
||||
}
|
||||
// 注册 Sa-Token 全局过滤器
|
||||
//@Bean
|
||||
//public SaServletFilter getSaServletFilter() {
|
||||
// return new SaServletFilter()
|
||||
// .addInclude("/**")
|
||||
// .addExclude("/favicon.ico")
|
||||
// .setAuth(obj -> {
|
||||
// // 校验 Same-Token 身份凭证 —— 以下两句代码可简化为:SaSameUtil.checkCurrentRequestToken();
|
||||
// String token = SaHolder.getRequest().getHeader("satoken");
|
||||
// SaSameUtil.checkToken(token);
|
||||
// })
|
||||
// .setError(e -> {
|
||||
// return SaResult.error(e.getMessage());
|
||||
// })
|
||||
// ;
|
||||
//}
|
||||
}
|
@ -2,10 +2,15 @@ package cn.gzkx.apidemo.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author: zqm
|
||||
* @desc:
|
||||
@ -18,7 +23,10 @@ public class ApiController {
|
||||
// 仅管理员角色可以访问
|
||||
@GetMapping("/admin")
|
||||
@SaCheckRole("admin")
|
||||
public String adminEndpoint() {
|
||||
public String adminEndpoint(HttpServletRequest request) {
|
||||
boolean flag= StpUtil.isLogin();
|
||||
Object role= StpUtil.getSession().get("role");
|
||||
Object loginId= StpUtil.getLoginId();
|
||||
return "欢迎管理员访问此接口";
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,16 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: api-demo
|
||||
# redis配置
|
||||
data:
|
||||
redis:
|
||||
# Redis数据库索引(默认为0)
|
||||
database: 1
|
||||
# Redis服务器地址
|
||||
host: 127.0.0.1
|
||||
# Redis服务器连接端口
|
||||
host: 192.168.56.12
|
||||
port: 6379
|
||||
# Redis服务器连接密码(默认为空)
|
||||
# password:
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
# redis 密码必须配置
|
||||
password: Asd123$
|
||||
database: 0
|
||||
# 需要使用数字
|
||||
timeout: 10000
|
||||
ssl.enabled: false
|
||||
lettuce:
|
||||
pool:
|
||||
# 连接池最大连接数
|
||||
@ -25,3 +23,20 @@ spring:
|
||||
max-idle: 10
|
||||
# 连接池中的最小空闲连接
|
||||
min-idle: 0
|
||||
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: satoken
|
||||
# token 有效期(单位:秒) 默认30天,-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
active-timeout: -1
|
||||
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||
is-share: true
|
||||
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
token-style: uuid
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
is-read-cookie: false
|
@ -34,12 +34,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@ -57,11 +51,23 @@
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>1.39.0</version>
|
||||
</dependency>
|
||||
<!-- Sa-Token 插件:整合SSO -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<version>1.39.0</version>
|
||||
</dependency>
|
||||
<!-- 提供Redis连接池 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -3,18 +3,16 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: satoken-auth
|
||||
# redis配置
|
||||
data:
|
||||
redis:
|
||||
# Redis数据库索引(默认为0)
|
||||
database: 1
|
||||
# Redis服务器地址
|
||||
host: 127.0.0.1
|
||||
# Redis服务器连接端口
|
||||
host: 192.168.56.12
|
||||
port: 6379
|
||||
# Redis服务器连接密码(默认为空)
|
||||
# password:
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
# redis 密码必须配置
|
||||
password: Asd123$
|
||||
database: 0
|
||||
# 需要使用数字
|
||||
timeout: 10000
|
||||
ssl.enabled: false
|
||||
lettuce:
|
||||
pool:
|
||||
# 连接池最大连接数
|
||||
@ -42,3 +40,4 @@ sa-token:
|
||||
token-style: uuid
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
is-read-cookie: false
|
||||
|
@ -27,6 +27,5 @@
|
||||
<artifactId>udf-common-web</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@ -1,28 +1,28 @@
|
||||
//package cn.udf.demo.controller;
|
||||
//
|
||||
//import cn.udf.common.core.result.ApiResult;
|
||||
//import cn.udf.common.web.core.BaseController;
|
||||
//import cn.udf.demo.domain.SysUser;
|
||||
//import cn.udf.demo.service.SysUserService;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestBody;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
///**
|
||||
// * @author: zqm
|
||||
// * @desc:
|
||||
// * @date: 2024/12/28 下午5:14
|
||||
// */
|
||||
//@RequiredArgsConstructor
|
||||
//@RestController
|
||||
//@RequestMapping("/sysUser")
|
||||
//public class SysUserController extends BaseController {
|
||||
// private final SysUserService sysUserService;
|
||||
//
|
||||
// @PostMapping("/add")
|
||||
// public ApiResult addSysUser(@RequestBody SysUser sysUser) {
|
||||
// return ApiResult.success(sysUserService.addUser(sysUser));
|
||||
// }
|
||||
//}
|
||||
package cn.udf.demo.controller;
|
||||
|
||||
import cn.udf.common.core.result.ApiResult;
|
||||
import cn.udf.common.web.core.BaseController;
|
||||
import cn.udf.demo.domain.SysUser;
|
||||
import cn.udf.demo.service.SysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author: zqm
|
||||
* @desc:
|
||||
* @date: 2024/12/28 下午5:14
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/sysUser")
|
||||
public class SysUserController extends BaseController {
|
||||
private final SysUserService sysUserService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public ApiResult addSysUser(@RequestBody SysUser sysUser) {
|
||||
return ApiResult.success(sysUserService.addUser(sysUser));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package cn.udf.demo.service;
|
||||
|
||||
import cn.udf.demo.domain.SysUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface IUserSreivce extends IService<SysUser> {
|
||||
}
|
@ -1,24 +1,24 @@
|
||||
//package cn.udf.demo.service;
|
||||
//
|
||||
//import cn.udf.demo.domain.SysUser;
|
||||
//import cn.udf.demo.mapper.SysUserMapper;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author: zqm
|
||||
// * @desc:
|
||||
// * @date: 2024/12/28 下午5:02
|
||||
// */
|
||||
//@Slf4j
|
||||
//@RequiredArgsConstructor
|
||||
//@Service
|
||||
//public class SysUserService {
|
||||
// private final SysUserMapper sysUserMapper;
|
||||
//
|
||||
// public int addUser(SysUser sysUser) {
|
||||
// return sysUserMapper.insert(sysUser);
|
||||
// }
|
||||
//}
|
||||
package cn.udf.demo.service;
|
||||
|
||||
import cn.udf.demo.domain.SysUser;
|
||||
import cn.udf.demo.mapper.SysUserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author: zqm
|
||||
* @desc:
|
||||
* @date: 2024/12/28 下午5:02
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysUserService {
|
||||
private final SysUserMapper sysUserMapper;
|
||||
|
||||
public int addUser(SysUser sysUser) {
|
||||
return sysUserMapper.insert(sysUser);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user