feat(7): 开启登录校验
This commit is contained in:
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于配置
|
* 用于公共字段的自动填充
|
||||||
*
|
*
|
||||||
* @author guo
|
* @author guo
|
||||||
*/
|
*/
|
||||||
@@ -20,10 +20,6 @@ public class AutoTableField implements MetaObjectHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertFill(MetaObject metaObject) {
|
public void insertFill(MetaObject metaObject) {
|
||||||
log.info("insert autoField");
|
|
||||||
log.warn("============================已自动登录==============================");
|
|
||||||
StpUtil.login("testUser");
|
|
||||||
log.warn("============================已自动登录==============================");
|
|
||||||
this.strictInsertFill(metaObject, "createdBy", StpUtil::getLoginIdAsString, String.class);
|
this.strictInsertFill(metaObject, "createdBy", StpUtil::getLoginIdAsString, String.class);
|
||||||
this.strictInsertFill(metaObject, "createdTime", LocalDateTime::now, LocalDateTime.class);
|
this.strictInsertFill(metaObject, "createdTime", LocalDateTime::now, LocalDateTime.class);
|
||||||
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
||||||
@@ -33,10 +29,6 @@ public class AutoTableField implements MetaObjectHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFill(MetaObject metaObject) {
|
public void updateFill(MetaObject metaObject) {
|
||||||
log.info("update autoField");
|
|
||||||
log.warn("============================已自动登录==============================");
|
|
||||||
StpUtil.login("testUser");
|
|
||||||
log.warn("============================已自动登录==============================");
|
|
||||||
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
||||||
this.strictInsertFill(metaObject, "lastModifiedTime", LocalDateTime::now, LocalDateTime.class);
|
this.strictInsertFill(metaObject, "lastModifiedTime", LocalDateTime::now, LocalDateTime.class);
|
||||||
this.strictInsertFill(metaObject,"deviceInfo",StpUtil::getLoginDevice,String.class);
|
this.strictInsertFill(metaObject,"deviceInfo",StpUtil::getLoginDevice,String.class);
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
package com.guo.learningprogresstracker.config;
|
package com.guo.learningprogresstracker.config;
|
||||||
|
|
||||||
import com.guo.learningprogresstracker.config.interceptor.Interceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
public class SaTokenConfigure implements WebMvcConfigurer {
|
||||||
@Autowired
|
|
||||||
Interceptor interceptor;
|
|
||||||
// 注册拦截器
|
// 注册拦截器
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
|
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
|
||||||
registry.addInterceptor(interceptor)
|
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns(Arrays.asList("/login","/tasks"));
|
.excludePathPatterns("/login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.guo.learningprogresstracker.config.interceptor;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拦截器
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class Interceptor implements HandlerInterceptor {
|
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
|
|
||||||
// StpUtil.checkLogin();
|
|
||||||
// //续签
|
|
||||||
// StpUtil.updateLastActiveToNow();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user