This commit is contained in:
wol
2025-08-20 23:39:52 +08:00
parent 74d030a97e
commit f22189bc00
27 changed files with 86 additions and 54 deletions

View File

@@ -3,10 +3,14 @@ package com.agileboot.common.satoken.config;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.same.SaSameUtil;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.agileboot.common.core.constant.HttpStatus;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -28,10 +32,25 @@ public class SaTokenMvcConfiguration implements WebMvcConfigurer {
registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
}
/**
* 注册 [Sa-Token全局过滤器]
*/
@Bean
@ConditionalOnMissingClass("cn.dev33.satoken.reactor.spring.SaTokenContextRegister")
public SaServletFilter getGlobleSaServletFilter() {
return new SaServletFilter()
.addInclude("/**").addExclude("/favicon.ico")
.setAuth(obj -> {
SaRouter.match("/**", "/auth/login", StpUtil::checkLogin);
})
.setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED));
}
/**
* 校验是否从网关转发
*/
// @Bean
@Bean
@ConditionalOnMissingBean(SaServletFilter.class)
public SaServletFilter getSaServletFilter() {
return new SaServletFilter()
.addInclude("/**")

View File

@@ -10,6 +10,6 @@ sa-token:
# 关闭 cookie 鉴权 从根源杜绝 csrf 漏洞风险
is-read-cookie: false
# 开启内网服务调用鉴权(不允许越过gateway访问内网服务 保障服务安全)
# check-same-token: true
check-same-token: false
# token前缀
token-prefix: "Bearer"

View File

@@ -77,7 +77,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BizException.class)
public R<Void> handleBaseException(BizException e, HttpServletRequest request) {
log.error(e.getMessage());
return R.fail(e.getMessage());
Integer code = e.getCode();
return ObjectUtil.isNotNull(code) ? R.fail(code, e.getMessage()) : R.fail(e.getMessage());
}
/**

View File

@@ -1,6 +1,6 @@
package com.agileboot.auth.mapper;
package com.agileboot.system.client.mapper;
import com.agileboot.auth.pojo.entity.SysClient;
import com.agileboot.system.client.pojo.entity.SysClient;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface SysClientMapper extends BaseMapper<SysClient> {

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.agileboot.auth.pojo.entity.SysClient">
<mapper namespace="com.agileboot.system.client.pojo.entity.SysClient">
</mapper>

View File

@@ -1,4 +1,4 @@
package com.agileboot.auth.pojo.entity;
package com.agileboot.system.client.pojo.entity;
import com.agileboot.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;

View File

@@ -1,4 +1,4 @@
package com.agileboot.auth.pojo.vo;
package com.agileboot.system.client.pojo.vo;
import lombok.Data;

View File

@@ -0,0 +1,7 @@
package com.agileboot.system.client.service;
import com.agileboot.system.client.pojo.vo.SysClientVO;
public interface ISysClientService {
SysClientVO queryByClientId(String clientId);
}

View File

@@ -1,10 +1,10 @@
package com.agileboot.auth.service.impl;
package com.agileboot.system.client.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.agileboot.auth.mapper.SysClientMapper;
import com.agileboot.auth.pojo.entity.SysClient;
import com.agileboot.auth.pojo.vo.SysClientVO;
import com.agileboot.auth.service.ISysClientService;
import com.agileboot.system.client.mapper.SysClientMapper;
import com.agileboot.system.client.pojo.entity.SysClient;
import com.agileboot.system.client.pojo.vo.SysClientVO;
import com.agileboot.system.client.service.ISysClientService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

View File

@@ -1,6 +1,6 @@
package com.agileboot.auth.mapper;
package com.agileboot.system.user.mapper;
import com.agileboot.auth.pojo.entity.SysUser;
import com.agileboot.system.user.pojo.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface SysUserMapper extends BaseMapper<SysUser> {

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.agileboot.auth.pojo.entity.SysUser">
<mapper namespace="com.agileboot.system.user.pojo.entity.SysUser">
</mapper>

View File

@@ -1,4 +1,4 @@
package com.agileboot.auth.pojo.entity;
package com.agileboot.system.user.pojo.entity;
import com.agileboot.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;

View File

@@ -1,7 +1,7 @@
package com.agileboot.auth.service;
package com.agileboot.system.user.service;
import com.agileboot.auth.pojo.entity.SysUser;
import com.agileboot.common.satoken.pojo.LoginUser;
import com.agileboot.system.user.pojo.entity.SysUser;
public interface ISysUserService {
LoginUser getUserInfo(String username);

View File

@@ -1,9 +1,9 @@
package com.agileboot.auth.service.impl;
package com.agileboot.system.user.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.agileboot.auth.mapper.SysUserMapper;
import com.agileboot.auth.pojo.entity.SysUser;
import com.agileboot.auth.service.ISysUserService;
import com.agileboot.system.user.mapper.SysUserMapper;
import com.agileboot.system.user.pojo.entity.SysUser;
import com.agileboot.system.user.service.ISysUserService;
import com.agileboot.common.core.constant.Constants;
import com.agileboot.common.core.exception.BizException;
import com.agileboot.common.satoken.pojo.LoginUser;

View File

@@ -16,4 +16,14 @@
<module>wol-api</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-system-base</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@@ -0,0 +1,7 @@
package com.agileboot.api.user.pojo;
import org.springframework.stereotype.Service;
@Service
public interface RemoteSysUserService {
}

View File

@@ -12,14 +12,6 @@
<artifactId>wol-auth</artifactId>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-satoken</artifactId>
@@ -30,7 +22,7 @@
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-api</artifactId>
<artifactId>agileboot-system-base</artifactId>
</dependency>
</dependencies>

View File

@@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Author cuiJiaWang
* @Create 2025-08-12 18:07
*/
@SpringBootApplication
@SpringBootApplication(scanBasePackages = "com.agileboot.*")
public class WolAuthApplication {
public static void main(String[] args) {

View File

@@ -5,9 +5,9 @@ import cn.hutool.core.util.ObjectUtil;
import com.agileboot.auth.pojo.dto.LoginBody;
import com.agileboot.auth.pojo.dto.RegisterBody;
import com.agileboot.auth.pojo.vo.LoginVO;
import com.agileboot.auth.pojo.vo.SysClientVO;
import com.agileboot.system.client.pojo.vo.SysClientVO;
import com.agileboot.auth.service.IAuthStrategy;
import com.agileboot.auth.service.ISysClientService;
import com.agileboot.system.client.service.ISysClientService;
import com.agileboot.auth.service.SysLoginService;
import com.agileboot.common.core.constant.Constants;
import com.agileboot.common.core.core.R;
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("")
@RequestMapping("/auth")
public class AuthController {
private final SysLoginService loginService;

View File

@@ -33,7 +33,7 @@ import java.time.Duration;
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RestController("/captcha")
public class CaptchaController {
private final CaptchaProperties captchaProperties;
@@ -50,7 +50,8 @@ public class CaptchaController {
captchaVo.setCaptchaEnabled(false);
return R.ok(captchaVo);
}
return R.ok(this.getCodeImpl());
CaptchaController proxy = (CaptchaController) AopContext.currentProxy();
return R.ok(proxy.getCodeImpl());
}
/**

View File

@@ -3,7 +3,7 @@ package com.agileboot.auth.service;
import cn.hutool.extra.spring.SpringUtil;
import com.agileboot.auth.pojo.vo.LoginVO;
import com.agileboot.auth.pojo.vo.SysClientVO;
import com.agileboot.system.client.pojo.vo.SysClientVO;
import com.agileboot.common.core.exception.ServiceException;
/**

View File

@@ -1,7 +0,0 @@
package com.agileboot.auth.service;
import com.agileboot.auth.pojo.vo.SysClientVO;
public interface ISysClientService {
SysClientVO queryByClientId(String clientId);
}

View File

@@ -5,7 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.BCrypt;
import com.agileboot.auth.pojo.dto.RegisterBody;
import com.agileboot.auth.pojo.entity.SysUser;
import com.agileboot.system.user.pojo.entity.SysUser;
import com.agileboot.auth.properties.CaptchaProperties;
import com.agileboot.auth.properties.UserPasswordProperties;
import com.agileboot.common.core.constant.Constants;
@@ -15,11 +15,11 @@ import com.agileboot.common.core.exception.BizException;
import com.agileboot.common.redis.utils.RedisUtils;
import com.agileboot.common.satoken.pojo.LoginUser;
import com.agileboot.common.satoken.utils.LoginHelper;
import com.agileboot.system.user.service.ISysUserService;
import com.alibaba.fastjson2.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Duration;

View File

@@ -5,15 +5,15 @@ import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.hutool.crypto.digest.BCrypt;
import com.agileboot.auth.pojo.form.PasswordLoginBody;
import com.agileboot.auth.pojo.vo.LoginVO;
import com.agileboot.auth.pojo.vo.SysClientVO;
import com.agileboot.auth.properties.CaptchaProperties;
import com.agileboot.auth.service.IAuthStrategy;
import com.agileboot.auth.service.ISysUserService;
import com.agileboot.auth.service.SysLoginService;
import com.agileboot.common.core.enums.LoginType;
import com.agileboot.common.core.utils.ValidatorUtils;
import com.agileboot.common.satoken.pojo.LoginUser;
import com.agileboot.common.satoken.utils.LoginHelper;
import com.agileboot.system.client.pojo.vo.SysClientVO;
import com.agileboot.system.user.service.ISysUserService;
import com.alibaba.fastjson2.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@@ -120,10 +120,12 @@ sa-token:
# token名称 (同时也是cookie名称)
token-name: Authorization
# 开启内网服务调用鉴权(不允许越过gateway访问内网服务 保障服务安全)
check-same-token: true
check-same-token: false
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share: false
is-share: true
# 是否输出操作日志
is-log: true
# jwt秘钥
jwt-secret-key: abcdefghijklmnopqrstuvwxyz

View File

@@ -1,9 +1,9 @@
server:
port: 9210
servlet:
context-path: /auth
context-path: /
spring:
application:
name: wol-auth
name: agileboot-system
profiles:
active: dev