perf:调整登录模块
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.tiesheng.core;
|
||||
|
||||
import com.tiesheng.login.LoginAutoImportSelector;
|
||||
import com.tiesheng.migration.MigrationAutoImportSelector;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@@ -13,7 +15,9 @@ import java.lang.annotation.*;
|
||||
@Documented
|
||||
@Import({
|
||||
CoreAutoImportSelector.class,
|
||||
LoginAutoImportSelector.class,
|
||||
MigrationAutoImportSelector.class
|
||||
})
|
||||
@ComponentScan("cn.hutool.extra.spring")
|
||||
public @interface EnableTieshengWeb {
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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 org.aspectj.lang.ProceedingJoinPoint;
|
||||
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,58 +0,0 @@
|
||||
package com.tiesheng.core.config.token;
|
||||
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
* @ProjectName CmccSpring
|
||||
* @Copyright Hangzhou ShuoChuang Technology Co.,Ltd All Right Reserved
|
||||
* @Description 这里是对文件的描述
|
||||
* @data 2019-07-15
|
||||
* @note 这里写文件的详细功能和改动
|
||||
* @note
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class TokenValidAspect {
|
||||
|
||||
|
||||
/**
|
||||
* 切入点
|
||||
*/
|
||||
@Pointcut("execution(* com..controller..*.*(..))")
|
||||
public void methodArgs() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取操作日志说明
|
||||
*
|
||||
* @param joinPoint
|
||||
*/
|
||||
@Before("methodArgs()")
|
||||
public void before(JoinPoint joinPoint) {
|
||||
|
||||
// 过滤不要需要验证的接口
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
TokenIgnore apiTokenIgnore = method.getAnnotation(TokenIgnore.class);
|
||||
if (apiTokenIgnore != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// token验证
|
||||
TokenParse.get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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,72 +0,0 @@
|
||||
package com.tiesheng.core.config.token.bean;
|
||||
|
||||
import cn.hutool.jwt.JWT;
|
||||
|
||||
public class TokenBean {
|
||||
|
||||
private String id;
|
||||
private String environmentType;
|
||||
private String service;
|
||||
private String extra;
|
||||
|
||||
public TokenBean() {
|
||||
}
|
||||
|
||||
public TokenBean(String id, String environmentType, String service) {
|
||||
this.id = id;
|
||||
this.environmentType = environmentType;
|
||||
this.service = service;
|
||||
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
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEnvironmentType() {
|
||||
return environmentType;
|
||||
}
|
||||
|
||||
public void setEnvironmentType(String environmentType) {
|
||||
this.environmentType = environmentType;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tiesheng.core.config.web;
|
||||
|
||||
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.util.exception.ApiRespEnum;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
@@ -23,7 +23,7 @@ public interface TieshengWebConfigurer {
|
||||
*/
|
||||
default CurrentWebUser getCurrentUserName() {
|
||||
CurrentWebUser webUser = new CurrentWebUser();
|
||||
webUser.setId(TokenParse.getWithoutThr().getId());
|
||||
webUser.setId(TsTokenConfig.getWithoutThr().getId());
|
||||
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.dto.PageDTO;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -23,6 +25,8 @@ public class ManagerLogController {
|
||||
|
||||
@Autowired
|
||||
CoreLogService coreLogService;
|
||||
@Autowired(required = false)
|
||||
LoginLogService loginLogService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,7 +35,7 @@ public class ManagerLogController {
|
||||
* @return
|
||||
*/
|
||||
@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.eq("is_deleted", 0);
|
||||
@@ -44,4 +48,25 @@ public class ManagerLogController {
|
||||
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;
|
||||
|
||||
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.bean.CurrentWebUser;
|
||||
import com.tiesheng.core.mapper.CoreLogOperationMapper;
|
||||
@@ -33,7 +33,7 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
operation.setUserId(currentWebUser.getId());
|
||||
operation.setUserName(currentWebUser.getName());
|
||||
} else {
|
||||
operation.setUserId(TokenParse.getWithoutThr().getId());
|
||||
operation.setUserId(TsTokenConfig.getWithoutThr().getId());
|
||||
}
|
||||
operation.setTitle(title);
|
||||
operation.setSubject(subject);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.tiesheng.core.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.exception.ApiException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.tiesheng.core.util.servlet;
|
||||
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class ServletKit extends ServletUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前线程的request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletRequest getRequest() {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes)
|
||||
RequestContextHolder.getRequestAttributes();
|
||||
return attributes.getRequest();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user