Commit 52ba6026 by xlx

账号登录

接口认证
parent 2f8a5b1d
Showing with 636 additions and 1438 deletions
......@@ -3,6 +3,7 @@ package com.matchtech.system.api;
import com.matchtech.common.core.constants.SecurityConstants;
import com.matchtech.common.core.constants.ServiceNameConstants;
import com.matchtech.common.core.domain.R;
import com.matchtech.common.core.page.resp.ApiResponseEntity;
import com.matchtech.system.api.domain.SysUser;
import com.matchtech.system.api.factory.RemoteUserFallbackFactory;
import com.matchtech.system.api.model.LoginUser;
......@@ -28,27 +29,6 @@ public interface RemoteUserService {
* @param source 请求来源
* @return 结果
*/
@GetMapping("/user/info/{username}")
public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 注册用户信息
*
* @param sysUser 用户信息
* @param source 请求来源
* @return 结果
*/
@PostMapping("/user/register")
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 记录用户登录IP地址和登录时间
*
* @param sysUser 用户信息
* @param source 请求来源
* @return 结果
*/
@PutMapping("/user/recordlogin")
public R<Boolean> recordUserLogin(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@GetMapping("/a/sys/user/info/{userId}")
public ApiResponseEntity<LoginUser> getUserInfo(@PathVariable("userId") String userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
package com.matchtech.system.api.domain;
import java.util.Date;
import java.util.List;
import com.matchtech.common.core.domain.BaseEntity;
import jakarta.validation.constraints.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.matchtech.common.core.annotation.Excel;
import com.matchtech.common.core.annotation.Excel.ColumnType;
import com.matchtech.common.core.annotation.Excel.Type;
import com.matchtech.common.core.constants.UserConstants;
import com.matchtech.common.core.annotation.Excels;
import com.matchtech.common.core.xss.Xss;
import com.matchtech.common.core.constants.UserConstants;
import com.matchtech.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 用户对象 sys_user
*
* @author matchtech
*/
@Data
public class SysUser extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 用户ID */
@Excel(name = "用户序号", type = Type.EXPORT, cellType = ColumnType.NUMERIC, prompt = "用户编号")
private Long userId;
private String userId;
/** 部门ID */
@Excel(name = "部门编号", type = Type.IMPORT)
private Long deptId;
private String deptId;
/** 用户账号 */
@Excel(name = "登录名称")
......@@ -94,222 +90,15 @@ public class SysUser extends BaseEntity
/** 角色ID */
private Long roleId;
public SysUser()
{
}
public SysUser(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public boolean isAdmin()
{
return isAdmin(this.userId);
}
public static boolean isAdmin(Long userId)
public static boolean isAdmin(String userId)
{
return UserConstants.isAdmin(userId);
}
public Long getDeptId()
{
return deptId;
}
public void setDeptId(Long deptId)
{
this.deptId = deptId;
}
@Xss(message = "用户昵称不能包含脚本字符")
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
public String getNickName()
{
return nickName;
}
public void setNickName(String nickName)
{
this.nickName = nickName;
}
@Xss(message = "用户账号不能包含脚本字符")
@NotBlank(message = "用户账号不能为空")
@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
@Email(message = "邮箱格式不正确")
@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
@Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
public String getPhonenumber()
{
return phonenumber;
}
public void setPhonenumber(String phonenumber)
{
this.phonenumber = phonenumber;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getAvatar()
{
return avatar;
}
public void setAvatar(String avatar)
{
this.avatar = avatar;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public String getDelFlag()
{
return delFlag;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getLoginIp()
{
return loginIp;
}
public void setLoginIp(String loginIp)
{
this.loginIp = loginIp;
}
public Date getLoginDate()
{
return loginDate;
}
public void setLoginDate(Date loginDate)
{
this.loginDate = loginDate;
}
public Date getPwdUpdateDate()
{
return pwdUpdateDate;
}
public void setPwdUpdateDate(Date pwdUpdateDate)
{
this.pwdUpdateDate = pwdUpdateDate;
}
public SysDept getDept()
{
return dept;
}
public void setDept(SysDept dept)
{
this.dept = dept;
}
public List<SysRole> getRoles()
{
return roles;
}
public void setRoles(List<SysRole> roles)
{
this.roles = roles;
}
public Long[] getRoleIds()
{
return roleIds;
}
public void setRoleIds(Long[] roleIds)
{
this.roleIds = roleIds;
}
public Long[] getPostIds()
{
return postIds;
}
public void setPostIds(Long[] postIds)
{
this.postIds = postIds;
}
public Long getRoleId()
{
return roleId;
}
public void setRoleId(Long roleId)
{
this.roleId = roleId;
}
}
package com.matchtech.system.api.factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.matchtech.common.core.domain.R;
import com.matchtech.common.core.page.resp.ApiResponseEntity;
import com.matchtech.system.api.RemoteUserService;
import com.matchtech.system.api.domain.SysUser;
import com.matchtech.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 用户服务降级处理
......@@ -15,32 +16,16 @@ import com.matchtech.system.api.model.LoginUser;
* @author matchtech
*/
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);
@Override
public RemoteUserService create(Throwable throwable)
{
public RemoteUserService create(Throwable throwable) {
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteUserService()
{
@Override
public R<LoginUser> getUserInfo(String username, String source)
{
return R.fail("获取用户失败:" + throwable.getMessage());
}
@Override
public R<Boolean> registerUserInfo(SysUser sysUser, String source)
{
return R.fail("注册用户失败:" + throwable.getMessage());
}
return new RemoteUserService() {
@Override
public R<Boolean> recordUserLogin(SysUser sysUser, String source)
{
return R.fail("记录用户登录信息失败:" + throwable.getMessage());
public ApiResponseEntity<LoginUser> getUserInfo(String username, String source) {
return ApiResponseEntity.fail(500, "获取用户失败", throwable.getMessage());
}
};
}
......
......@@ -3,12 +3,14 @@ package com.matchtech.system.api.model;
import java.io.Serializable;
import java.util.Set;
import com.matchtech.system.api.domain.SysUser;
import lombok.Data;
/**
* 用户信息
*
* @author matchtech
*/
@Data
public class LoginUser implements Serializable
{
private static final long serialVersionUID = 1L;
......@@ -21,7 +23,7 @@ public class LoginUser implements Serializable
/**
* 用户名id
*/
private Long userid;
private String userid;
/**
* 用户名
......@@ -58,93 +60,4 @@ public class LoginUser implements Serializable
*/
private SysUser sysUser;
public String getToken()
{
return token;
}
public void setToken(String token)
{
this.token = token;
}
public Long getUserid()
{
return userid;
}
public void setUserid(Long userid)
{
this.userid = userid;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public Long getLoginTime()
{
return loginTime;
}
public void setLoginTime(Long loginTime)
{
this.loginTime = loginTime;
}
public Long getExpireTime()
{
return expireTime;
}
public void setExpireTime(Long expireTime)
{
this.expireTime = expireTime;
}
public String getIpaddr()
{
return ipaddr;
}
public void setIpaddr(String ipaddr)
{
this.ipaddr = ipaddr;
}
public Set<String> getPermissions()
{
return permissions;
}
public void setPermissions(Set<String> permissions)
{
this.permissions = permissions;
}
public Set<String> getRoles()
{
return roles;
}
public void setRoles(Set<String> roles)
{
this.roles = roles;
}
public SysUser getSysUser()
{
return sysUser;
}
public void setSysUser(SysUser sysUser)
{
this.sysUser = sysUser;
}
}
......@@ -59,6 +59,12 @@
<artifactId>matchtech-common-dto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.matchtech</groupId>
<artifactId>matchtech-common-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
......
package com.matchtech.system.controller;
package com.matchtech.matchtechauthlocal.controller;
import com.matchtech.common.core.constants.SecurityConstants;
import com.matchtech.common.core.page.resp.ApiResponseEntity;
import com.matchtech.common.core.page.resp.ApiResponseUtils;
import com.matchtech.common.core.web.controller.BaseController;
import com.matchtech.common.dto.login.SysLoginDto;
import com.matchtech.common.dto.login.SysLoginVo;
import com.matchtech.common.dto.login.TokenDto;
import com.matchtech.common.redis.constant.RedisConstants;
import com.matchtech.common.redis.service.RedisUtils;
import com.matchtech.system.domain.dto.SysLoginDto;
import com.matchtech.system.service.SysUserService;
import com.matchtech.common.security.service.TokenService;
import com.matchtech.system.api.RemoteUserService;
import com.matchtech.system.api.model.LoginUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
......@@ -18,24 +22,28 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@Tag(name = "系统登录")
@RestController
@RequestMapping(value = "${matchtech.adminPath}/sys/")
public class SysLoginController extends BaseController {
@RequestMapping(value = "a/sys/")
public class LocalLoginController extends BaseController {
@Autowired
private SysUserService sysUserService;
private RemoteUserService remoteUserService;
@Autowired
private TokenService tokenService;
@Operation(summary = "用户登录")
@PostMapping("/login")
public ApiResponseEntity<SysLoginVo> login(@Validated @RequestBody SysLoginDto loginDto) {
SysLoginVo sysLoginVo = sysUserService.login(loginDto);
// String token = sysLoginVo.getToken();
// CompletableFuture.runAsync(() -> {
// GeneralUtils.setUserPermissionCache(token);
// });
return ApiResponseUtils.success(sysLoginVo);
public ApiResponseEntity login(@Validated @RequestBody SysLoginDto loginDto) {
ApiResponseEntity<LoginUser> userInfo = remoteUserService.getUserInfo(loginDto.getUsername(), SecurityConstants.INNER);
if(userInfo.getCode() != 200){
return userInfo;
}
LoginUser data = userInfo.getData();
TokenDto token = tokenService.createToken(data);
return ApiResponseUtils.success(token);
}
@Operation(summary = "退出登录")
......@@ -45,17 +53,4 @@ public class SysLoginController extends BaseController {
RedisUtils.delete(RedisConstants.SYS_USER_TOKEN_PREFIX + token);
return ApiResponseUtils.success();
}
// @Operation(summary = "获取登录用户权限菜单")
// @PostMapping("/getLoginUserMenu")
// public ApiResponseEntity<List<SysMenuVo>> getLoginUserMenu(HttpServletRequest request) {
// SysUserEntity sysUser = RedisUtils.get(RedisConstants.SYS_USER_TOKEN_PREFIX + request.getHeader("token"));
// if (Constants.SUPER_ADMIN_ID.equals(sysUser.getId())) {
// return ApiResponseUtils.success(sysMenuService.tree(new SysMenuQueryDto()));
// }
// // TODO: 非超级管理员获取有权限菜单
// return ApiResponseUtils.success(sysRoleMenuService.getMenuByUserId(sysUser.getId()));
// }
}
#matchtech-auth-local
# Tomcat
server:
port: 28080
# Spring
spring:
application:
# 应用名称
name: matchtech-auth-local
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
config:
# 配置中心地址
server-addr: 127.0.0.1:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 扩展配置
extension-configs:
- data-id: ${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
refresh: true
......@@ -16,8 +16,8 @@ public class MatchtechProperties {
private static final AntPathMatcher matcher = new AntPathMatcher();
private Map<String, List<String>> white;
private String tokenTimeout;
private String adminPath;
private String frontPath;
private String adminPath = "a";
private String frontPath = "f";
private String validateFlag;
private String signFlag;
private String frontUrl;
......
......@@ -20,7 +20,8 @@ public class SecurityConstants
/**
* 授权信息字段
*/
public static final String AUTHORIZATION_HEADER = "Authorization";
//public static final String AUTHORIZATION_HEADER = "Authorization";
public static final String AUTHORIZATION_HEADER = "token";
/**
* 请求来源
......
......@@ -15,10 +15,10 @@ public class ServiceNameConstants
/**
* 系统模块的serviceid
*/
public static final String SYSTEM_SERVICE = "matchtech-modules-system";
public static final String SYSTEM_SERVICE = "matchtech-system";
/**
* 文件服务的serviceid
*/
public static final String FILE_SERVICE = "matchtech-modules-file";
public static final String FILE_SERVICE = "matchtech-file";
}
package com.matchtech.common.core.constants;
import cn.hutool.core.util.StrUtil;
/**
* 用户常量信息
*
......@@ -81,8 +83,8 @@ public class UserConstants
public static final int PASSWORD_MAX_LENGTH = 20;
public static boolean isAdmin(Long userId)
public static boolean isAdmin(String userId)
{
return userId != null && 1L == userId;
return StrUtil.equals(userId,"1");
}
}
......@@ -51,9 +51,9 @@ public class SecurityContextHolder
THREAD_LOCAL.set(threadLocalMap);
}
public static Long getUserId()
public static String getUserId()
{
return Convert.toLong(get(SecurityConstants.DETAILS_USER_ID), 0L);
return Convert.toStr(get(SecurityConstants.DETAILS_USER_ID), "0");
}
public static void setUserId(String account)
......
package com.matchtech.common.core.servlet;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper {
private Logger logger = LoggerFactory.getLogger(getClass());
/** 复制请求body */
private byte[] body;
public MyHttpServletRequestWrapper(HttpServletRequest request) {
super(request);
try {
// 设置编码格式, 防止中文乱码
//request.setCharacterEncoding("UTF-8");
// 将请求中的流取出来放到body里,后面都只操作body就行
this.body = RequestReadUtils.readByte(request);
} catch (Exception e) {
logger.error("MyHttpServletRequestWrapper 拦截器异常", e);
}
}
@Override
public ServletInputStream getInputStream() {
// 返回body的流信息即可
try (final ByteArrayInputStream bais = new ByteArrayInputStream(body)) {
return getServletInputStream(bais);
} catch (IOException e) {
logger.error("MyHttpServletRequestWrapper.getInputStream() exception", e);
throw new RuntimeException("MyHttpServletRequestWrapper 获取input流异常");
}
}
@Override
public BufferedReader getReader() {
return new BufferedReader(new InputStreamReader(this.getInputStream()));
}
/**
* 重写getInputStream流
*
* @param bais
* @return
*/
private static ServletInputStream getServletInputStream(ByteArrayInputStream bais) {
return new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() {
return bais.read();
}
};
}
public byte[] getBody() {
return body;
}
}
\ No newline at end of file
package com.matchtech.common.core.servlet;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.WriteListener;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
public class MyHttpServletResponseWrapper extends HttpServletResponseWrapper {
private ByteArrayOutputStream buffer = null;
private ServletOutputStream out = null;
private PrintWriter writer = null;
public MyHttpServletResponseWrapper(HttpServletResponse resp) throws IOException {
super(resp);
// 真正存储数据的流
buffer = new ByteArrayOutputStream();
out = new WapperedOutputStream(buffer);
writer = new PrintWriter(new OutputStreamWriter(buffer, this.getCharacterEncoding()));
}
/**
* 重载父类获取outputstream的方法
*/
@Override
public ServletOutputStream getOutputStream() throws IOException {
return out;
}
/**
* 重载父类获取writer的方法
*/
@Override
public PrintWriter getWriter() throws UnsupportedEncodingException {
return writer;
}
/**
* 重载父类获取flushBuffer的方法
*/
@Override
public void flushBuffer() throws IOException {
if (out != null) {
out.flush();
}
if (writer != null) {
writer.flush();
}
}
@Override
public void reset() {
buffer.reset();
}
/**
* 将out、writer中的数据强制输出到WapperedResponse的buffer里面,否则取不到数据
*/
public byte[] getResponseData() throws IOException {
flushBuffer();
return buffer.toByteArray();
}
/**
* 内部类,对ServletOutputStream进行包装
*/
private class WapperedOutputStream extends ServletOutputStream {
private ByteArrayOutputStream bos = null;
public WapperedOutputStream(ByteArrayOutputStream stream) throws IOException {
bos = stream;
}
@Override
public void write(int b) throws IOException {
bos.write(b);
}
@Override
public void write(byte[] b) throws IOException {
bos.write(b, 0, b.length);
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setWriteListener(WriteListener writeListener) {
}
}
}
package com.matchtech.common.core.servlet;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class RequestReadUtils {
public static Logger logger = LoggerFactory.getLogger(RequestReadUtils.class);
/**
* 读取请求流
*
* @param request
* @return
* @throws IOException
* @throws UnsupportedEncodingException
*/
public static String read(HttpServletRequest request) throws IOException {
// StringBuilder sb = new StringBuilder();
// BufferedReader reader = request.getReader();
// String line;
// while ((line = reader.readLine()) != null) {
// sb.append(line);
// }
// return sb.toString();
if (request instanceof MyHttpServletRequestWrapper cachedRequest) {
// 使用Java 17的模式匹配
return new String(cachedRequest.getBody(), request.getCharacterEncoding());
} else {
// 对于普通请求,使用原来的方式
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = request.getReader()) {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
}
return sb.toString();
}
}
public static byte[] readByte(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
byte[] data = result.toByteArray();
return data;
}
}
package com.matchtech.common.core.async;
package com.matchtech.common.core.thread;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......
package com.matchtech.common.core.async;
package com.matchtech.common.core.thread;
public class MyThreadLocal {
private static ThreadLocal<String> tokenThreadLocal = new ThreadLocal<String>();
private static ThreadLocal<String> tenantIdThreadLocal = new ThreadLocal<String>();
private static ThreadLocal<CurrentUserDTO> userThreadLocal = new ThreadLocal<CurrentUserDTO>();
public static CurrentUserDTO getUserThreadLocal() {
return userThreadLocal.get();
}
public static void setUserThreadLocal(CurrentUserDTO currentUserDTO) {
userThreadLocal.set(currentUserDTO);
}
/**
* 设置登录token
*
......
HELP.md
target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Apache Maven Wrapper startup batch script, version 3.3.4
#
# Optional ENV vars
# -----------------
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
# MVNW_REPOURL - repo url base for downloading maven distribution
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
# ----------------------------------------------------------------------------
set -euf
[ "${MVNW_VERBOSE-}" != debug ] || set -x
# OS specific support.
native_path() { printf %s\\n "$1"; }
case "$(uname)" in
CYGWIN* | MINGW*)
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
native_path() { cygpath --path --windows "$1"; }
;;
esac
# set JAVACMD and JAVACCMD
set_java_home() {
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
if [ -n "${JAVA_HOME-}" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
JAVACCMD="$JAVA_HOME/jre/sh/javac"
else
JAVACMD="$JAVA_HOME/bin/java"
JAVACCMD="$JAVA_HOME/bin/javac"
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
return 1
fi
fi
else
JAVACMD="$(
'set' +e
'unset' -f command 2>/dev/null
'command' -v java
)" || :
JAVACCMD="$(
'set' +e
'unset' -f command 2>/dev/null
'command' -v javac
)" || :
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
return 1
fi
fi
}
# hash string like Java String::hashCode
hash_string() {
str="${1:-}" h=0
while [ -n "$str" ]; do
char="${str%"${str#?}"}"
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
str="${str#?}"
done
printf %x\\n $h
}
verbose() { :; }
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
die() {
printf %s\\n "$1" >&2
exit 1
}
trim() {
# MWRAPPER-139:
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
# Needed for removing poorly interpreted newline sequences when running in more
# exotic environments such as mingw bash on Windows.
printf "%s" "${1}" | tr -d '[:space:]'
}
scriptDir="$(dirname "$0")"
scriptName="$(basename "$0")"
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
while IFS="=" read -r key value; do
case "${key-}" in
distributionUrl) distributionUrl=$(trim "${value-}") ;;
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
esac
done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
case "${distributionUrl##*/}" in
maven-mvnd-*bin.*)
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
*)
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
distributionPlatform=linux-amd64
;;
esac
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
;;
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
esac
# apply MVNW_REPOURL and calculate MAVEN_HOME
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
distributionUrlName="${distributionUrl##*/}"
distributionUrlNameMain="${distributionUrlName%.*}"
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
exec_maven() {
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
}
if [ -d "$MAVEN_HOME" ]; then
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
exec_maven "$@"
fi
case "${distributionUrl-}" in
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
esac
# prepare tmp dir
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
trap clean HUP INT TERM EXIT
else
die "cannot create temp dir"
fi
mkdir -p -- "${MAVEN_HOME%/*}"
# Download and Install Apache Maven
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
verbose "Downloading from: $distributionUrl"
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
# select .zip or .tar.gz
if ! command -v unzip >/dev/null; then
distributionUrl="${distributionUrl%.zip}.tar.gz"
distributionUrlName="${distributionUrl##*/}"
fi
# verbose opt
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
# normalize http auth
case "${MVNW_PASSWORD:+has-password}" in
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
esac
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
verbose "Found wget ... using wget"
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
verbose "Found curl ... using curl"
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
elif set_java_home; then
verbose "Falling back to use Java to download"
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
cat >"$javaSource" <<-END
public class Downloader extends java.net.Authenticator
{
protected java.net.PasswordAuthentication getPasswordAuthentication()
{
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
}
public static void main( String[] args ) throws Exception
{
setDefault( new Downloader() );
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
}
}
END
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
verbose " - Compiling Downloader.java ..."
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
verbose " - Running Downloader.java ..."
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
fi
# If specified, validate the SHA-256 sum of the Maven distribution zip file
if [ -n "${distributionSha256Sum-}" ]; then
distributionSha256Result=false
if [ "$MVN_CMD" = mvnd.sh ]; then
echo "Checksum validation is not supported for maven-mvnd." >&2
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
exit 1
elif command -v sha256sum >/dev/null; then
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
distributionSha256Result=true
fi
elif command -v shasum >/dev/null; then
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
distributionSha256Result=true
fi
else
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
exit 1
fi
if [ $distributionSha256Result = false ]; then
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
exit 1
fi
fi
# unzip and move
if command -v unzip >/dev/null; then
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
else
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
fi
# Find the actual extracted directory name (handles snapshots where filename != directory name)
actualDistributionDir=""
# First try the expected directory name (for regular distributions)
if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
actualDistributionDir="$distributionUrlNameMain"
fi
fi
# If not found, search for any directory with the Maven executable (for snapshots)
if [ -z "$actualDistributionDir" ]; then
# enable globbing to iterate over items
set +f
for dir in "$TMP_DOWNLOAD_DIR"/*; do
if [ -d "$dir" ]; then
if [ -f "$dir/bin/$MVN_CMD" ]; then
actualDistributionDir="$(basename "$dir")"
break
fi
fi
done
set -f
fi
if [ -z "$actualDistributionDir" ]; then
verbose "Contents of $TMP_DOWNLOAD_DIR:"
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
die "Could not find Maven distribution directory in extracted archive"
fi
verbose "Found extracted Maven distribution directory: $actualDistributionDir"
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
clean || :
exec_maven "$@"
<# : batch portion
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Apache Maven Wrapper startup batch script, version 3.3.4
@REM
@REM Optional ENV vars
@REM MVNW_REPOURL - repo url base for downloading maven distribution
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
@REM ----------------------------------------------------------------------------
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
@SET __MVNW_CMD__=
@SET __MVNW_ERROR__=
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
@SET PSModulePath=
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
)
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
@SET __MVNW_PSMODULEP_SAVE=
@SET __MVNW_ARG0_NAME__=
@SET MVNW_USERNAME=
@SET MVNW_PASSWORD=
@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
@echo Cannot start maven from wrapper >&2 && exit /b 1
@GOTO :EOF
: end batch / begin powershell #>
$ErrorActionPreference = "Stop"
if ($env:MVNW_VERBOSE -eq "true") {
$VerbosePreference = "Continue"
}
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
if (!$distributionUrl) {
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
}
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
"maven-mvnd-*" {
$USE_MVND = $true
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
$MVN_CMD = "mvnd.cmd"
break
}
default {
$USE_MVND = $false
$MVN_CMD = $script -replace '^mvnw','mvn'
break
}
}
# apply MVNW_REPOURL and calculate MAVEN_HOME
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
if ($env:MVNW_REPOURL) {
$MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
}
$distributionUrlName = $distributionUrl -replace '^.*/',''
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
$MAVEN_M2_PATH = "$HOME/.m2"
if ($env:MAVEN_USER_HOME) {
$MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
}
if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
}
$MAVEN_WRAPPER_DISTS = $null
if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
$MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
} else {
$MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
}
$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
exit $?
}
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
}
# prepare tmp dir
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
trap {
if ($TMP_DOWNLOAD_DIR.Exists) {
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
}
}
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
# Download and Install Apache Maven
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
Write-Verbose "Downloading from: $distributionUrl"
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
$webclient = New-Object System.Net.WebClient
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
# If specified, validate the SHA-256 sum of the Maven distribution zip file
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
if ($distributionSha256Sum) {
if ($USE_MVND) {
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
}
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
}
}
# unzip and move
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
# Find the actual extracted directory name (handles snapshots where filename != directory name)
$actualDistributionDir = ""
# First try the expected directory name (for regular distributions)
$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
$actualDistributionDir = $distributionUrlNameMain
}
# If not found, search for any directory with the Maven executable (for snapshots)
if (!$actualDistributionDir) {
Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
$testPath = Join-Path $_.FullName "bin/$MVN_CMD"
if (Test-Path -Path $testPath -PathType Leaf) {
$actualDistributionDir = $_.Name
}
}
}
if (!$actualDistributionDir) {
Write-Error "Could not find Maven distribution directory in extracted archive"
}
Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
try {
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
} catch {
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
Write-Error "fail to move MAVEN_HOME"
}
} finally {
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
}
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
......@@ -19,12 +19,11 @@
<dependency>
<groupId>com.matchtech</groupId>
<artifactId>matchtech-common-swagger</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.matchtech</groupId>
<artifactId>matchtech-common-core</artifactId>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
......
package com.matchtech.common.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import io.swagger.v3.oas.annotations.media.Schema;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BaseIdDto {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED)
private String id;
}
package com.matchtech.system.domain.dto;
package com.matchtech.common.dto.login;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
......
......@@ -9,6 +9,7 @@ public class SysLoginVo {
@Schema(description = "token")
private String token;
@Schema(description = "用户详情")
private SysUserDetailVo sysUserDetailVo;
......
package com.matchtech.common.dto.login;
import lombok.Data;
@Data
public class TokenDto {
private String token;
private Long expire;
}
......@@ -34,6 +34,11 @@
<artifactId>matchtech-common-redis</artifactId>
</dependency>
<dependency>
<groupId>com.matchtech</groupId>
<artifactId>matchtech-common-dto</artifactId>
</dependency>
</dependencies>
</project>
......@@ -3,6 +3,8 @@ package com.matchtech.common.security.service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.matchtech.common.dto.login.TokenDto;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -45,12 +47,12 @@ public class TokenService
/**
* 创建令牌
*/
public Map<String, Object> createToken(LoginUser loginUser)
public TokenDto createToken(LoginUser loginUser)
{
String token = IdUtils.fastUUID();
Long userId = loginUser.getSysUser().getUserId();
String userName = loginUser.getSysUser().getUserName();
loginUser.setToken(token);
String userKey = IdUtils.fastUUID();
String userId = loginUser.getUserid();
String userName = loginUser.getUsername();
loginUser.setToken(userKey);
loginUser.setUserid(userId);
loginUser.setUsername(userName);
loginUser.setIpaddr(IpUtils.getIpAddr());
......@@ -58,15 +60,15 @@ public class TokenService
// Jwt存储信息
Map<String, Object> claimsMap = new HashMap<String, Object>();
claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.USER_KEY, userKey);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
// 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>();
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
rspMap.put("expires_in", TOKEN_EXPIRE_TIME);
return rspMap;
TokenDto tokenDto = new TokenDto();
tokenDto.setExpire(TOKEN_EXPIRE_TIME);
tokenDto.setToken(JwtUtils.createToken(claimsMap));
return tokenDto;
}
/**
......
......@@ -19,7 +19,7 @@ public class SecurityUtils
/**
* 获取用户ID
*/
public static Long getUserId()
public static String getUserId()
{
return SecurityContextHolder.getUserId();
}
......
......@@ -55,7 +55,7 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
{
try
{
Long userId = SecurityContextHolder.getUserId();
String userId = SecurityContextHolder.getUserId();
// 管理员不脱敏
return !UserConstants.isAdmin(userId);
}
......
......@@ -33,7 +33,11 @@
<dependency>
<groupId>io.springboot</groupId>
<artifactId>knife4j-openapi3-ui</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
......
......@@ -12,6 +12,11 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
......
......@@ -87,13 +87,6 @@
</dependency>
<!-- Springdoc -->
<!-- <dependency>-->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-starter-webflux-ui</artifactId>-->
<!-- <version>${springdoc.version}</version>-->
<!-- </dependency>-->
<!-- Springdoc -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-core</artifactId>
......
//package com.matchtech.gateway.filter;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import com.matchtech.common.core.constants.CacheConstants;
//import com.matchtech.common.core.constants.HttpStatus;
//import com.matchtech.common.core.constants.SecurityConstants;
//import com.matchtech.common.core.constants.TokenConstants;
//import com.matchtech.common.core.utils.JwtUtils;
//import com.matchtech.common.core.utils.ServletUtils;
//import com.matchtech.common.core.utils.StringUtils;
//import com.matchtech.common.redis.service.RedisService;
//import com.matchtech.gateway.config.properties.IgnoreWhiteProperties;
//import io.jsonwebtoken.Claims;
//import reactor.core.publisher.Mono;
//
///**
// * 网关鉴权
// *
// * @author matchtech
// */
//@Component
//public class AuthFilter implements GlobalFilter, Ordered
//{
// private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
//
// // 排除过滤的 uri 地址,nacos自行添加
// @Autowired
// private IgnoreWhiteProperties ignoreWhite;
//
// @Autowired
// private RedisService redisService;
//
//
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
// {
// ServerHttpRequest request = exchange.getRequest();
// ServerHttpRequest.Builder mutate = request.mutate();
//
// String url = request.getURI().getPath();
// // 跳过不需要验证的路径
// if (StringUtils.matches(url, ignoreWhite.getWhites()))
// {
// return chain.filter(exchange);
// }
// String token = getToken(request);
// if (StringUtils.isEmpty(token))
// {
// return unauthorizedResponse(exchange, "令牌不能为空");
// }
// Claims claims = JwtUtils.parseToken(token);
// if (claims == null)
// {
// return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
// }
// String userkey = JwtUtils.getUserKey(claims);
// boolean islogin = redisService.hasKey(getTokenKey(userkey));
// if (!islogin)
// {
// return unauthorizedResponse(exchange, "登录状态已过期");
// }
// String userid = JwtUtils.getUserId(claims);
// String username = JwtUtils.getUserName(claims);
// if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))
// {
// return unauthorizedResponse(exchange, "令牌验证失败");
// }
//
// // 设置用户信息到请求
// addHeader(mutate, SecurityConstants.USER_KEY, userkey);
// addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
// addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
// // 内部请求来源参数清除
// removeHeader(mutate, SecurityConstants.FROM_SOURCE);
// return chain.filter(exchange.mutate().request(mutate.build()).build());
// }
//
// private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value)
// {
// if (value == null)
// {
// return;
// }
// String valueStr = value.toString();
// String valueEncode = ServletUtils.urlEncode(valueStr);
// mutate.header(name, valueEncode);
// }
//
// private void removeHeader(ServerHttpRequest.Builder mutate, String name)
// {
// mutate.headers(httpHeaders -> httpHeaders.remove(name)).build();
// }
//
// private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
// {
// log.error("[鉴权异常处理]请求路径:{},错误信息:{}", exchange.getRequest().getPath(), msg);
// return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
// }
//
// /**
// * 获取缓存key
// */
// private String getTokenKey(String token)
// {
// return CacheConstants.LOGIN_TOKEN_KEY + token;
// }
//
// /**
// * 获取请求token
// */
// private String getToken(ServerHttpRequest request)
// {
// String token = request.getHeaders().getFirst(SecurityConstants.AUTHORIZATION_HEADER);
// // 如果前端设置了令牌前缀,则裁剪掉前缀
// if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX))
// {
// token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY);
// }
// return token;
// }
//
// @Override
// public int getOrder()
// {
// return -200;
// }
//}
\ No newline at end of file
package com.matchtech.gateway.filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import com.matchtech.common.core.constants.CacheConstants;
import com.matchtech.common.core.constants.HttpStatus;
import com.matchtech.common.core.constants.SecurityConstants;
import com.matchtech.common.core.constants.TokenConstants;
import com.matchtech.common.core.utils.JwtUtils;
import com.matchtech.common.core.utils.ServletUtils;
import com.matchtech.common.core.utils.StringUtils;
import com.matchtech.common.redis.service.RedisService;
import com.matchtech.gateway.config.properties.IgnoreWhiteProperties;
import io.jsonwebtoken.Claims;
import reactor.core.publisher.Mono;
/**
* 网关鉴权
*
* @author matchtech
*/
@Component
public class AuthFilter implements GlobalFilter, Ordered
{
private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
// 排除过滤的 uri 地址,nacos自行添加
@Autowired
private IgnoreWhiteProperties ignoreWhite;
@Autowired
private RedisService redisService;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
{
ServerHttpRequest request = exchange.getRequest();
ServerHttpRequest.Builder mutate = request.mutate();
String url = request.getURI().getPath();
// 跳过不需要验证的路径
if (StringUtils.matches(url, ignoreWhite.getWhites()))
{
return chain.filter(exchange);
}
String token = getToken(request);
if (StringUtils.isEmpty(token))
{
return unauthorizedResponse(exchange, "令牌不能为空");
}
Claims claims = JwtUtils.parseToken(token);
if (claims == null)
{
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
}
String userkey = JwtUtils.getUserKey(claims);
boolean islogin = redisService.hasKey(getTokenKey(userkey));
if (!islogin)
{
return unauthorizedResponse(exchange, "登录状态已过期");
}
String userid = JwtUtils.getUserId(claims);
String username = JwtUtils.getUserName(claims);
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))
{
return unauthorizedResponse(exchange, "令牌验证失败");
}
// 设置用户信息到请求
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
// 内部请求来源参数清除
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
Mono<Void> filter = chain.filter(exchange.mutate().request(mutate.build()).build());
return filter;
}
private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value)
{
if (value == null)
{
return;
}
String valueStr = value.toString();
String valueEncode = ServletUtils.urlEncode(valueStr);
mutate.header(name, valueEncode);
}
private void removeHeader(ServerHttpRequest.Builder mutate, String name)
{
mutate.headers(httpHeaders -> httpHeaders.remove(name)).build();
}
private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
{
log.error("[鉴权异常处理]请求路径:{},错误信息:{}", exchange.getRequest().getPath(), msg);
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
}
/**
* 获取缓存key
*/
private String getTokenKey(String token)
{
return CacheConstants.LOGIN_TOKEN_KEY + token;
}
/**
* 获取请求token
*/
private String getToken(ServerHttpRequest request)
{
String token = request.getHeaders().getFirst(SecurityConstants.AUTHORIZATION_HEADER);
// 如果前端设置了令牌前缀,则裁剪掉前缀
if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX))
{
token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY);
}
return token;
}
@Override
public int getOrder()
{
return -200;
}
}
\ No newline at end of file
package com.matchtech.gateway.filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
@Configuration
public class FilterConfig {
/**重新HttpServletRequest,让输入流body支持多次读取。
* @return
*/
@Bean
public FilterRegistrationBean<HttpServletRequestRewriteFilter> httpServletRequestRewriteFilterFilter() {
FilterRegistrationBean<HttpServletRequestRewriteFilter> registration = new FilterRegistrationBean<HttpServletRequestRewriteFilter>(
new HttpServletRequestRewriteFilter());
registration.addUrlPatterns("/a/*","/f/*");
registration.setName("httpServletRequestRewriteFilter");
registration.setOrder(1);
return registration;
}
/**登录拦截检验,并把把token和租户ID放进
* @return
*/
@Bean
public FilterRegistrationBean<LoginAndThreadLocalFilter> setThreadLocalFilter() {
FilterRegistrationBean<LoginAndThreadLocalFilter> registration = new FilterRegistrationBean<LoginAndThreadLocalFilter>(
new LoginAndThreadLocalFilter());
registration.addUrlPatterns("/a/*","/f/*");
registration.setName("loginAndThreadLocalFilter");
registration.setOrder(2);
return registration;
}
/**权限验证过滤器。
* @return
*/
@Bean
public FilterRegistrationBean<PermissionAuthenticationFilter> permissionAuthenticationFilter() {
FilterRegistrationBean<PermissionAuthenticationFilter> registration = new FilterRegistrationBean<PermissionAuthenticationFilter>(
new PermissionAuthenticationFilter());
registration.addUrlPatterns("/a/*","/f/*");
registration.setName("permissionAuthenticationFilter");
registration.setOrder(Ordered.LOWEST_PRECEDENCE);
return registration;
}
}
package com.matchtech.gateway.filter;
import com.matchtech.utils.servlet.MyHttpServletRequestWrapper;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class HttpServletRequestRewriteFilter implements Filter {
protected Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
// 排除文件上传接口
if (null != httpServletRequest.getHeader("Content-Type")
&& httpServletRequest.getHeader("Content-Type").contains("multipart/form-data")) {
chain.doFilter(request, response);
return;
}
MyHttpServletRequestWrapper myHttpServletRequestWrapper = new MyHttpServletRequestWrapper(httpServletRequest);
chain.doFilter(myHttpServletRequestWrapper, response);
}
}
package com.matchtech.gateway.filter;
import com.matchtech.common.core.async.MyThreadLocal;
import com.matchtech.common.core.config.MatchtechProperties;
import com.matchtech.common.core.constants.GlobalCodeMessageEnum;
import com.matchtech.common.core.page.resp.ApiResponseUtils;
import com.matchtech.common.redis.constant.RedisConstants;
import com.matchtech.common.redis.service.RedisUtils;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import java.io.IOException;
import java.io.PrintWriter;
public class LoginAndThreadLocalFilter implements Filter {
protected Logger logger = LoggerFactory.getLogger(getClass());
private SysUserService sysUserService;
private MatchtechProperties matchtechProperties;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext sc = filterConfig.getServletContext();
WebApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(sc);
if (cxt != null) {
if (sysUserService == null) {
sysUserService = cxt.getBean(SysUserService.class);
}
if (matchtechProperties == null) {
matchtechProperties = cxt.getBean(MatchtechProperties.class);
}
}
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
String tenantId = httpServletRequest.getHeader("tenantId");
String token = httpServletRequest.getHeader("token");
// 登录校验拦截
if (!matchtechProperties.containPath(httpServletRequest.getRequestURI())) {
if (StringUtils.isEmpty(token) || "null".equals(token)) {
this.writer(httpServletResponse, ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_TOKEN_NOT_FOUND));
return;
}
CurrentUserDTO currentUserDTO = RedisUtils.get(RedisConstants.SYS_USER_TOKEN_PREFIX + token);
if (null == currentUserDTO) {
this.writer(httpServletResponse, ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_TOKEN_OVERDUE));
return;
}
// 重置token时间
RedisUtils.setExpire(RedisConstants.SYS_USER_TOKEN_PREFIX +token, Long.parseLong(matchtechProperties.getTokenTimeout()));
MyThreadLocal.setUserThreadLocal(currentUserDTO);
}
// 设置token和tenantId到ThreadLocal
MyThreadLocal.setToken(httpServletRequest.getHeader("token"));
MyThreadLocal.setTenantId(httpServletRequest.getHeader("tenantId"));
chain.doFilter(request, response);
//清除ThreadLocal
MyThreadLocal.remove();
}
private void writer(HttpServletResponse httpServletResponse, Object value) throws IOException {
httpServletResponse.setContentType("application/json");
httpServletResponse.setCharacterEncoding("UTF-8");
PrintWriter printWriter = httpServletResponse.getWriter();
printWriter.print(value);
printWriter.flush();
printWriter.close();
}
}
package com.matchtech.gateway.filter;
import com.matchtech.config.MatchtechProperties;
import com.matchtech.service.SysRoleMenuService;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import java.io.IOException;
import java.io.PrintWriter;
public class PermissionAuthenticationFilter implements Filter {
protected Logger logger = LoggerFactory.getLogger(getClass());
private SysRoleMenuService sysRoleMenuService;
private MatchtechProperties matchtechProperties;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext sc = filterConfig.getServletContext();
WebApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(sc);
if (cxt != null) {
if (sysRoleMenuService == null) {
sysRoleMenuService = cxt.getBean(SysRoleMenuService.class);
}
if (matchtechProperties == null) {
matchtechProperties = cxt.getBean(MatchtechProperties.class);
}
}
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
// List<String> list = matchtechProperties.getWhite().get("authorityurls");
// list.addAll(matchtechProperties.getWhite().get("loginurls"));
// CurrentUserDTO sysUser = RedisUtils.get(RedisConstants.SYS_USER_TOKEN_PREFIX + MyThreadLocal.getToken());
// // 登录校验拦截
// if (null != sysUser && !Constants.SUPER_ADMIN_ID.equals(sysUser.getId()) && !list.contains(httpServletRequest.getRequestURI())) {
// Map<String, SysMenuVo> map = sysRoleMenuService.getMenuByToken(MyThreadLocal.getToken());
//权限注解 判断
//获取处理器方法
// HttpServletRequest httpRequest = (HttpServletRequest) request;
// Object handler = httpRequest.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
// if (handler instanceof HandlerMethod) {
// HandlerMethod handlerMethod = (HandlerMethod) handler;
// Method method = handlerMethod.getMethod();
// // 获取方法上的注解
// Permission annotation = method.getAnnotation(Permission.class);
// if (annotation != null) {
// String code = annotation.code();
// if(StringUtils.isNotBlank(code)){
// if (null == map.get(code)) {
// this.writer(httpServletResponse, ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_NOT_AUTH));
// return;
// }
// }
// }
// }
// }
chain.doFilter(request, response);
}
private void writer(HttpServletResponse httpServletResponse, Object value) throws IOException {
httpServletResponse.setContentType("application/json");
httpServletResponse.setCharacterEncoding("UTF-8");
PrintWriter printWriter = httpServletResponse.getWriter();
printWriter.print(value);
printWriter.close();
}
}
# Tomcat
server:
port: 8080
port: 9999
# Spring
spring:
......@@ -23,6 +23,9 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
extension-configs:
- data-id: matchtech-gateway-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
refresh: true
sentinel:
# 取消控制台懒加载
eager: true
......
package com.matchtech.system.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.matchtech.common.core.constants.GlobalCodeMessageEnum;
import com.matchtech.common.core.domain.R;
import com.matchtech.common.core.page.resp.ApiResponseEntity;
import com.matchtech.common.core.page.resp.ApiResponseUtils;
import com.matchtech.common.core.utils.StringUtils;
import com.matchtech.common.core.web.controller.BaseController;
import com.matchtech.common.dto.BaseIdDto;
import com.matchtech.common.dto.login.SysUserDetailVo;
import com.matchtech.system.api.domain.SysUser;
import com.matchtech.system.api.model.LoginUser;
import com.matchtech.system.entity.SysUserEntity;
import com.matchtech.system.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;
import java.util.Set;
@Tag(name = "系统用户管理")
@RestController
@RequestMapping(value = "${matchtech.adminPath}/sys/user")
......@@ -16,4 +34,31 @@ public class SysUserController extends BaseController {
@Autowired
private SysUserService sysUserService;
@Operation(summary = "用户详情")
@PostMapping("/detail")
public ApiResponseEntity<SysUserEntity> detail(@RequestBody BaseIdDto baseIdDto) {
return ApiResponseUtils.success(sysUserService.getById(baseIdDto.getId()));
}
@GetMapping("/info/{userId}")
public ApiResponseEntity<LoginUser> info(@PathVariable("userId") String userId)
{
SysUserEntity sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUserEntity.class).eq(SysUserEntity::getLoginName,userId),Boolean.FALSE);
if (StringUtils.isNull(sysUser))
{
return ApiResponseEntity.fail(GlobalCodeMessageEnum.SYSTEM_USER_NOT_FOUND);
}
// // 角色集合
// Set<String> roles = permissionService.getRolePermission(sysUser);
// // 权限集合
// Set<String> permissions = permissionService.getMenuPermission(sysUser);
LoginUser sysUserVo = new LoginUser();
sysUserVo.setUserid(sysUser.getId());
sysUserVo.setUsername(sysUser.getName());
//sysUserVo.setSysUser(sysUser);
//sysUserVo.setRoles(roles);
//sysUserVo.setPermissions(permissions);
return ApiResponseEntity.success(sysUserVo);
}
}
......@@ -4,7 +4,7 @@ import cn.hutool.core.util.HexUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.matchtech.common.core.async.MyThreadLocal;
import com.matchtech.common.core.thread.MyThreadLocal;
import com.matchtech.common.core.config.MatchtechProperties;
import com.matchtech.common.core.constants.Constants;
import com.matchtech.common.core.constants.GlobalCodeMessageEnum;
......@@ -15,12 +15,12 @@ import com.matchtech.common.core.utils.sign.RsaUtil;
import com.matchtech.common.dto.login.SysLoginVo;
import com.matchtech.common.redis.constant.RedisConstants;
import com.matchtech.common.redis.service.RedisUtils;
import com.matchtech.common.security.service.TokenService;
import com.matchtech.system.convertors.SysUserConvertor;
import com.matchtech.system.domain.dto.SysLoginDto;
import com.matchtech.common.dto.login.SysLoginDto;
import com.matchtech.system.entity.SysUserEntity;
import com.matchtech.system.mapper.SysUserMapper;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -47,6 +47,8 @@ public class SysUserService extends ServiceImpl<SysUserMapper, SysUserEntity> {
private long maxLoginFailedAttempts;
@Value("${matchtech.user.lock-duration}")
private int lockDuration;
@Autowired
private TokenService tokenService;
@Transactional
public SysLoginVo login(SysLoginDto loginDto) {
......@@ -178,28 +180,6 @@ public class SysUserService extends ServiceImpl<SysUserMapper, SysUserEntity> {
return RedisUtils.get(RedisConstants.USER_LOGIN_LOCKED + userId) != null;
}
// @Transactional
// public void updatePassword(SysUpdatePasswordDto updatePasswordDto) {
// SysUserEntity currentUser = getCurrentUser();
// if (!validatePassword(updatePasswordDto.getOldPassword(), currentUser.getPassword())) {
// throw new GlobalException(GlobalCodeMessageEnum.SYS_USER_OLD_PASSWORD_ERROR);
// }
// LambdaUpdateWrapper<SysUserEntity> updateWrapper = new LambdaUpdateWrapper<>();
// updateWrapper.set(SysUserEntity::getPassword, RsaUtil.encrypt(updatePasswordDto.getNewPassword()))
// .eq(SysUserEntity::getId, currentUser.getId());
// sysUserMapper.update(null, updateWrapper);
// }
// @Transactional
// public void resetPassword(SysResetPasswordDto sysResetPasswordDto) {
//
// LambdaUpdateWrapper<SysUserEntity> updateWrapper = new LambdaUpdateWrapper<>();
// updateWrapper.set(SysUserEntity::getPassword, RsaUtil.encrypt(sysResetPasswordDto.getNewPassword()))
// .eq(SysUserEntity::getId, sysResetPasswordDto.getUserId());
// sysUserMapper.update(null, updateWrapper);
// }
/**
* 获取当前登录用户
*/
......@@ -262,76 +242,6 @@ public class SysUserService extends ServiceImpl<SysUserMapper, SysUserEntity> {
// return password.equals(HexUtil.encodeHexStr(salt) + HexUtil.encodeHexStr(hashPassword));
return RsaUtil.decrypt(plainPassword).equals(RsaUtil.decrypt(password));
}
// /**
// * 批量启用/禁用
// * @param req 参数
// */
// @Transactional(rollbackFor = Exception.class)
// public void changeStatus(SysUserReq.ChangeStatus req) {
// super.update(null, Wrappers.lambdaUpdate(SysUserEntity.class)
// .set(SysUserEntity::getLoginFlag, req.getStatus())
// .in(SysUserEntity::getId, req.getIds()));
// //清除登录信息
// if (Constants.NO.equals(req.getStatus())) {
// for (String id : req.getIds()) {
// String token = RedisUtils.get(RedisConstants.SYS_USER_ID_TOKEN_PREFIX + id);
// if (StrUtil.isNotBlank(token)) {
// RedisUtils.delete(RedisConstants.SYS_USER_TOKEN_PREFIX + token);
// }
// RedisUtils.delete(RedisConstants.SYS_USER_ID_TOKEN_PREFIX + id);
// }
// }
// }
// /**
// * 通过工号查询员工信息
// * @param managerId 工号
// * @return 员工信息
// */
// public EmployeeInfoVo getEmployeeInfoByManagerId(String managerId) {
// return sysUserMapper.selectEmployeeInfoById(managerId);
// }
// /**
// * 根据机构ID查询员工信息
// * @param officeId 机构ID
// * @return 员工信息列表
// */
// public List<EmployeeInfoVo> getEmployeeInfoByOfficeId(String officeId) {
// return sysUserMapper.selectEmployeeInfoByOfficeId(officeId);
// }
// /**
// * 根据机构ID和筛选条件查询员工信息
// * @param req 筛选条件
// * @return 员工信息列表
// */
// public PageVO<EmployeeInfoVo> getEmployeeInfoByOfficeIdWithFilter(PageReqDto<EmployeeInfoVo> req) {
// EmployeeInfoVo employeeInfoVo = req.getSearch();
// Page page = sysUserMapper.selectEmployeeInfoByOfficeIdWithFilter(MyBatisUtils.buildPage(req),employeeInfoVo);
// return new PageVO(page, page.getRecords());
// }
// /**
// * 根据角色ID获取用户ID列表
// */
// public List<String> listUserIdByRoleId(String roleId) {
// if (roleId == null){
// return new ArrayList<>();
// }
// return sysUserRoleService.getUserListByRoleId(roleId);
// }
// /**
// * 根据角色ID列表获取用户ID列表
// */
// public List<String> listUserIdByRoleIds(List<String> roleIds) {
// if (roleIds == null || roleIds.isEmpty()){
// return new ArrayList<>();
// }
// return sysUserRoleService.getUserListByRoleIds(roleIds);
// }
}
......@@ -19,7 +19,7 @@
<!-- Spring生态核心版本 -->
<spring-boot.version>3.1.1</spring-boot.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
<spring-cloud-alibaba.version>2022.0.0.2</spring-cloud-alibaba.version>
<spring-boot-admin.version>3.1.1</spring-boot-admin.version>
<!-- 数据访问层版本 -->
......@@ -265,6 +265,24 @@
<version>${matchtech.version}</version>
</dependency>
<dependency>
<groupId>com.matchtech</groupId>
<artifactId>matchtech-common-dto</artifactId>
<version>${matchtech.version}</version>
</dependency>
<dependency>
<groupId>io.springboot</groupId>
<artifactId>knife4j-openapi3-ui</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.20</version>
</dependency>
</dependencies>
</dependencyManagement>
......
2025年12月30日
2025年12月29日
2025年12月30日
2025年12月29日
springboot 降版本到3.1.1,其他也降版本
授权
2025年12月30日
账号密码登录认证
swagger
单点登录
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment