init:删除无用配置
This commit is contained in:
@@ -57,8 +57,7 @@ public class GlobalExceptionHandler {
|
|||||||
*/
|
*/
|
||||||
@ExceptionHandler(value = NotLoginException.class)
|
@ExceptionHandler(value = NotLoginException.class)
|
||||||
public ResponseEntity<ApiError> notLoginException(Exception e) {
|
public ResponseEntity<ApiError> notLoginException(Exception e) {
|
||||||
// log.error(ThrowableUtil.getStackTrace(e));
|
log.error(ThrowableUtil.getStackTrace(e));
|
||||||
log.error("token超时:-------------------------------------" + e.getMessage());
|
|
||||||
return buildResponseEntity(ApiError.error(401, "token 失效"));
|
return buildResponseEntity(ApiError.error(401, "token 失效"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,19 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.nl.common.domain.aspect;
|
package org.nl.common.logging.aspect;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import io.netty.util.internal.ThrowableUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.nl.common.utils.*;
|
import org.nl.common.utils.IPUtil;
|
||||||
|
import org.nl.common.utils.IdUtil;
|
||||||
|
import org.nl.common.utils.RequestHolder;
|
||||||
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.config.lucene.LuceneAppender;
|
import org.nl.config.lucene.LuceneAppender;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -58,6 +59,7 @@ public class LogAspect {
|
|||||||
*/
|
*/
|
||||||
@Around("@annotation(logInfo)")
|
@Around("@annotation(logInfo)")
|
||||||
public Object logAround(ProceedingJoinPoint joinPoint,org.nl.common.logging.annotation.Log logInfo) throws Throwable {
|
public Object logAround(ProceedingJoinPoint joinPoint,org.nl.common.logging.annotation.Log logInfo) throws Throwable {
|
||||||
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
String params = getParameter(method, joinPoint.getArgs());
|
String params = getParameter(method, joinPoint.getArgs());
|
||||||
@@ -72,6 +74,11 @@ public class LogAspect {
|
|||||||
try {
|
try {
|
||||||
log.info("[--request--][请求接口:{}][请求参数:{}]",url,params);
|
log.info("[--request--][请求接口:{}][请求参数:{}]",url,params);
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
|
// //是否把日志存到日志表
|
||||||
|
// if (logInfo.isAddLogTable()) {
|
||||||
|
// Log log = new Log("INFO", System.currentTimeMillis() - comming);
|
||||||
|
// logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||||
|
// }
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
|
|
||||||
StringBuffer errorStack = new StringBuffer();
|
StringBuffer errorStack = new StringBuffer();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package org.nl.common.utils;
|
|||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.json.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import cn.hutool.json.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.common.utils.dto.CurrentUser;
|
import org.nl.common.utils.dto.CurrentUser;
|
||||||
|
|
||||||
@@ -24,14 +24,22 @@ public class SecurityUtils {
|
|||||||
*/
|
*/
|
||||||
public static CurrentUser getCurrentUser() {
|
public static CurrentUser getCurrentUser() {
|
||||||
try {
|
try {
|
||||||
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo");
|
Object loginInfo = StpUtil.getExtra("loginInfo");
|
||||||
if (ObjectUtil.isNotEmpty(json)) {
|
if (loginInfo==null){
|
||||||
return json.toBean(CurrentUser.class);
|
CurrentUser currentUser = new CurrentUser();
|
||||||
|
currentUser.setId("2");
|
||||||
|
currentUser.setPresonName("外部系统用户");
|
||||||
|
currentUser.setUsername("admin");
|
||||||
|
return currentUser;
|
||||||
}
|
}
|
||||||
|
return JSONObject.parseObject(String.valueOf(loginInfo),CurrentUser.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return CurrentUser.getDefaultUser();
|
CurrentUser currentUser = new CurrentUser();
|
||||||
|
currentUser.setId("2");
|
||||||
|
currentUser.setPresonName("外部系统用户");
|
||||||
|
currentUser.setUsername("admin");
|
||||||
|
return currentUser;
|
||||||
}
|
}
|
||||||
return CurrentUser.getDefaultUser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +57,11 @@ public class SecurityUtils {
|
|||||||
* @return 系统用户名称
|
* @return 系统用户名称
|
||||||
*/
|
*/
|
||||||
public static String getCurrentNickName() {
|
public static String getCurrentNickName() {
|
||||||
return getCurrentUser().getPresonName();
|
CurrentUser user = getCurrentUser();
|
||||||
|
if (user!=null){
|
||||||
|
return user.getPresonName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,11 +74,12 @@ public class SecurityUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统用户Id
|
* 获取系统用户部门Id
|
||||||
*
|
* @return 用户部门现在1:n,该方法禁用
|
||||||
* @return 系统用户Id
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static Long getDeptId() {
|
public static Long getDeptId() {
|
||||||
|
// return getCurrentUser().getUser().getDept().getId();
|
||||||
return 1L;
|
return 1L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +89,10 @@ public class SecurityUtils {
|
|||||||
* @return 权限列表
|
* @return 权限列表
|
||||||
*/
|
*/
|
||||||
public static List<String> getCurrentUserPermissions() {
|
public static List<String> getCurrentUserPermissions() {
|
||||||
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo");
|
JSONObject json =JSONObject.parseObject(String.valueOf(StpUtil.getExtra("loginInfo")));
|
||||||
JSONArray permissions = json.getJSONArray("permissions");
|
JSONArray permissions = json.getJSONArray("permissions");
|
||||||
if (permissions.size() > 0) {
|
if (permissions.size() > 0) {
|
||||||
return permissions.toList(String.class);
|
return permissions.toJavaList(String.class);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
|
|||||||
public CorsFilter corsFilter() {
|
public CorsFilter corsFilter() {
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
config.setAllowCredentials(true);
|
config.setAllowCredentials(false);
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
config.addAllowedHeader("*");
|
config.addAllowedHeader("*");
|
||||||
config.addAllowedMethod("*");
|
config.addAllowedMethod("*");
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
||||||
|
//
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns(excludes); // 白名单
|
.excludePathPatterns(excludes); // 白名单
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.wf.captcha.base.Captcha;
|
|||||||
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.common.logging.annotation.Log;
|
||||||
import org.nl.common.utils.RedisUtils;
|
import org.nl.common.utils.RedisUtils;
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.common.utils.dto.CurrentUser;
|
import org.nl.common.utils.dto.CurrentUser;
|
||||||
@@ -45,6 +46,7 @@ public class AuthorizationController {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
|
@Log
|
||||||
public ResponseEntity<Object> login(@RequestBody JSONObject authMap, HttpServletRequest request) throws Exception {
|
public ResponseEntity<Object> login(@RequestBody JSONObject authMap, HttpServletRequest request) throws Exception {
|
||||||
if (ObjectUtil.isEmpty(authMap)){
|
if (ObjectUtil.isEmpty(authMap)){
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ const user = {
|
|||||||
actions: {
|
actions: {
|
||||||
// 登录
|
// 登录
|
||||||
Login({ commit }, userInfo) {
|
Login({ commit }, userInfo) {
|
||||||
// const rememberMe = userInfo.rememberMe
|
const rememberMe = userInfo.rememberMe
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login(userInfo.username, userInfo.password, userInfo.code, userInfo.uuid).then(res => {
|
login(userInfo.username, userInfo.password, userInfo.code, userInfo.uuid).then(res => {
|
||||||
// setToken(res.token, rememberMe)
|
setToken(res.token, rememberMe)
|
||||||
commit('SET_TOKEN', res.token)
|
commit('SET_TOKEN', res.token)
|
||||||
setUserInfo(res.user, commit)
|
setUserInfo(res.user, commit)
|
||||||
// 第一次加载菜单时用到, 具体见 src 目录下的 permission.js
|
// 第一次加载菜单时用到, 具体见 src 目录下的 permission.js
|
||||||
@@ -82,7 +82,6 @@ export const logOut = (commit) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const setUserInfo = (res, commit) => {
|
export const setUserInfo = (res, commit) => {
|
||||||
console.log(res)
|
|
||||||
// 如果没有任何权限,则赋予一个默认的权限,避免请求死循环
|
// 如果没有任何权限,则赋予一个默认的权限,避免请求死循环
|
||||||
if (res.roles && res.roles.length > 0) {
|
if (res.roles && res.roles.length > 0) {
|
||||||
commit('SET_ROLES', res.roles)
|
commit('SET_ROLES', res.roles)
|
||||||
|
|||||||
Reference in New Issue
Block a user