|
|
@@ -142,13 +142,32 @@ public class AccessTokenValidatorFilter extends AbstractFilter implements Ordere
|
|
|
// 校验通过,设置上下文
|
|
|
tokenVerify.setContextOne(httpRequest, accessToken, clientId, username);
|
|
|
}
|
|
|
- else if(GrantType.CLIENT_CREDENTIALS.equalsIgnoreCase(grantType)) {
|
|
|
- Map<String, String> outContextMap = new HashMap<>();
|
|
|
- outContextMap.put("uid", "client."+StringFormater.desensitizMobile(clientId));
|
|
|
- LogUtil.setMDC(outContextMap);
|
|
|
- tokenVerify.setContextClientId(clientId);
|
|
|
- tokenVerify.setContextAccessToken(accessToken);
|
|
|
- }
|
|
|
+ else if(GrantType.CLIENT_CREDENTIALS.equalsIgnoreCase(grantType)) {
|
|
|
+ // 【安全修复LD-06】client_credentials 令牌仅限内部服务调用;
|
|
|
+ // 经网关转发进来的外部请求禁止使用服务令牌访问业务接口
|
|
|
+ String fromGateway = httpRequest.getHeader(ParameterKey.HEADER_GATEWAY);
|
|
|
+ if(StringUtil.isNotBlank(fromGateway) && SecrectUtil.getGatewaySecretValue().equals(fromGateway)) {
|
|
|
+ String clientIp = RequestUtil.getIpAddr(httpRequest);
|
|
|
+ logApiInvoke(uri, clientId, clientId, clientIp, StringPool.N, "client_credentials token is not allowed from gateway");
|
|
|
+ logger.error("client_credentials token is not allowed from gateway:{}", uri);
|
|
|
+
|
|
|
+ APIResult<Void> result = new APIResult<>();
|
|
|
+ result.setState(StateEnum.NO_PERMISSION.getCode());
|
|
|
+ result.setCause(StateEnum.NO_PERMISSION.getText());
|
|
|
+
|
|
|
+ httpResponse.setStatus(403);
|
|
|
+ httpResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
|
+ httpResponse.getWriter().print(result.toString());
|
|
|
+ httpResponse.getWriter().flush();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> outContextMap = new HashMap<>();
|
|
|
+ outContextMap.put("uid", "client."+StringFormater.desensitizMobile(clientId));
|
|
|
+ LogUtil.setMDC(outContextMap);
|
|
|
+ tokenVerify.setContextClientId(clientId);
|
|
|
+ tokenVerify.setContextAccessToken(accessToken);
|
|
|
+ }
|
|
|
else {
|
|
|
logger.warn("This grant type {} has not user info.");
|
|
|
}
|