perf:调整登录模块
This commit is contained in:
20
demo/pom.xml
20
demo/pom.xml
@@ -25,4 +25,24 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>kepai-repo</id>
|
||||||
|
<url>http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
1
pom.xml
1
pom.xml
@@ -35,6 +35,7 @@
|
|||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<mybatis-plus.version>3.5.1</mybatis-plus.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
public class DbMigrationConfig {
|
public class DbMigrationConfig {
|
||||||
|
|
||||||
private String table = "core_db_migration";
|
private String table = "core_db_migration";
|
||||||
private List<String> locations = CollUtil.newArrayList("classpath:db/migration/*.sql");
|
private List<String> locations = CollUtil.newArrayList("classpath*:db/migration/*.sql");
|
||||||
private String ignoreSqls = "drop,delete";
|
private String ignoreSqls = "drop,delete";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,14 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- aspect -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng</groupId>
|
<groupId>com.tiesheng</groupId>
|
||||||
<artifactId>tiesheng-ding</artifactId>
|
<artifactId>tiesheng-ding</artifactId>
|
||||||
@@ -30,6 +38,14 @@
|
|||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.tiesheng.login;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
|
||||||
|
@ComponentScan({
|
||||||
|
"com.tiesheng.login.**.*",
|
||||||
|
})
|
||||||
|
@MapperScan("com.tiesheng.login.mapper")
|
||||||
|
public class LoginAutoImportSelector {
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tiesheng.core.config.token;
|
package com.tiesheng.login.config.token;
|
||||||
|
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
@@ -6,6 +6,7 @@ import org.aspectj.lang.annotation.Aspect;
|
|||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -22,7 +23,10 @@ import java.lang.reflect.Method;
|
|||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class TokenValidAspect {
|
public class TsTokenAspect {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TsTokenConfig tsTokenConfig;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +55,8 @@ public class TokenValidAspect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// token验证
|
// token验证
|
||||||
TokenParse.get();
|
tsTokenConfig.validToken(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package com.tiesheng.login.config.token;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.hutool.jwt.JWT;
|
||||||
|
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||||
|
import com.tiesheng.util.ServletKit;
|
||||||
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties("tiesheng.token")
|
||||||
|
public class TsTokenConfig {
|
||||||
|
|
||||||
|
private Map<String, TokenBean> ignores = MapUtil.newHashMap();
|
||||||
|
private String encryptKey = "%kIp9frQCu";
|
||||||
|
private Integer expireHours = 48;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录的token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static TokenBean get() {
|
||||||
|
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
||||||
|
return tokenConfig.validToken(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录的token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static TokenBean getWithoutThr() {
|
||||||
|
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
||||||
|
return tokenConfig.validToken(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证token
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TokenBean isIgnored(String token) {
|
||||||
|
if (ignores == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ignores.get(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置token
|
||||||
|
*/
|
||||||
|
public String toToken(String id, String environmentType, String service, String extra) {
|
||||||
|
return JWT.create()
|
||||||
|
.setPayload("id", id)
|
||||||
|
.setPayload("environmentType", environmentType)
|
||||||
|
.setPayload("service", service)
|
||||||
|
.setPayload("extra", extra)
|
||||||
|
.setPayload("time", System.currentTimeMillis() + expireHours * 1000 * 60 * 60)
|
||||||
|
.setKey(getEncryptKey().getBytes())
|
||||||
|
.sign();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TokenBean validToken(boolean thrExp) {
|
||||||
|
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
||||||
|
TokenBean tokenBean = isIgnored(token);
|
||||||
|
if (tokenBean != null) {
|
||||||
|
return tokenBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
JWT decode = JWT.of(token);
|
||||||
|
String id = decode.getPayload("id").toString();
|
||||||
|
String environmentType = decode.getPayload("environmentType").toString();
|
||||||
|
String service = decode.getPayload("service").toString();
|
||||||
|
String extra = decode.getPayload("extra").toString();
|
||||||
|
Long expireTime = decode.getPayloads().getLong("time");
|
||||||
|
if (expireTime != null && expireTime < System.currentTimeMillis()) {
|
||||||
|
throw new ApiException("登录过期,请重新登陆");
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBean = new TokenBean(id, environmentType, service);
|
||||||
|
tokenBean.setExtra(extra);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokenBean == null && thrExp) {
|
||||||
|
throw new ApiException(StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokenBean == null) {
|
||||||
|
tokenBean = new TokenBean();
|
||||||
|
tokenBean.setId("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokenBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public Map<String, TokenBean> getIgnores() {
|
||||||
|
return ignores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIgnores(Map<String, TokenBean> ignores) {
|
||||||
|
this.ignores = ignores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEncryptKey() {
|
||||||
|
return encryptKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncryptKey(String encryptKey) {
|
||||||
|
this.encryptKey = encryptKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getExpireHours() {
|
||||||
|
return expireHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpireHours(Integer expireHours) {
|
||||||
|
this.expireHours = expireHours;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.tiesheng.core.config.token.bean;
|
package com.tiesheng.login.config.token.bean;
|
||||||
|
|
||||||
import cn.hutool.jwt.JWT;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
public class TokenBean {
|
public class TokenBean {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
@@ -19,21 +20,6 @@ public class TokenBean {
|
|||||||
this.extra = "";
|
this.extra = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置token
|
|
||||||
*/
|
|
||||||
public String toToken() {
|
|
||||||
byte[] key = "%kIp9frQCu".getBytes();
|
|
||||||
return JWT.create()
|
|
||||||
.setPayload("id", id)
|
|
||||||
.setPayload("environmentType", environmentType)
|
|
||||||
.setPayload("service", service)
|
|
||||||
.setPayload("extra", extra)
|
|
||||||
.setPayload("time", System.currentTimeMillis())
|
|
||||||
.setKey(key)
|
|
||||||
.sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.tiesheng.login.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/login/user")
|
||||||
|
public class LoginUserController {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.tiesheng.login.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||||
|
|
||||||
|
public interface CoreLogLoginMapper extends BaseMapper<CoreLogLogin> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package com.tiesheng.login.pojos.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志-登录
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_log_login")
|
||||||
|
public class CoreLogLogin {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@TableField(value = "is_deleted")
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ip
|
||||||
|
*/
|
||||||
|
@TableField(value = "platform")
|
||||||
|
private String platform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ip
|
||||||
|
*/
|
||||||
|
@TableField(value = "ip")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ip地址
|
||||||
|
*/
|
||||||
|
@TableField(value = "address")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIsDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDeleted(Integer isDeleted) {
|
||||||
|
this.isDeleted = isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户id
|
||||||
|
*
|
||||||
|
* @return user_id - 用户id
|
||||||
|
*/
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户id
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ip
|
||||||
|
*
|
||||||
|
* @return ip - ip
|
||||||
|
*/
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置ip
|
||||||
|
*
|
||||||
|
* @param ip ip
|
||||||
|
*/
|
||||||
|
public void setIp(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ip地址
|
||||||
|
*
|
||||||
|
* @return address - ip地址
|
||||||
|
*/
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置ip地址
|
||||||
|
*
|
||||||
|
* @param address ip地址
|
||||||
|
*/
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.tiesheng.login.service;
|
||||||
|
|
||||||
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.tiesheng.login.mapper.CoreLogLoginMapper;
|
||||||
|
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||||
|
import com.tiesheng.util.ServletKit;
|
||||||
|
import com.tiesheng.util.ip2region.DataBlock;
|
||||||
|
import com.tiesheng.util.ip2region.Ip2Region;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class LoginLogService extends ServiceImpl<CoreLogLoginMapper, CoreLogLogin> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
public void addLog(String userId, String platform) {
|
||||||
|
|
||||||
|
HttpServletRequest request = ServletKit.getRequest();
|
||||||
|
String ip = ServletUtil.getClientIP(request);
|
||||||
|
|
||||||
|
CoreLogLogin login = new CoreLogLogin();
|
||||||
|
login.setUserId(userId);
|
||||||
|
login.setPlatform(platform);
|
||||||
|
|
||||||
|
login.setIp(ip);
|
||||||
|
DataBlock dataBlock = Ip2Region.getInstance().btreeSearch(ip);
|
||||||
|
login.setAddress(dataBlock.getRegion());
|
||||||
|
save(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for core_log_login
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `core_log_login`
|
||||||
|
(
|
||||||
|
`id` varchar(50) NOT NULL,
|
||||||
|
`create_time` datetime NOT NULL,
|
||||||
|
`update_time` datetime NOT NULL,
|
||||||
|
`is_deleted` int(6) NOT NULL DEFAULT '0',
|
||||||
|
`user_id` varchar(50) DEFAULT NULL COMMENT '用户id',
|
||||||
|
`user_name` varchar(255) DEFAULT NULL COMMENT '用户姓名',
|
||||||
|
`platform` varchar(50) DEFAULT NULL COMMENT '登录方式',
|
||||||
|
`ip` varchar(100) DEFAULT NULL COMMENT 'ip',
|
||||||
|
`address` varchar(255) DEFAULT NULL COMMENT 'ip地址',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE = InnoDB
|
||||||
|
DEFAULT CHARSET = utf8mb4 COMMENT ='日志-登录';
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?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.tiesheng.login.mapper.CoreLogLoginMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.tiesheng.login.pojos.dao.CoreLogLogin">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
<!--@Table core_log_login-->
|
||||||
|
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||||
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||||
|
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||||
|
<result column="user_id" jdbcType="VARCHAR" property="userId" />
|
||||||
|
<result column="user_name" jdbcType="VARCHAR" property="userName" />
|
||||||
|
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||||
|
<result column="ip" jdbcType="VARCHAR" property="ip" />
|
||||||
|
<result column="address" jdbcType="VARCHAR" property="address" />
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
@@ -18,6 +18,13 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tiesheng.core.util.servlet;
|
package com.tiesheng.util;
|
||||||
|
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
@@ -48,14 +48,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.12</version>
|
<version>8.0.30</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mybatis-plus -->
|
<!-- mybatis-plus -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>${mybatis-plus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.tiesheng.core;
|
package com.tiesheng.core;
|
||||||
|
|
||||||
|
import com.tiesheng.login.LoginAutoImportSelector;
|
||||||
import com.tiesheng.migration.MigrationAutoImportSelector;
|
import com.tiesheng.migration.MigrationAutoImportSelector;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
@@ -13,7 +15,9 @@ import java.lang.annotation.*;
|
|||||||
@Documented
|
@Documented
|
||||||
@Import({
|
@Import({
|
||||||
CoreAutoImportSelector.class,
|
CoreAutoImportSelector.class,
|
||||||
|
LoginAutoImportSelector.class,
|
||||||
MigrationAutoImportSelector.class
|
MigrationAutoImportSelector.class
|
||||||
})
|
})
|
||||||
|
@ComponentScan("cn.hutool.extra.spring")
|
||||||
public @interface EnableTieshengWeb {
|
public @interface EnableTieshengWeb {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.tiesheng.annotation.operation.OperationLog;
|
import com.tiesheng.annotation.operation.OperationLog;
|
||||||
import com.tiesheng.core.config.token.TokenParse;
|
|
||||||
import com.tiesheng.core.config.token.bean.TokenBean;
|
|
||||||
import com.tiesheng.core.service.CoreLogService;
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.tiesheng.core.config.token;
|
|
||||||
|
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import cn.hutool.jwt.JWT;
|
|
||||||
import com.tiesheng.core.config.token.bean.TokenBean;
|
|
||||||
import com.tiesheng.core.util.servlet.ServletKit;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
public class TokenParse {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取登陆信息
|
|
||||||
*
|
|
||||||
* @param token
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static TokenBean get(String token) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
TokenValidConfig tokenValidConfig = SpringUtil.getBean(TokenValidConfig.class);
|
|
||||||
TokenBean tokenBean = tokenValidConfig.getTokenBean(token);
|
|
||||||
if (tokenBean == null) {
|
|
||||||
JWT decode = JWT.of(token);
|
|
||||||
String id = decode.getPayload("id").toString();
|
|
||||||
String environmentType = decode.getPayload("environmentType").toString();
|
|
||||||
String service = decode.getPayload("service").toString();
|
|
||||||
String extra = decode.getPayload("extra").toString();
|
|
||||||
tokenBean = new TokenBean(id, environmentType, service);
|
|
||||||
tokenBean.setExtra(extra);
|
|
||||||
}
|
|
||||||
return tokenBean;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ApiException(ApiResp.respNeedLogin("请重新登录"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取登录信息
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static TokenBean get() {
|
|
||||||
String headerToken = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
|
||||||
return get(headerToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static TokenBean getWithoutThr() {
|
|
||||||
TokenBean tokenBean = null;
|
|
||||||
try {
|
|
||||||
tokenBean = get();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
return tokenBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.tiesheng.core.config.token;
|
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
|
||||||
import com.tiesheng.core.config.token.bean.TokenBean;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties("tiesheng.token")
|
|
||||||
public class TokenValidConfig {
|
|
||||||
|
|
||||||
private Map<String, TokenBean> ignores = MapUtil.newHashMap();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证token
|
|
||||||
*
|
|
||||||
* @param token
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public TokenBean getTokenBean(String token) {
|
|
||||||
if (ignores == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ignores.get(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// setter\getter
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public Map<String, TokenBean> getIgnores() {
|
|
||||||
return ignores;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIgnores(Map<String, TokenBean> ignores) {
|
|
||||||
this.ignores = ignores;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tiesheng.core.config.web;
|
package com.tiesheng.core.config.web;
|
||||||
|
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.tiesheng.core.config.token.TokenParse;
|
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||||
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||||
import com.tiesheng.util.exception.ApiRespEnum;
|
import com.tiesheng.util.exception.ApiRespEnum;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
@@ -23,7 +23,7 @@ public interface TieshengWebConfigurer {
|
|||||||
*/
|
*/
|
||||||
default CurrentWebUser getCurrentUserName() {
|
default CurrentWebUser getCurrentUserName() {
|
||||||
CurrentWebUser webUser = new CurrentWebUser();
|
CurrentWebUser webUser = new CurrentWebUser();
|
||||||
webUser.setId(TokenParse.getWithoutThr().getId());
|
webUser.setId(TsTokenConfig.getWithoutThr().getId());
|
||||||
return webUser;
|
return webUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||||
import com.tiesheng.core.pojos.dto.PageDTO;
|
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||||
import com.tiesheng.core.service.CoreLogService;
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
|
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||||
|
import com.tiesheng.login.service.LoginLogService;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -23,6 +25,8 @@ public class ManagerLogController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CoreLogService coreLogService;
|
CoreLogService coreLogService;
|
||||||
|
@Autowired(required = false)
|
||||||
|
LoginLogService loginLogService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +35,7 @@ public class ManagerLogController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/operation/page")
|
@GetMapping("/operation/page")
|
||||||
public ApiResp<List<CoreLogOperation>> operationList(@Valid PageDTO dto) {
|
public ApiResp<List<CoreLogOperation>> operationPage(@Valid PageDTO dto) {
|
||||||
|
|
||||||
QueryWrapper<CoreLogOperation> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<CoreLogOperation> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("is_deleted", 0);
|
queryWrapper.eq("is_deleted", 0);
|
||||||
@@ -44,4 +48,25 @@ public class ManagerLogController {
|
|||||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录日志列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/login/page")
|
||||||
|
public ApiResp<List<CoreLogLogin>> loginPage(@Valid PageDTO dto) {
|
||||||
|
|
||||||
|
QueryWrapper<CoreLogLogin> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("is_deleted", 0);
|
||||||
|
dto.likeColumns(queryWrapper, "user_name", "ip", "address");
|
||||||
|
queryWrapper.orderByDesc("create_time");
|
||||||
|
|
||||||
|
Page<CoreLogLogin> page = dto.pageObj();
|
||||||
|
if (loginLogService != null) {
|
||||||
|
loginLogService.page(page, queryWrapper);
|
||||||
|
}
|
||||||
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tiesheng.core.service;
|
package com.tiesheng.core.service;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.tiesheng.core.config.token.TokenParse;
|
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||||
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
||||||
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||||
import com.tiesheng.core.mapper.CoreLogOperationMapper;
|
import com.tiesheng.core.mapper.CoreLogOperationMapper;
|
||||||
@@ -33,7 +33,7 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
|||||||
operation.setUserId(currentWebUser.getId());
|
operation.setUserId(currentWebUser.getId());
|
||||||
operation.setUserName(currentWebUser.getName());
|
operation.setUserName(currentWebUser.getName());
|
||||||
} else {
|
} else {
|
||||||
operation.setUserId(TokenParse.getWithoutThr().getId());
|
operation.setUserId(TsTokenConfig.getWithoutThr().getId());
|
||||||
}
|
}
|
||||||
operation.setTitle(title);
|
operation.setTitle(title);
|
||||||
operation.setSubject(subject);
|
operation.setSubject(subject);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tiesheng.core.service;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import com.tiesheng.core.util.servlet.ServletKit;
|
import com.tiesheng.util.ServletKit;
|
||||||
import com.tiesheng.util.TimedCacheHelper;
|
import com.tiesheng.util.TimedCacheHelper;
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|||||||
Reference in New Issue
Block a user