mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-18 02:56:30 +08:00
commit:添加多对多关联中间表更新支持,功能位于 班级管理 -> 课程 -> 编辑课程顺序
This commit is contained in:
@@ -17,8 +17,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
/**
|
||||
* 网关服务启动类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||
@SpringCloudApplication
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
/**
|
||||
* 网关业务配置类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@RefreshScope
|
||||
|
||||
@@ -11,8 +11,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||
/**
|
||||
* 跨域信任配置类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.nio.charset.StandardCharsets;
|
||||
/**
|
||||
* Web通用过滤器配置类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
public class FilterConfig {
|
||||
|
||||
@@ -16,8 +16,8 @@ import java.util.*;
|
||||
/**
|
||||
* Spring Cloud Gateway的Sentinel流控配置类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
public class SentinelConfig {
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.orange.demo.gateway.constant;
|
||||
/**
|
||||
* 网关业务相关的常量对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public final class GatewayConstant {
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ import java.util.Map;
|
||||
/**
|
||||
* 全局后处理过滤器。主要用于将用户的会话信息存到缓存服务器,以及在登出时清除缓存中的会话数据。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class AuthenticationPostFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@@ -37,8 +37,8 @@ import java.util.Map;
|
||||
/**
|
||||
* 全局前处理过滤器。主要用于用户操作权限验证。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class AuthenticationPreFilter implements GlobalFilter, Ordered {
|
||||
@@ -60,7 +60,6 @@ public class AuthenticationPreFilter implements GlobalFilter, Ordered {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
String url = request.getURI().getPath();
|
||||
// 登录请求,直接转发给login验证服务器。
|
||||
// NOTE: 所有不需要登录验证的url,都可以添加在下面。
|
||||
if (url.equals(GatewayConstant.ADMIN_LOGIN_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
@@ -70,9 +69,8 @@ public class AuthenticationPreFilter implements GlobalFilter, Ordered {
|
||||
log.warn("EXPIRED request [{}] from REMOTE-IP [{}].", url, IpUtil.getRemoteIpAddress(request));
|
||||
response.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
byte[] responseBody = JSON.toJSONString(
|
||||
ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户登录已过期,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] responseBody = JSON.toJSONString(ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户登录已过期,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
return response.writeWith(Flux.just(response.bufferFactory().wrap(responseBody)));
|
||||
}
|
||||
// 这里判断是否需要定时刷新token
|
||||
@@ -85,25 +83,22 @@ public class AuthenticationPreFilter implements GlobalFilter, Ordered {
|
||||
String sessionId = (String) c.get(GatewayConstant.SESSION_ID_KEY_NAME);
|
||||
Map<String, String> userMap = jedis.hgetAll(RedisKeyUtil.makeSessionIdKeyForRedis(sessionId));
|
||||
if (userMap == null) {
|
||||
log.warn("UNAUTHORIZED request [{}] from REMOTE-IP [{}] because no sessionId exists in redis."
|
||||
, url, IpUtil.getRemoteIpAddress(request));
|
||||
log.warn("UNAUTHORIZED request [{}] from REMOTE-IP [{}] because no sessionId exists in redis.",
|
||||
url, IpUtil.getRemoteIpAddress(request));
|
||||
response.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
byte[] responseBody = JSON.toJSONString(
|
||||
ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户会话已失效,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] responseBody = JSON.toJSONString(ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户会话已失效,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
return response.writeWith(Flux.just(response.bufferFactory().wrap(responseBody)));
|
||||
}
|
||||
|
||||
String userId = userMap.get("userId");
|
||||
if (StringUtils.isBlank(userId)) {
|
||||
log.warn("UNAUTHORIZED request [{}] from REMOTE-IP [{}] because userId is empty in redis."
|
||||
, url, IpUtil.getRemoteIpAddress(request));
|
||||
log.warn("UNAUTHORIZED request [{}] from REMOTE-IP [{}] because userId is empty in redis.",
|
||||
url, IpUtil.getRemoteIpAddress(request));
|
||||
response.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
byte[] responseBody = JSON.toJSONString(
|
||||
ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户登录验证信息已过期,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] responseBody = JSON.toJSONString(ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN,
|
||||
"用户登录验证信息已过期,请重新登录!")).getBytes(StandardCharsets.UTF_8);
|
||||
return response.writeWith(Flux.just(response.bufferFactory().wrap(responseBody)));
|
||||
}
|
||||
boolean isAdmin = false;
|
||||
@@ -119,16 +114,13 @@ public class AuthenticationPreFilter implements GlobalFilter, Ordered {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("Failed to call AuthenticationPreFilter.filter.", e);
|
||||
}
|
||||
// 对于isAdmin == false的用户,继续查找权限资源信息是否存在
|
||||
if (Boolean.FALSE.equals(isAdmin)
|
||||
&& !this.hasPermission(jedis, sessionId, url)) {
|
||||
log.warn("FORBIDDEN request [{}] from REMOTE-IP [{}] for USER [{} -- {}] no perm!"
|
||||
, url, IpUtil.getRemoteIpAddress(request), userId, showName);
|
||||
if (Boolean.FALSE.equals(isAdmin) && !this.hasPermission(jedis, sessionId, url)) {
|
||||
log.warn("FORBIDDEN request [{}] from REMOTE-IP [{}] for USER [{} -- {}] no perm!",
|
||||
url, IpUtil.getRemoteIpAddress(request), userId, showName);
|
||||
response.setStatusCode(HttpStatus.FORBIDDEN);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
byte[] responseBody = JSON.toJSONString(
|
||||
ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION,
|
||||
"用户对该URL没有访问权限,请核对!")).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] responseBody = JSON.toJSONString(ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION,
|
||||
"用户对该URL没有访问权限,请核对!")).getBytes(StandardCharsets.UTF_8);
|
||||
return response.writeWith(Flux.just(response.bufferFactory().wrap(responseBody)));
|
||||
}
|
||||
// 将session中关联的用户信息,添加到当前的Request中。转发后,业务服务可以根据需要自定读取。
|
||||
|
||||
@@ -16,8 +16,8 @@ import reactor.core.publisher.Mono;
|
||||
* 链路日志前置过虑器。
|
||||
* 为整个链路生成唯一的traceId,并存储在Request Head中。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class RequestLogFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@@ -15,8 +15,8 @@ import reactor.core.publisher.Mono;
|
||||
* 链路日志后置过虑器。
|
||||
* 将整个链路的traceId存储在Response Head中,并返回给前端,便于问题定位。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class ResponseLogFilter implements GlobalFilter, Ordered {
|
||||
|
||||
Reference in New Issue
Block a user