1、修复小程序手机号登录问题
2、调整OA
This commit is contained in:
+1
-1
@@ -169,7 +169,7 @@ public class UserController {
|
|||||||
@Operation(summary = "同步OA人员")
|
@Operation(summary = "同步OA人员")
|
||||||
public R<OaPersonSyncPageVO> syncIamAccounts(
|
public R<OaPersonSyncPageVO> syncIamAccounts(
|
||||||
@RequestParam(defaultValue = "1") Integer current,
|
@RequestParam(defaultValue = "1") Integer current,
|
||||||
@RequestParam(defaultValue = "50") Integer size) {
|
@RequestParam(defaultValue = "20") Integer size) {
|
||||||
return R.data(oaSyncService.syncPersonFromUserList(current, size));
|
return R.data(oaSyncService.syncPersonFromUserList(current, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -266,7 +266,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
*/
|
*/
|
||||||
private OaPersonSyncPageVO syncPersonFromOaPage(int current, int size) {
|
private OaPersonSyncPageVO syncPersonFromOaPage(int current, int size) {
|
||||||
int pageNo = current < 1 ? 1 : current;
|
int pageNo = current < 1 ? 1 : current;
|
||||||
int pageSize = size < 1 ? 50 : Math.min(size, 200);
|
int pageSize = size < 1 ? 20 : Math.min(size, 200);
|
||||||
OAPersonSearch personSearch = buildPersonSearch(null);
|
OAPersonSearch personSearch = buildPersonSearch(null);
|
||||||
personSearch.setCurPage(pageNo);
|
personSearch.setCurPage(pageNo);
|
||||||
personSearch.setPageSize(pageSize);
|
personSearch.setPageSize(pageSize);
|
||||||
@@ -309,7 +309,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
private OAPersonSearch buildPersonSearch(Date startTime) {
|
private OAPersonSearch buildPersonSearch(Date startTime) {
|
||||||
OAPersonSearch personSearch = new OAPersonSearch();
|
OAPersonSearch personSearch = new OAPersonSearch();
|
||||||
personSearch.setCurPage(1);
|
personSearch.setCurPage(1);
|
||||||
personSearch.setPageSize(200);
|
personSearch.setPageSize(20);
|
||||||
personSearch.setCreated("");
|
personSearch.setCreated("");
|
||||||
personSearch.setWorkcode("");
|
personSearch.setWorkcode("");
|
||||||
personSearch.setSubcompanyid1("");
|
personSearch.setSubcompanyid1("");
|
||||||
|
|||||||
+22
-1
@@ -1,24 +1,45 @@
|
|||||||
package org.springblade.thirdparty.oa.config;
|
package org.springblade.thirdparty.oa.config;
|
||||||
|
|
||||||
|
import feign.Logger;
|
||||||
import feign.Request;
|
import feign.Request;
|
||||||
import org.springblade.thirdparty.oa.interceptor.OARequestInterceptor;
|
import org.springblade.thirdparty.oa.interceptor.OARequestInterceptor;
|
||||||
|
import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OA Feign 客户端配置
|
* OA Feign 客户端配置。
|
||||||
|
* <p>
|
||||||
|
* 必须关闭父上下文继承,否则全局 {@code BladeFeignRequestInterceptor}
|
||||||
|
* 会把当前登录请求的 Host、Content-Length、Blade-Auth 等头再次写入,
|
||||||
|
* 导致 gwzh nginx 返回 400。
|
||||||
*
|
*
|
||||||
* @author bfhuange
|
* @author bfhuange
|
||||||
* @since 2024/12/18
|
* @since 2024/12/18
|
||||||
*/
|
*/
|
||||||
public class OAFeignClientConfig {
|
public class OAFeignClientConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FeignClientConfigurer feignClientConfigurer() {
|
||||||
|
return new FeignClientConfigurer() {
|
||||||
|
@Override
|
||||||
|
public boolean inheritParentConfiguration() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public OARequestInterceptor requestInterceptor(OAProperties oaProperties) {
|
public OARequestInterceptor requestInterceptor(OAProperties oaProperties) {
|
||||||
return new OARequestInterceptor(oaProperties);
|
return new OARequestInterceptor(oaProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Logger.Level feignLoggerLevel() {
|
||||||
|
return Logger.Level.FULL;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Request.Options options() {
|
public Request.Options options() {
|
||||||
return new Request.Options(10, TimeUnit.SECONDS, 120, TimeUnit.SECONDS, true);
|
return new Request.Options(10, TimeUnit.SECONDS, 120, TimeUnit.SECONDS, true);
|
||||||
|
|||||||
+38
-35
@@ -34,16 +34,21 @@ import org.springblade.thirdparty.oa.config.OAProperties;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OA Feign 请求拦截器。
|
* OA Feign 请求拦截器。
|
||||||
* <p>
|
* <p>
|
||||||
* 对齐可用 curl:仅发送 Authorization + Content-Type,并清掉登录请求透传头,
|
* 对齐可用 curl:仅发送 Authorization + Content-Type。
|
||||||
* 避免 nginx 因 Host/Content-Length/Blade-Auth 等返回 400。
|
* 配合 {@code FeignClientConfigurer#inheritParentConfiguration()=false},
|
||||||
|
* 避免全局 BladeFeignRequestInterceptor 透传登录请求头。
|
||||||
*
|
*
|
||||||
* @author Chill
|
* @author Chill
|
||||||
*/
|
*/
|
||||||
@@ -53,38 +58,16 @@ public class OARequestInterceptor implements RequestInterceptor {
|
|||||||
|
|
||||||
private static final String BASIC_PREFIX = "Basic ";
|
private static final String BASIC_PREFIX = "Basic ";
|
||||||
private static final String BEARER_PREFIX = "Bearer ";
|
private static final String BEARER_PREFIX = "Bearer ";
|
||||||
private static final Set<String> STRIP_HEADERS = Set.of(
|
private static final Set<String> KEEP_HEADERS = Set.of(
|
||||||
HttpHeaders.HOST.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.CONTENT_LENGTH.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.ACCEPT.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.CONNECTION.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.TRANSFER_ENCODING.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.COOKIE.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.AUTHORIZATION.toLowerCase(Locale.ROOT),
|
HttpHeaders.AUTHORIZATION.toLowerCase(Locale.ROOT),
|
||||||
HttpHeaders.ACCEPT_ENCODING.toLowerCase(Locale.ROOT),
|
HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ROOT)
|
||||||
HttpHeaders.ORIGIN.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.REFERER.toLowerCase(Locale.ROOT),
|
|
||||||
HttpHeaders.EXPECT.toLowerCase(Locale.ROOT),
|
|
||||||
"keep-alive",
|
|
||||||
"upgrade",
|
|
||||||
"te",
|
|
||||||
"trailer",
|
|
||||||
"forwarded",
|
|
||||||
"x-real-ip",
|
|
||||||
"x-request-id",
|
|
||||||
"blade-auth",
|
|
||||||
"blade-requested-with",
|
|
||||||
"tenant-id",
|
|
||||||
"auth"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private final OAProperties oaProperties;
|
private final OAProperties oaProperties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(RequestTemplate template) {
|
public void apply(RequestTemplate template) {
|
||||||
stripForwardedHeaders(template);
|
stripUnwantedHeaders(template);
|
||||||
// 与可用 curl 保持一致:Authorization + Content-Type
|
|
||||||
template.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
template.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
|
||||||
String authorization = normalizeAuthorization(oaProperties.getAuthorization());
|
String authorization = normalizeAuthorization(oaProperties.getAuthorization());
|
||||||
@@ -93,17 +76,37 @@ public class OARequestInterceptor implements RequestInterceptor {
|
|||||||
} else {
|
} else {
|
||||||
log.warn("OA Feign 未配置 third-party.oa.authorization,gwzh 网关可能拒绝请求");
|
log.warn("OA Feign 未配置 third-party.oa.authorization,gwzh 网关可能拒绝请求");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logRequest(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stripForwardedHeaders(RequestTemplate template) {
|
/**
|
||||||
List<String> headerNames = new ArrayList<>(template.headers().keySet());
|
* 打印 OA Feign 最终发出的请求头与 body,便于对照 curl。
|
||||||
|
*/
|
||||||
|
private void logRequest(RequestTemplate template) {
|
||||||
|
String bodyText = "";
|
||||||
|
byte[] body = template.body();
|
||||||
|
if (body != null && body.length > 0) {
|
||||||
|
Charset charset = template.requestCharset() == null ? StandardCharsets.UTF_8 : template.requestCharset();
|
||||||
|
bodyText = new String(body, charset);
|
||||||
|
}
|
||||||
|
log.info("OA Feign 请求 method={}, url={}{}{}, headers={}, body={}",
|
||||||
|
template.method(),
|
||||||
|
template.feignTarget() == null ? "" : template.feignTarget().url(),
|
||||||
|
template.path(),
|
||||||
|
template.queryLine() == null ? "" : template.queryLine(),
|
||||||
|
template.headers(),
|
||||||
|
bodyText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只保留 Authorization / Content-Type,其余全部移除。
|
||||||
|
*/
|
||||||
|
private void stripUnwantedHeaders(RequestTemplate template) {
|
||||||
|
Map<String, Collection<String>> headers = template.headers();
|
||||||
|
List<String> headerNames = new ArrayList<>(headers.keySet());
|
||||||
for (String headerName : headerNames) {
|
for (String headerName : headerNames) {
|
||||||
String lowerName = headerName.toLowerCase(Locale.ROOT);
|
if (!KEEP_HEADERS.contains(headerName.toLowerCase(Locale.ROOT))) {
|
||||||
if (STRIP_HEADERS.contains(lowerName)
|
|
||||||
|| lowerName.startsWith("x-forwarded-")
|
|
||||||
|| lowerName.startsWith("blade-")
|
|
||||||
|| lowerName.startsWith("x-b3-")
|
|
||||||
|| lowerName.startsWith("sw8")) {
|
|
||||||
template.removeHeader(headerName);
|
template.removeHeader(headerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user