This commit is contained in:
zlt
2019-08-28 10:53:49 +08:00
parent 9dffed648a
commit f69f574f13
5 changed files with 64 additions and 39 deletions
@@ -28,47 +28,49 @@ public class FeignInterceptorConfig {
RequestInterceptor requestInterceptor = template -> { RequestInterceptor requestInterceptor = template -> {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes(); .getRequestAttributes();
HttpServletRequest request = attributes.getRequest(); if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
//传递access_token,无网络隔离时需要传递 //传递access_token,无网络隔离时需要传递
/* /*
String token = extractHeaderToken(request); String token = extractHeaderToken(request);
if (StrUtil.isEmpty(token)) { if (StrUtil.isEmpty(token)) {
token = request.getParameter(CommonConstant.ACCESS_TOKEN); token = request.getParameter(CommonConstant.ACCESS_TOKEN);
} }
if (StrUtil.isNotEmpty(token)) { if (StrUtil.isNotEmpty(token)) {
template.header(CommonConstant.TOKEN_HEADER, CommonConstant.BEARER_TYPE + " " + token); template.header(CommonConstant.TOKEN_HEADER, CommonConstant.BEARER_TYPE + " " + token);
} }
*/ */
//传递userid //传递userid
String userid = request.getHeader(SecurityConstants.USER_ID_HEADER); String userid = request.getHeader(SecurityConstants.USER_ID_HEADER);
if (StrUtil.isNotEmpty(userid)) { if (StrUtil.isNotEmpty(userid)) {
template.header(SecurityConstants.USER_ID_HEADER, userid); template.header(SecurityConstants.USER_ID_HEADER, userid);
} }
//传递username //传递username
String username = request.getHeader(SecurityConstants.USER_HEADER); String username = request.getHeader(SecurityConstants.USER_HEADER);
if (StrUtil.isNotEmpty(username)) { if (StrUtil.isNotEmpty(username)) {
template.header(SecurityConstants.USER_HEADER, username); template.header(SecurityConstants.USER_HEADER, username);
} }
//传递roles //传递roles
String roles = request.getHeader(SecurityConstants.ROLE_HEADER); String roles = request.getHeader(SecurityConstants.ROLE_HEADER);
if (StrUtil.isNotEmpty(roles)) { if (StrUtil.isNotEmpty(roles)) {
template.header(SecurityConstants.ROLE_HEADER, roles); template.header(SecurityConstants.ROLE_HEADER, roles);
} }
//传递client //传递client
String tenant = TenantContextHolder.getTenant(); String tenant = TenantContextHolder.getTenant();
if (StrUtil.isNotEmpty(tenant)) { if (StrUtil.isNotEmpty(tenant)) {
template.header(SecurityConstants.TENANT_HEADER, tenant); template.header(SecurityConstants.TENANT_HEADER, tenant);
} }
//传递日志traceId //传递日志traceId
String traceId = MDC.get(CommonConstant.LOG_TRACE_ID); String traceId = MDC.get(CommonConstant.LOG_TRACE_ID);
if (StrUtil.isNotEmpty(traceId)) { if (StrUtil.isNotEmpty(traceId)) {
template.header(CommonConstant.TRACE_ID_HEADER, traceId); template.header(CommonConstant.TRACE_ID_HEADER, traceId);
}
} }
}; };
return requestInterceptor; return requestInterceptor;
@@ -1,6 +1,6 @@
########################## 统一变量配置 ########################## ########################## 统一变量配置 ##########################
##### 数据库配置 ##### 数据库配置
zlt.datasource.ip=192.168.28.131 zlt.datasource.ip=192.168.28.130
zlt.datasource.username=root zlt.datasource.username=root
zlt.datasource.password=1q2w3e4r zlt.datasource.password=1q2w3e4r
-1
View File
@@ -202,7 +202,6 @@ INSERT INTO `sys_role_menu` VALUES (3, 2);
INSERT INTO `sys_role_menu` VALUES (3, 3); INSERT INTO `sys_role_menu` VALUES (3, 3);
INSERT INTO `sys_role_menu` VALUES (3, 4); INSERT INTO `sys_role_menu` VALUES (3, 4);
INSERT INTO `sys_role_menu` VALUES (3, 12); INSERT INTO `sys_role_menu` VALUES (3, 12);
INSERT INTO `sys_role_menu` VALUES (3, 12);
INSERT INTO `sys_role_menu` VALUES (4, 80); INSERT INTO `sys_role_menu` VALUES (4, 80);
INSERT INTO `sys_role_menu` VALUES (4, 81); INSERT INTO `sys_role_menu` VALUES (4, 81);
INSERT INTO `sys_role_menu` VALUES (4, 82); INSERT INTO `sys_role_menu` VALUES (4, 82);
@@ -26,6 +26,10 @@ spring:
groupId: DEFAULT_GROUP groupId: DEFAULT_GROUP
rule-type: gw-api-group rule-type: gw-api-group
security:
sessions: ALWAYS
zlt: zlt:
oauth2: oauth2:
token: token:
@@ -35,6 +39,7 @@ zlt:
ignore: ignore:
# 忽略认证的地址 # 忽略认证的地址
httpUrls: > httpUrls: >
/api-user/test,
/api-uaa/oauth/**, /api-uaa/oauth/**,
/api-uaa/validata/**, /api-uaa/validata/**,
/api-uaa/css/**, /api-uaa/css/**,
@@ -61,6 +66,10 @@ zlt:
#白名单 #白名单
includeClientIds: includeClientIds:
- webApp - webApp
gateway:
#网关动态路由
dynamicRoute:
enabled: true
zuul: zuul:
@@ -73,8 +82,6 @@ zuul:
threadPoolKeyPrefix: api-gateway threadPoolKeyPrefix: api-gateway
#关闭重试 #关闭重试
retryable: false retryable: false
#/oauth/token需要请求头处理
sensitive-headers:
ignored-headers: Access-Control-Allow-Credentials,Access-Control-Allow-Origin,Access-Control-Allow-Methods ignored-headers: Access-Control-Allow-Credentials,Access-Control-Allow-Origin,Access-Control-Allow-Methods
add-host-header: true add-host-header: true
routes: routes:
@@ -82,53 +89,67 @@ zuul:
path: /api-uaa/** path: /api-uaa/**
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
auth-login-page: auth-login-page:
path: /login.html path: /login.html
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
auth-login-process: auth-login-process:
path: /user/login path: /user/login
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
auth-login-token: auth-login-token:
path: /oauth/token path: /oauth/token
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
auth-login-authorize: auth-login-authorize:
path: /oauth/authorize path: /oauth/authorize
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
auth-check-process: auth-check-process:
path: /oauth/check_token path: /oauth/check_token
service-id: uaa-server service-id: uaa-server
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
user: user:
path: /api-user/** path: /api-user/**
service-id: user-center service-id: user-center
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
file: file:
path: /api-file/** path: /api-file/**
service-id: file-center service-id: file-center
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
log: log:
path: /api-log/** path: /api-log/**
service-id: log-center service-id: log-center
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
generator: generator:
path: /api-generator/** path: /api-generator/**
service-id: code-generator service-id: code-generator
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
search: search:
path: /api-search/** path: /api-search/**
service-id: search-center service-id: search-center
strip-prefix: true strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true custom-sensitive-headers: true
ssl-hostname-validation-enabled: false ssl-hostname-validation-enabled: false
@@ -84,6 +84,9 @@
layer.load(2); layer.load(2);
$.ajax({ $.ajax({
url: config.base_server + 'api-uaa/oauth/user/token', url: config.base_server + 'api-uaa/oauth/user/token',
xhrFields: {
withCredentials: true
},
data: obj.field, data: obj.field,
type: 'POST', type: 'POST',
beforeSend: function (xhr) { beforeSend: function (xhr) {