ai引入
This commit is contained in:
parent
e907e6003a
commit
1c936afe4c
|
|
@ -0,0 +1,36 @@
|
||||||
|
//package cn.qihangerp.erp.config;
|
||||||
|
//
|
||||||
|
//import cn.qihangerp.erp.filter.UrlTokenFilter;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.context.annotation.Bean;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
//import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
|
//import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * Spring Security配置
|
||||||
|
// *
|
||||||
|
// * @author qihang
|
||||||
|
// */
|
||||||
|
//@Configuration
|
||||||
|
//@EnableWebSecurity
|
||||||
|
//public class SecurityConfig {
|
||||||
|
// @Autowired
|
||||||
|
// private UrlTokenFilter urlTokenFilter;
|
||||||
|
//
|
||||||
|
// @Bean
|
||||||
|
// public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
// http
|
||||||
|
// .csrf(AbstractHttpConfigurer::disable)
|
||||||
|
// .authorizeRequests(authorizeRequests ->
|
||||||
|
// authorizeRequests
|
||||||
|
// .anyRequest().permitAll()
|
||||||
|
// )
|
||||||
|
// .addFilterBefore(urlTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
//
|
||||||
|
// return http.build();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
//package cn.qihangerp.erp.filter;
|
||||||
|
//
|
||||||
|
//import cn.qihangerp.common.AjaxResult;
|
||||||
|
//import cn.qihangerp.common.enums.HttpStatus;
|
||||||
|
//import cn.qihangerp.security.LoginUser;
|
||||||
|
//import cn.qihangerp.security.TokenService;
|
||||||
|
//import com.alibaba.fastjson2.JSON;
|
||||||
|
//import jakarta.servlet.FilterChain;
|
||||||
|
//import jakarta.servlet.ServletException;
|
||||||
|
//import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
//import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||||
|
//import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
//import org.slf4j.Logger;
|
||||||
|
//import org.slf4j.LoggerFactory;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.http.MediaType;
|
||||||
|
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
//import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
//
|
||||||
|
//import java.io.IOException;
|
||||||
|
//import java.io.PrintWriter;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * token过滤器 从URL参数中获取token并验证有效性
|
||||||
|
// *
|
||||||
|
// * @author qihang
|
||||||
|
// */
|
||||||
|
//@Component
|
||||||
|
//public class UrlTokenFilter extends OncePerRequestFilter {
|
||||||
|
// @Autowired
|
||||||
|
// private TokenService tokenService;
|
||||||
|
// private Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||||
|
// throws ServletException, IOException {
|
||||||
|
// // 从URL参数中获取token
|
||||||
|
// String token = request.getParameter("token");
|
||||||
|
// String url = request.getRequestURI();
|
||||||
|
//
|
||||||
|
// // 跳过登录等不需要token的请求
|
||||||
|
// if (url.contains("/login") || url.contains("/captchaImage")) {
|
||||||
|
// chain.doFilter(request, response);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 如果URL参数中没有token,尝试从header中获取(保持兼容性)
|
||||||
|
// if (token == null || token.isEmpty()) {
|
||||||
|
// token = request.getHeader("Authorization");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 验证token
|
||||||
|
// if (token != null && !token.isEmpty()) {
|
||||||
|
// // 移除Bearer前缀
|
||||||
|
// if (token.startsWith("Bearer ")) {
|
||||||
|
// token = token.substring(7);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 将token声明为final,以便内部类可以引用
|
||||||
|
// final String finalToken = token;
|
||||||
|
//
|
||||||
|
// // 将token设置到请求的header中,以便TokenService能够正常工作
|
||||||
|
// final HttpServletRequest modifiedRequest = new HttpServletRequestWrapper(request) {
|
||||||
|
// @Override
|
||||||
|
// public String getHeader(String name) {
|
||||||
|
// if ("Authorization".equals(name)) {
|
||||||
|
// return "Bearer " + finalToken;
|
||||||
|
// }
|
||||||
|
// return super.getHeader(name);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// // 验证token并设置用户信息
|
||||||
|
// try {
|
||||||
|
// LoginUser loginUser = tokenService.getLoginUser(modifiedRequest);
|
||||||
|
// if (loginUser != null) {
|
||||||
|
// tokenService.verifyToken(loginUser);
|
||||||
|
// UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
||||||
|
// authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(modifiedRequest));
|
||||||
|
// SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
||||||
|
// chain.doFilter(modifiedRequest, response);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// log.error("Token validation failed: {}", e.getMessage());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // token无效或不存在
|
||||||
|
// fallback("授权过期!", response);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private void fallback(String message, HttpServletResponse response) {
|
||||||
|
// response.setCharacterEncoding("UTF-8");
|
||||||
|
// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
// PrintWriter writer = null;
|
||||||
|
// try {
|
||||||
|
// if (message == null) {
|
||||||
|
// message = "401 Forbidden";
|
||||||
|
// }
|
||||||
|
// AjaxResult res = AjaxResult.error(HttpStatus.UNAUTHORIZED, message);
|
||||||
|
// writer = response.getWriter();
|
||||||
|
// writer.append(JSON.toJSONString(res));
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// log.error(e.getMessage());
|
||||||
|
// } finally {
|
||||||
|
// if (writer != null) {
|
||||||
|
// writer.close();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
@ -23,6 +23,9 @@ public class TokenFilter implements GlobalFilter, Ordered {
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
String token = exchange.getRequest().getHeaders().getFirst(TOKEN_HEADER);
|
String token = exchange.getRequest().getHeaders().getFirst(TOKEN_HEADER);
|
||||||
|
if(StringUtils.isEmpty(token)){
|
||||||
|
token=exchange.getRequest().getQueryParams().getFirst("token");
|
||||||
|
}
|
||||||
System.out.println("Token:"+token);
|
System.out.println("Token:"+token);
|
||||||
String url = exchange.getRequest().getURI().getPath();
|
String url = exchange.getRequest().getURI().getPath();
|
||||||
System.out.println("intercept " + url);
|
System.out.println("intercept " + url);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -43,7 +44,10 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
// String token = exchange.getRequest().getHeaders().getFirst(TOKEN_HEADER);
|
// String token = exchange.getRequest().getHeaders().getFirst(TOKEN_HEADER);
|
||||||
String token = request.getHeader("Authorization");
|
// String token = request.getHeader("Authorization");
|
||||||
|
// if(StringUtils.isEmpty(token)){
|
||||||
|
// token = request.getParameter("token");
|
||||||
|
// }
|
||||||
String url = request.getRequestURI();
|
String url = request.getRequestURI();
|
||||||
// log.info("intercept " + url);
|
// log.info("intercept " + url);
|
||||||
// log.info("token: " + token); || request.getRequestURI().equals("/getInfo") || request.getRequestURI().equals("/logout")
|
// log.info("token: " + token); || request.getRequestURI().equals("/getInfo") || request.getRequestURI().equals("/logout")
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,9 @@ public class TokenService
|
||||||
private String getToken(HttpServletRequest request)
|
private String getToken(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String token = request.getHeader("Authorization");
|
String token = request.getHeader("Authorization");
|
||||||
|
if(org.springframework.util.StringUtils.isEmpty(token)){
|
||||||
|
token = request.getParameter("token");
|
||||||
|
}
|
||||||
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
|
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
|
||||||
{
|
{
|
||||||
token = token.replace(Constants.TOKEN_PREFIX, "");
|
token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1752030896826" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8333" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M934.4 288c0-16-16-28.8-32-28.8h-137.6c-25.6-108.8-124.8-188.8-240-188.8h-19.2c-115.2 0-214.4 80-240 188.8H128C108.8 256 96 268.8 96 288l-28.8 553.6v3.2C73.6 912 128 960 192 960h649.6c64 0 118.4-51.2 121.6-115.2v-3.2L934.4 288z m-96 608H192c-28.8 0-54.4-22.4-57.6-54.4L156.8 320h102.4v134.4c-19.2 9.6-32 32-32 54.4 0 35.2 28.8 64 64 64s64-28.8 64-64c0-22.4-12.8-44.8-32-54.4V313.6c0-102.4 83.2-182.4 182.4-182.4h19.2c102.4 0 182.4 83.2 182.4 182.4v144c-19.2 9.6-32 32-32 54.4 0 35.2 28.8 64 64 64s64-28.8 64-64c0-22.4-12.8-44.8-32-54.4V320h99.2l25.6 521.6c0 32-25.6 54.4-57.6 54.4z" fill="#666666" p-id="8334"></path><path d="M611.2 256h-192c-19.2 0-32 12.8-32 32s12.8 32 32 32h192c19.2 0 32-12.8 32-32s-12.8-32-32-32z" fill="#666666" p-id="8335"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
|
|
@ -34,7 +34,10 @@ module.exports = {
|
||||||
* 是否显示动态标题
|
* 是否显示动态标题
|
||||||
*/
|
*/
|
||||||
dynamicTitle: false,
|
dynamicTitle: false,
|
||||||
|
/**
|
||||||
|
* 侧边栏默认状态 true:展开 false:收起
|
||||||
|
*/
|
||||||
|
sidebarDefaultOpen: false,
|
||||||
/**
|
/**
|
||||||
* @type {string | array} 'production' | ['production', 'development']
|
* @type {string | array} 'production' | ['production', 'development']
|
||||||
* @description Need show err logs component.
|
* @description Need show err logs component.
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
|
import defaultSettings from '@/settings'
|
||||||
const state = {
|
const state = {
|
||||||
sidebar: {
|
sidebar: {
|
||||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : defaultSettings.sidebarDefaultOpen,
|
||||||
withoutAnimation: false,
|
withoutAnimation: false,
|
||||||
hide: false
|
hide: false
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue