feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
package com.central.oauth.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.oauth.model.*;
|
||||
import com.central.oauth.service.ICryptoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* RSA加解密接口控制器
|
||||
*/
|
||||
@Tag(name = "RSA加解密接口")
|
||||
@RestController
|
||||
@RequestMapping("/crypto")
|
||||
@Slf4j
|
||||
public class CryptoController {
|
||||
|
||||
@Autowired
|
||||
private ICryptoService cryptoService;
|
||||
|
||||
/**
|
||||
* 获取RSA公钥
|
||||
* 前端可以调用此接口获取公钥,用于数据加密
|
||||
*/
|
||||
@Operation(summary = "获取RSA公钥", description = "获取用于加密的RSA公钥,前端使用此公钥加密敏感数据")
|
||||
@GetMapping("/public-key")
|
||||
public Result<PublicKeyResponse> getPublicKey() {
|
||||
try {
|
||||
PublicKeyResponse response = cryptoService.getPublicKey();
|
||||
log.info("公钥获取成功");
|
||||
return Result.succeed(response, "公钥获取成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取公钥失败", e);
|
||||
return Result.failed("获取公钥失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RSA加密接口
|
||||
* 使用RSA公钥加密数据
|
||||
*/
|
||||
@Operation(summary = "RSA加密", description = "使用RSA公钥加密数据,返回Base64编码的密文")
|
||||
@PostMapping("/encrypt")
|
||||
public Result<CryptoResponse> encrypt(@Valid @RequestBody CryptoRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
try {
|
||||
// 获取客户端IP
|
||||
String clientIp = getClientIp(httpRequest);
|
||||
|
||||
// 检查请求频率限制
|
||||
if (!cryptoService.checkRateLimit(clientIp)) {
|
||||
log.warn("客户端 {} 请求频率过高", clientIp);
|
||||
return Result.failed("请求过于频繁,请稍后重试");
|
||||
}
|
||||
|
||||
CryptoResponse response = cryptoService.encrypt(request);
|
||||
log.info("数据加密成功,客户端IP: {}", clientIp);
|
||||
return Result.succeed(response, "加密成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("加密失败: {}", e.getMessage(), e);
|
||||
return Result.failed("加密失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RSA解密接口
|
||||
* 使用RSA私钥解密数据(管理员功能,需要权限控制)
|
||||
*/
|
||||
@Operation(summary = "RSA解密", description = "使用RSA私钥解密数据,返回明文(需要管理员权限)")
|
||||
@PostMapping("/decrypt")
|
||||
public Result<DecryptResponse> decrypt(@Valid @RequestBody DecryptRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
try {
|
||||
// 获取客户端IP
|
||||
String clientIp = getClientIp(httpRequest);
|
||||
|
||||
// 检查请求频率限制(解密接口限制更严格)
|
||||
if (!cryptoService.checkRateLimit(clientIp)) {
|
||||
log.warn("客户端 {} 解密请求频率过高", clientIp);
|
||||
return Result.failed("请求过于频繁,请稍后重试");
|
||||
}
|
||||
|
||||
// 记录解密操作日志(安全审计)
|
||||
log.info("解密请求,客户端IP: {}, 时间戳: {}", clientIp, request.getTimestamp());
|
||||
|
||||
DecryptResponse response = cryptoService.decrypt(request);
|
||||
log.info("数据解密成功,客户端IP: {}", clientIp);
|
||||
return Result.succeed(response, "解密成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("解密失败: {}", e.getMessage(), e);
|
||||
return Result.failed("解密失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试加解密流程
|
||||
* 用于验证RSA加解密功能是否正常
|
||||
*/
|
||||
@Operation(summary = "测试加解密", description = "测试RSA加解密流程是否正常工作")
|
||||
@PostMapping("/test")
|
||||
public Result<String> testCrypto(@RequestParam(defaultValue = "hello123") String testData,
|
||||
HttpServletRequest httpRequest) {
|
||||
try {
|
||||
String clientIp = getClientIp(httpRequest);
|
||||
|
||||
// 检查请求频率
|
||||
if (!cryptoService.checkRateLimit(clientIp)) {
|
||||
return Result.failed("请求过于频繁,请稍后重试");
|
||||
}
|
||||
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
// 1. 加密测试
|
||||
CryptoRequest encryptReq = new CryptoRequest();
|
||||
encryptReq.setData(testData);
|
||||
encryptReq.setTimestamp(timestamp);
|
||||
|
||||
CryptoResponse encryptResp = cryptoService.encrypt(encryptReq);
|
||||
|
||||
// 2. 解密测试
|
||||
DecryptRequest decryptReq = new DecryptRequest();
|
||||
decryptReq.setEncryptedData(encryptResp.getEncryptedData());
|
||||
decryptReq.setTimestamp(String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
DecryptResponse decryptResp = cryptoService.decrypt(decryptReq);
|
||||
|
||||
// 3. 验证结果
|
||||
boolean success = testData.equals(decryptResp.getData());
|
||||
String result = String.format("测试%s - 原文: %s, 密文: %s, 解密: %s",
|
||||
success ? "成功" : "失败",
|
||||
testData,
|
||||
encryptResp.getEncryptedData().substring(0, Math.min(20, encryptResp.getEncryptedData().length())) + "...",
|
||||
decryptResp.getData());
|
||||
|
||||
log.info("加解密测试完成,结果: {}, 客户端IP: {}", success, clientIp);
|
||||
return Result.succeed(result, success ? "测试成功" : "测试失败");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试加解密失败", e);
|
||||
return Result.failed("测试失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端真实IP地址
|
||||
*/
|
||||
private String getClientIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
// 处理多级代理的情况
|
||||
if (ip != null && ip.contains(",")) {
|
||||
ip = ip.substring(0, ip.indexOf(",")).trim();
|
||||
}
|
||||
|
||||
return ip != null ? ip : "unknown";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
package com.central.oauth.controller;
|
||||
|
||||
import com.central.common.constant.SecurityConstants;
|
||||
import com.central.common.model.CodeEnum;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.utils.RSAUtil;
|
||||
import com.central.common.utils.StringUtils;
|
||||
import com.central.oauth.model.Client;
|
||||
import com.central.oauth.model.LoginReq;
|
||||
import com.central.oauth.service.IClientService;
|
||||
import com.central.oauth.service.IValidateCodeService;
|
||||
import com.central.oauth.service.ZltUserDetailsService;
|
||||
import com.central.oauth.service.impl.UnifiedLogoutService;
|
||||
import com.central.oauth.service.impl.UserDetailServiceFactory;
|
||||
import com.central.oauth.support.mobile.MobileAuthenticationProvider;
|
||||
import com.central.oauth.support.openid.OpenIdAuthenticationProvider;
|
||||
import com.central.oauth.support.password.PasswordAuthenticationProvider;
|
||||
import com.central.oauth.support.passwordCode.PasswordCodeAuthenticationProvider;
|
||||
import com.central.oauth.support.tencent.TencentAuthenticationProvider;
|
||||
import com.central.oauth2.common.properties.SecurityProperties;
|
||||
import com.central.oauth2.common.token.OpenIdAuthenticationToken;
|
||||
import com.central.oauth2.common.token.TencentAuthenticationToken;
|
||||
import com.central.oauth2.common.util.AuthUtils;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AccessTokenAuthenticationToken;
|
||||
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;
|
||||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
|
||||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
|
||||
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenGenerator;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Tag(name = "登录接口")
|
||||
@RestController
|
||||
@RequestMapping("/oauth")
|
||||
@Slf4j
|
||||
public class LoginController {
|
||||
|
||||
@Resource
|
||||
private IClientService clientService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private RegisteredClientRepository registeredClientRepository;
|
||||
|
||||
@Resource
|
||||
private ZltUserDetailsService zltUserDetailsService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private OAuth2AuthorizationService authorizationService;
|
||||
|
||||
@Resource
|
||||
private OAuth2TokenGenerator tokenGenerator;
|
||||
|
||||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Resource
|
||||
private UserDetailServiceFactory userDetailServiceFactory;
|
||||
|
||||
@Resource
|
||||
private IValidateCodeService validateCodeService;
|
||||
|
||||
@Resource
|
||||
private SecurityProperties securityProperties;
|
||||
@Resource
|
||||
private UnifiedLogoutService unifiedLogoutService;
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
public Result<Map<String, Object>> login(@RequestBody LoginReq req) {
|
||||
try {
|
||||
// 1) 参数与用户基础校验
|
||||
Result<?> userCheck = zltUserDetailsService.checkUser(req);
|
||||
// 日志(避免敏感信息)
|
||||
log.info("用户登录请求:用户名={}, 客户端ID={}, 授权类型={}", req.getUserName(), req.getClientId(), req.getGrantType());
|
||||
if (Objects.equals(userCheck.getResp_code(), CodeEnum.ERROR.getCode())) {
|
||||
return Result.failed(userCheck.getResp_msg());
|
||||
}
|
||||
|
||||
// 2) 客户端与授权类型校验
|
||||
Client client = clientService.loadClientByClientId(req.getClientId());
|
||||
if (client == null) {
|
||||
return Result.failed("所属客户端不存在");
|
||||
}
|
||||
RegisteredClient registeredClient = registeredClientRepository.findByClientId(client.getClientId());
|
||||
if (registeredClient == null) {
|
||||
return Result.failed("未注册的客户端");
|
||||
}
|
||||
AuthorizationGrantType grantTypeToUse = new AuthorizationGrantType(req.getGrantType());
|
||||
if (!registeredClient.getAuthorizationGrantTypes().contains(grantTypeToUse)) {
|
||||
return Result.failed("客户端未开通该授权类型: " + req.getGrantType());
|
||||
}
|
||||
|
||||
// 3) 解密密码(需要密码的授权类型)
|
||||
String rawPassword = null;
|
||||
if ("password".equals(req.getGrantType()) || "password_code".equals(req.getGrantType()) || "mobile_password".equals(req.getGrantType())) {
|
||||
try {
|
||||
rawPassword = RSAUtil.decryptOne(req.getPassword());
|
||||
if (StringUtils.isBlank(rawPassword)) {
|
||||
return Result.failed("登录密码不能为空");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("密码解密失败", e);
|
||||
return Result.failed("登录密码解密失败,请确保使用正确的加密方式");
|
||||
}
|
||||
}
|
||||
|
||||
// 4) 本地颁发令牌(不走标准端点)
|
||||
return issueTokenInternally(req, registeredClient, rawPassword);
|
||||
} catch (Exception e) {
|
||||
log.error("登录过程发生异常", e);
|
||||
return Result.failed("登录失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/logout")
|
||||
public Result<String> logOut(HttpServletRequest request) {
|
||||
String token = AuthUtils.extractHeaderToken(request);
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return Result.failed("未提供Authorization Bearer token");
|
||||
}
|
||||
try {
|
||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||
if (authorization == null) {
|
||||
return Result.failed("无效的token或token已过期");
|
||||
}
|
||||
if (Boolean.TRUE.equals(securityProperties.getAuth().getUnifiedLogout())) {
|
||||
com.central.oauth.utils.UsernameHolder.setContext(authorization.getPrincipalName());
|
||||
unifiedLogoutService.allLogout();
|
||||
} else {
|
||||
authorizationService.remove(authorization);
|
||||
}
|
||||
return Result.succeed("退出成功");
|
||||
} catch (Exception e) {
|
||||
log.error("登出过程发生异常", e);
|
||||
return Result.failed("登出失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 屏蔽参数中的 token/access_token,只允许从 Authorization 头取 token
|
||||
*/
|
||||
private static class HeaderOnlyTokenRequestWrapper extends HttpServletRequestWrapper {
|
||||
public HeaderOnlyTokenRequestWrapper(HttpServletRequest request) { super(request); }
|
||||
@Override public String getParameter(String name) {
|
||||
if ("token".equals(name) || "access_token".equals(name)) { return null; }
|
||||
return super.getParameter(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用本地 Provider 颁发令牌,支持多种授权类型
|
||||
*/
|
||||
private Result<Map<String, Object>> issueTokenInternally(LoginReq req, RegisteredClient registeredClient, String rawPassword) {
|
||||
try {
|
||||
OAuth2ClientAuthenticationToken clientPrincipal =
|
||||
new OAuth2ClientAuthenticationToken(registeredClient, ClientAuthenticationMethod.CLIENT_SECRET_BASIC, null);
|
||||
|
||||
OAuth2AccessTokenAuthenticationToken accessTokenAuthentication;
|
||||
switch (req.getGrantType()) {
|
||||
case "password": {
|
||||
PasswordAuthenticationProvider provider = new PasswordAuthenticationProvider(
|
||||
authorizationService, tokenGenerator, userDetailServiceFactory, passwordEncoder);
|
||||
com.central.oauth2.common.token.PasswordAuthenticationToken authToken =
|
||||
new com.central.oauth2.common.token.PasswordAuthenticationToken(req.getUserName(), rawPassword);
|
||||
authToken.setScopes(registeredClient.getScopes());
|
||||
authToken.setClientPrincipal(clientPrincipal);
|
||||
java.util.HashMap<String, Object> ap = new java.util.HashMap<>();
|
||||
ap.put(com.central.common.constant.SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, com.central.common.constant.SecurityConstants.DEF_ACCOUNT_TYPE);
|
||||
authToken.setAdditionalParameters(ap);
|
||||
accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) provider.authenticate(authToken);
|
||||
break;
|
||||
}
|
||||
case "password_code": {
|
||||
PasswordCodeAuthenticationProvider provider = new PasswordCodeAuthenticationProvider(
|
||||
authorizationService, tokenGenerator, userDetailServiceFactory, passwordEncoder, validateCodeService);
|
||||
com.central.oauth2.common.token.PasswordCodeAuthenticationToken authToken =
|
||||
new com.central.oauth2.common.token.PasswordCodeAuthenticationToken(
|
||||
req.getUserName(), rawPassword, req.getDeviceId(), req.getValidCode());
|
||||
authToken.setScopes(registeredClient.getScopes());
|
||||
authToken.setClientPrincipal(clientPrincipal);
|
||||
java.util.HashMap<String, Object> ap = new java.util.HashMap<>();
|
||||
ap.put(com.central.common.constant.SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, com.central.common.constant.SecurityConstants.DEF_ACCOUNT_TYPE);
|
||||
authToken.setAdditionalParameters(ap);
|
||||
accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) provider.authenticate(authToken);
|
||||
break;
|
||||
}
|
||||
case "mobile_password": {
|
||||
MobileAuthenticationProvider provider = new MobileAuthenticationProvider(
|
||||
authorizationService, tokenGenerator, userDetailServiceFactory, passwordEncoder);
|
||||
com.central.oauth2.common.token.MobileAuthenticationToken authToken =
|
||||
new com.central.oauth2.common.token.MobileAuthenticationToken(req.getMobile(), rawPassword);
|
||||
authToken.setScopes(registeredClient.getScopes());
|
||||
authToken.setClientPrincipal(clientPrincipal);
|
||||
java.util.HashMap<String, Object> ap = new java.util.HashMap<>();
|
||||
ap.put(com.central.common.constant.SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, com.central.common.constant.SecurityConstants.DEF_ACCOUNT_TYPE);
|
||||
authToken.setAdditionalParameters(ap);
|
||||
accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) provider.authenticate(authToken);
|
||||
break;
|
||||
}
|
||||
case "openId": {
|
||||
OpenIdAuthenticationProvider provider = new OpenIdAuthenticationProvider(
|
||||
authorizationService, tokenGenerator, userDetailServiceFactory);
|
||||
OpenIdAuthenticationToken authToken = new OpenIdAuthenticationToken(req.getOpenId());
|
||||
authToken.setScopes(registeredClient.getScopes());
|
||||
authToken.setClientPrincipal(clientPrincipal);
|
||||
java.util.HashMap<String, Object> ap = new java.util.HashMap<>();
|
||||
ap.put(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, SecurityConstants.DEF_ACCOUNT_TYPE);
|
||||
authToken.setAdditionalParameters(ap);
|
||||
accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) provider.authenticate(authToken);
|
||||
break;
|
||||
}
|
||||
case "tencent": {
|
||||
TencentAuthenticationProvider provider = new TencentAuthenticationProvider(
|
||||
authorizationService, tokenGenerator, userDetailServiceFactory, securityProperties);
|
||||
TencentAuthenticationToken authToken =
|
||||
new com.central.oauth2.common.token.TencentAuthenticationToken(
|
||||
req.getCode(), req.getEncryptedData(), req.getIv(),
|
||||
StringUtils.isBlank(req.getAppCode()) ? "" : req.getAppCode());
|
||||
authToken.setScopes(registeredClient.getScopes());
|
||||
authToken.setClientPrincipal(clientPrincipal);
|
||||
java.util.HashMap<String, Object> ap = new java.util.HashMap<>();
|
||||
ap.put(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, SecurityConstants.DEF_ACCOUNT_TYPE);
|
||||
authToken.setAdditionalParameters(ap);
|
||||
accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) provider.authenticate(authToken);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return Result.failed("不支持的授权类型: " + req.getGrantType());
|
||||
}
|
||||
|
||||
OAuth2AccessToken accessToken = accessTokenAuthentication.getAccessToken();
|
||||
OAuth2RefreshToken refreshToken = accessTokenAuthentication.getRefreshToken();
|
||||
Map<String, Object> additionalParameters = accessTokenAuthentication.getAdditionalParameters();
|
||||
|
||||
OAuth2AccessTokenResponse.Builder builder = OAuth2AccessTokenResponse
|
||||
.withToken(accessToken.getTokenValue())
|
||||
.tokenType(accessToken.getTokenType())
|
||||
.scopes(accessToken.getScopes());
|
||||
if (accessToken.getIssuedAt() != null && accessToken.getExpiresAt() != null) {
|
||||
builder.expiresIn(ChronoUnit.SECONDS.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()));
|
||||
}
|
||||
if (refreshToken != null) {
|
||||
builder.refreshToken(refreshToken.getTokenValue());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(additionalParameters)) {
|
||||
builder.additionalParameters(additionalParameters);
|
||||
}
|
||||
OAuth2AccessTokenResponse tokenResponse = builder.build();
|
||||
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("access_token", tokenResponse.getAccessToken().getTokenValue());
|
||||
body.put("token_type", tokenResponse.getAccessToken().getTokenType().getValue());
|
||||
body.put("expires_in", tokenResponse.getAccessToken().getExpiresAt() != null && tokenResponse.getAccessToken().getIssuedAt() != null
|
||||
? ChronoUnit.SECONDS.between(tokenResponse.getAccessToken().getIssuedAt(), tokenResponse.getAccessToken().getExpiresAt())
|
||||
: 0);
|
||||
body.put("scope", String.join(" ", tokenResponse.getAccessToken().getScopes()));
|
||||
if (tokenResponse.getRefreshToken() != null) {
|
||||
body.put("refresh_token", tokenResponse.getRefreshToken().getTokenValue());
|
||||
}
|
||||
if (!tokenResponse.getAdditionalParameters().isEmpty()) {
|
||||
body.putAll(tokenResponse.getAdditionalParameters());
|
||||
}
|
||||
return Result.succeed(body, "登录成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("本地颁发令牌失败", ex);
|
||||
String msg = ex.getMessage();
|
||||
return Result.failed(StringUtils.isBlank(msg) ? "登录失败" : ("登录失败:" + msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 加密请求模型
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "加密请求")
|
||||
public class CryptoRequest {
|
||||
|
||||
@Schema(description = "要加密的明文数据", required = true, example = "hello123")
|
||||
@NotBlank(message = "数据不能为空")
|
||||
private String data;
|
||||
|
||||
@Schema(description = "请求时间戳(防重放攻击)", required = true)
|
||||
@NotBlank(message = "时间戳不能为空")
|
||||
private String timestamp;
|
||||
|
||||
@Schema(description = "随机数(增强安全性)", required = false)
|
||||
private String nonce;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 加密响应模型
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "加密响应")
|
||||
public class CryptoResponse {
|
||||
|
||||
@Schema(description = "加密后的数据", example = "LBS9qzlDcBQeb+WLhGRKm5+zoQk...")
|
||||
private String encryptedData;
|
||||
|
||||
@Schema(description = "响应时间戳")
|
||||
private Long timestamp;
|
||||
|
||||
@Schema(description = "加密算法信息")
|
||||
private String algorithm;
|
||||
|
||||
@Schema(description = "密钥长度")
|
||||
private Integer keyLength;
|
||||
|
||||
public CryptoResponse() {
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.algorithm = "RSA/ECB/PKCS1Padding";
|
||||
this.keyLength = 1024;
|
||||
}
|
||||
|
||||
public CryptoResponse(String encryptedData) {
|
||||
this();
|
||||
this.encryptedData = encryptedData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 解密请求模型
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "解密请求")
|
||||
public class DecryptRequest {
|
||||
|
||||
@Schema(description = "要解密的密文数据", required = true, example = "LBS9qzlDcBQeb+WLhGRKm5+zoQk...")
|
||||
@NotBlank(message = "加密数据不能为空")
|
||||
private String encryptedData;
|
||||
|
||||
@Schema(description = "请求时间戳(防重放攻击)", required = true)
|
||||
@NotBlank(message = "时间戳不能为空")
|
||||
private String timestamp;
|
||||
|
||||
@Schema(description = "随机数(增强安全性)", required = false)
|
||||
private String nonce;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 解密响应模型
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "解密响应")
|
||||
public class DecryptResponse {
|
||||
|
||||
@Schema(description = "解密后的明文数据")
|
||||
private String data;
|
||||
|
||||
@Schema(description = "响应时间戳")
|
||||
private Long timestamp;
|
||||
|
||||
@Schema(description = "解密算法信息")
|
||||
private String algorithm;
|
||||
|
||||
public DecryptResponse() {
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.algorithm = "RSA/ECB/PKCS1Padding";
|
||||
}
|
||||
|
||||
public DecryptResponse(String data) {
|
||||
this();
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录请求
|
||||
*/
|
||||
@Data
|
||||
public class LoginReq {
|
||||
|
||||
@Schema(description = "用户名(grantType 为 password/password_code 时必填)")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "密码(RSA 加密)。grantType 为 password/password_code/mobile_password 必填")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "认证类型:1)用户名+密码=password;2)用户名+密码+验证码=password_code;3)手机号+密码=mobile_password;4)OpenId=openId;5)微信小程序=tencent。必填")
|
||||
private String grantType;
|
||||
|
||||
@Schema(description = "手机号(grantType 为 mobile_password 必填)")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "客户端ID,必填")
|
||||
private String clientId;
|
||||
|
||||
@Schema(description = "验证码(grantType 为 password_code 必填)")
|
||||
private String validCode;
|
||||
|
||||
@Schema(description = "前端唯一标识,需与获取验证码一致(grantType 为 password_code 必填)")
|
||||
private String deviceId;
|
||||
|
||||
@Schema(description = "OpenId(grantType 为 openId 必填)")
|
||||
private String openId;
|
||||
|
||||
@Schema(description = "微信小程序登录 code(grantType 为 tencent 必填)")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "微信小程序加密数据 encryptedData(tencent 模式建议必填)")
|
||||
private String encryptedData;
|
||||
|
||||
@Schema(description = "微信小程序 iv(tencent 模式建议必填)")
|
||||
private String iv;
|
||||
|
||||
@Schema(description = "应用标识 appCode(tencent 模式可选,缺省使用默认配置)")
|
||||
private String appCode;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.central.oauth.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 公钥响应模型
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "公钥响应")
|
||||
public class PublicKeyResponse {
|
||||
|
||||
@Schema(description = "RSA公钥(Base64编码)")
|
||||
private String publicKey;
|
||||
|
||||
@Schema(description = "密钥长度")
|
||||
private Integer keyLength;
|
||||
|
||||
@Schema(description = "加密算法")
|
||||
private String algorithm;
|
||||
|
||||
@Schema(description = "响应时间戳")
|
||||
private Long timestamp;
|
||||
|
||||
@Schema(description = "密钥版本(用于密钥轮换)")
|
||||
private String version;
|
||||
|
||||
public PublicKeyResponse() {
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.algorithm = "RSA/ECB/PKCS1Padding";
|
||||
this.keyLength = 1024;
|
||||
this.version = "v1.0";
|
||||
}
|
||||
|
||||
public PublicKeyResponse(String publicKey) {
|
||||
this();
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.central.oauth.service;
|
||||
|
||||
import com.central.oauth.model.*;
|
||||
|
||||
/**
|
||||
* 加密服务接口
|
||||
*/
|
||||
public interface ICryptoService {
|
||||
|
||||
/**
|
||||
* 获取RSA公钥
|
||||
* @return 公钥响应
|
||||
*/
|
||||
PublicKeyResponse getPublicKey();
|
||||
|
||||
/**
|
||||
* RSA公钥加密
|
||||
* @param request 加密请求
|
||||
* @return 加密响应
|
||||
*/
|
||||
CryptoResponse encrypt(CryptoRequest request);
|
||||
|
||||
/**
|
||||
* RSA私钥解密
|
||||
* @param request 解密请求
|
||||
* @return 解密响应
|
||||
*/
|
||||
DecryptResponse decrypt(DecryptRequest request);
|
||||
|
||||
/**
|
||||
* 验证时间戳(防重放攻击)
|
||||
* @param timestamp 时间戳字符串
|
||||
* @return 是否有效
|
||||
*/
|
||||
boolean validateTimestamp(String timestamp);
|
||||
|
||||
/**
|
||||
* 检查请求频率限制
|
||||
* @param clientIp 客户端IP
|
||||
* @return 是否允许请求
|
||||
*/
|
||||
boolean checkRateLimit(String clientIp);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.central.oauth.service;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.oauth.model.LoginReq;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@@ -45,4 +47,10 @@ public interface ZltUserDetailsService extends UserDetailsService {
|
||||
* @return
|
||||
*/
|
||||
WechatConfig loadMiniAppConfig(String appId, String type);
|
||||
|
||||
/**
|
||||
* 检查登录用户
|
||||
* @return
|
||||
*/
|
||||
Result checkUser(LoginReq req) ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.central.oauth.service.impl;
|
||||
|
||||
import com.central.common.utils.RSAUtil;
|
||||
import com.central.oauth.model.*;
|
||||
import com.central.oauth.service.ICryptoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 加密服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CryptoServiceImpl implements ICryptoService {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
// 时间戳有效期(5分钟)
|
||||
private static final long TIMESTAMP_VALID_PERIOD = 50 * 60 * 1000 ;
|
||||
|
||||
// 请求频率限制(每IP每分钟最多10次)
|
||||
private static final int RATE_LIMIT_COUNT = 30;
|
||||
private static final int RATE_LIMIT_PERIOD = 60;
|
||||
|
||||
@Override
|
||||
public PublicKeyResponse getPublicKey() {
|
||||
try {
|
||||
// 获取RSA公钥(Base64编码)
|
||||
String publicKeyStr = Base64.getEncoder().encodeToString(RSAUtil.publicKey.getEncoded());
|
||||
return new PublicKeyResponse(publicKeyStr);
|
||||
} catch (Exception e) {
|
||||
log.error("获取公钥失败", e);
|
||||
throw new RuntimeException("获取公钥失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CryptoResponse encrypt(CryptoRequest request) {
|
||||
try {
|
||||
// 1. 验证时间戳
|
||||
if (!validateTimestamp(request.getTimestamp())) {
|
||||
throw new RuntimeException("请求时间戳无效或已过期");
|
||||
}
|
||||
|
||||
// 2. 验证数据
|
||||
if (!StringUtils.hasText(request.getData())) {
|
||||
throw new RuntimeException("要加密的数据不能为空");
|
||||
}
|
||||
|
||||
// 3. 数据长度限制(RSA加密有长度限制)
|
||||
if (request.getData().getBytes().length > 100) {
|
||||
throw new RuntimeException("数据长度不能超过100字节");
|
||||
}
|
||||
|
||||
// 4. RSA公钥加密
|
||||
String encryptedData = RSAUtil.encryptOne(request.getData());
|
||||
if (encryptedData == null) {
|
||||
throw new RuntimeException("数据加密失败");
|
||||
}
|
||||
|
||||
log.info("数据加密成功,原始长度: {}, 加密后长度: {}",
|
||||
request.getData().length(), encryptedData.length());
|
||||
|
||||
return new CryptoResponse(encryptedData);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("加密处理失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("加密失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecryptResponse decrypt(DecryptRequest request) {
|
||||
try {
|
||||
// 1. 验证时间戳
|
||||
if (!validateTimestamp(request.getTimestamp())) {
|
||||
throw new RuntimeException("请求时间戳无效或已过期");
|
||||
}
|
||||
|
||||
// 2. 验证加密数据
|
||||
if (!StringUtils.hasText(request.getEncryptedData())) {
|
||||
throw new RuntimeException("要解密的数据不能为空");
|
||||
}
|
||||
|
||||
// 3. RSA私钥解密
|
||||
String decryptedData = RSAUtil.decryptOne(request.getEncryptedData());
|
||||
if (decryptedData == null) {
|
||||
throw new RuntimeException("数据解密失败,请检查密文格式");
|
||||
}
|
||||
|
||||
log.info("数据解密成功,解密后长度: {}", decryptedData.length());
|
||||
|
||||
return new DecryptResponse(decryptedData);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("解密处理失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("解密失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateTimestamp(String timestamp) {
|
||||
try {
|
||||
if (!StringUtils.hasText(timestamp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long requestTime = Long.parseLong(timestamp);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
// 检查时间戳是否在有效期内(防重放攻击)
|
||||
long timeDiff = Math.abs(currentTime - requestTime);
|
||||
|
||||
if (timeDiff > TIMESTAMP_VALID_PERIOD) {
|
||||
log.warn("请求时间戳超出有效期: {} ms", timeDiff);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否为重放请求(同一时间戳只能使用一次)
|
||||
String key = "crypto:timestamp:" + timestamp;
|
||||
String exists = redisTemplate.opsForValue().get(key);
|
||||
if (exists != null) {
|
||||
log.warn("检测到重放请求,时间戳: {}", timestamp);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 记录已使用的时间戳
|
||||
redisTemplate.opsForValue().set(key, "used", TIMESTAMP_VALID_PERIOD, TimeUnit.MILLISECONDS);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("时间戳格式错误: {}", timestamp);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("验证时间戳失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkRateLimit(String clientIp) {
|
||||
try {
|
||||
String key = "crypto:rate_limit:" + clientIp;
|
||||
String countStr = redisTemplate.opsForValue().get(key);
|
||||
|
||||
if (countStr == null) {
|
||||
// 首次请求
|
||||
redisTemplate.opsForValue().set(key, "1", RATE_LIMIT_PERIOD, TimeUnit.SECONDS);
|
||||
return true;
|
||||
}
|
||||
|
||||
int count = Integer.parseInt(countStr);
|
||||
if (count >= RATE_LIMIT_COUNT) {
|
||||
log.warn("客户端 {} 请求频率过高,当前计数: {}", clientIp, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 增加计数
|
||||
redisTemplate.opsForValue().increment(key);
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("检查请求频率失败", e);
|
||||
// 出错时允许请求,避免影响正常业务
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,11 @@ package com.central.oauth.service.impl;
|
||||
|
||||
import com.central.common.constant.SecurityConstants;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.utils.LoginUserUtils;
|
||||
import com.central.common.utils.StringUtils;
|
||||
import com.central.oauth.model.LoginReq;
|
||||
import com.central.oauth.service.ZltUserDetailsService;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
@@ -16,12 +19,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* <p>
|
||||
* Blog: http://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserDetailServiceImpl implements ZltUserDetailsService {
|
||||
@@ -56,8 +53,8 @@ public class UserDetailServiceImpl implements ZltUserDetailsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByWxOpenId(String wxOpenId,String mobile,String unionId) throws UsernameNotFoundException {
|
||||
SysUser sysUser = userService.findByWxOpenId(wxOpenId,mobile,unionId);
|
||||
public UserDetails loadUserByWxOpenId(String wxOpenId, String mobile, String unionId) throws UsernameNotFoundException {
|
||||
SysUser sysUser = userService.findByWxOpenId(wxOpenId, mobile, unionId);
|
||||
checkUser(sysUser);
|
||||
return LoginUserUtils.getLoginAppUser(sysUser);
|
||||
}
|
||||
@@ -67,6 +64,66 @@ public class UserDetailServiceImpl implements ZltUserDetailsService {
|
||||
return wechatConfigService.getConfigByAppId(appId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result checkUser(LoginReq req) {
|
||||
if (req == null) {
|
||||
return Result.failed("请求参数不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(req.getClientId())) {
|
||||
return Result.failed("客户端ID不能为空");
|
||||
}
|
||||
|
||||
String grantType = req.getGrantType();
|
||||
if ("mobile_password".equals(grantType)) {
|
||||
if (StringUtils.isBlank(req.getMobile())) {
|
||||
return Result.failed("手机号不能为空");
|
||||
}
|
||||
} else if ("openId".equals(grantType)) {
|
||||
if (StringUtils.isBlank(req.getOpenId())) {
|
||||
return Result.failed("openId不能为空");
|
||||
}
|
||||
return Result.succeed("校验通过");
|
||||
} else if ("tencent".equals(grantType)) {
|
||||
if (StringUtils.isBlank(req.getCode())) {
|
||||
return Result.failed("code不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(req.getEncryptedData())) {
|
||||
return Result.failed("encryptedData不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(req.getIv())) {
|
||||
return Result.failed("iv不能为空");
|
||||
}
|
||||
return Result.succeed("校验通过");
|
||||
} else {
|
||||
if (StringUtils.isBlank(req.getUserName())) {
|
||||
return Result.failed("用户名不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
if ("password_code".equals(grantType)) {
|
||||
if (StringUtils.isBlank(req.getDeviceId())) {
|
||||
return Result.failed("deviceId不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(req.getValidCode())) {
|
||||
return Result.failed("验证码不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
SysUser sysUser;
|
||||
if ("mobile_password".equals(grantType)) {
|
||||
sysUser = userService.findByMobile(req.getMobile());
|
||||
} else {
|
||||
sysUser = userService.findByUsername(req.getUserName());
|
||||
}
|
||||
if (sysUser == null) {
|
||||
return Result.failed("用户不存在或密码错误");
|
||||
}
|
||||
if (!sysUser.getEnabled()) {
|
||||
return Result.failed("用户已冻结");
|
||||
}
|
||||
return Result.succeed("校验通过");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByMobile(String mobile) {
|
||||
SysUser sysUser = userService.findByMobile(mobile);
|
||||
@@ -80,3 +137,4 @@ public class UserDetailServiceImpl implements ZltUserDetailsService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +1,65 @@
|
||||
spring:
|
||||
datasource:
|
||||
# url: jdbc:mysql://${zlt.datasource.ip}:3306/oauth-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://${zlt.datasource.ip}/oauth-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.oauth.model
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
|
||||
springdoc:
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: com.central.oauth.controller
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
swagger-model-name: 认证中心接口文档
|
||||
#spring:
|
||||
# datasource:
|
||||
## url: jdbc:mysql://${zlt.datasource.ip}:3306/oauth-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
# url: jdbc:mysql://${zlt.datasource.ip}/oauth-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
# username: ${zlt.datasource.username}
|
||||
# password: ${zlt.datasource.password}
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#
|
||||
#mybatis-plus:
|
||||
# mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
# #瀹炰綋鎵弿锛屽涓猵ackage鐢ㄩ€楀彿鎴栬€呭垎鍙峰垎闅?
|
||||
# typeAliasesPackage: com.central.oauth.model
|
||||
# global-config:
|
||||
# db-config:
|
||||
# id-type: auto
|
||||
#
|
||||
#springdoc:
|
||||
# group-configs:
|
||||
# - group: 'default'
|
||||
# paths-to-match: '/**'
|
||||
# packages-to-scan: com.central.oauth.controller
|
||||
#
|
||||
#knife4j:
|
||||
# enable: true
|
||||
# setting:
|
||||
# swagger-model-name: 璁よ瘉涓績鎺ュ彛鏂囨。
|
||||
#
|
||||
#zlt:
|
||||
# security:
|
||||
# code:
|
||||
# # 蹇界暐楠岃瘉鐮佺殑搴旂敤缂栧彿
|
||||
# ignoreClientCode: app
|
||||
# auth:
|
||||
# # 寮€鍚粺涓€鐧诲嚭
|
||||
# unifiedLogout: true
|
||||
# # 鍚岃处鍙风櫥褰曚簰韪?
|
||||
# isSingleLogin: true
|
||||
# #澶氱鎴烽厤缃?
|
||||
# tenant:
|
||||
# enable: true
|
||||
# ignoreTables:
|
||||
# - oauth_client_details
|
||||
# # 鏁版嵁鏉冮檺
|
||||
# datascope:
|
||||
# enabled: false
|
||||
# includeSqls:
|
||||
# # 搴旂敤鍒楄〃
|
||||
# - com.central.oauth.mapper.ClientMapper.findList
|
||||
#uaa:
|
||||
# wx:
|
||||
# # 骞冲彴榛樿鐨凙PPID
|
||||
# appId: wx0c3cc6f1d297644d
|
||||
|
||||
zlt:
|
||||
security:
|
||||
code:
|
||||
# 忽略验证码的应用编号
|
||||
ignoreClientCode: app
|
||||
auth:
|
||||
# 开启统一登出
|
||||
unifiedLogout: true
|
||||
# 同账号登录互踢
|
||||
isSingleLogin: true
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: true
|
||||
ignoreTables:
|
||||
- oauth_client_details
|
||||
# 数据权限
|
||||
datascope:
|
||||
enabled: false
|
||||
includeSqls:
|
||||
# 应用列表
|
||||
- com.central.oauth.mapper.ClientMapper.findList
|
||||
uaa:
|
||||
wx:
|
||||
# 平台默认的APPID
|
||||
appId: wx0c3cc6f1d297644d
|
||||
# 涓鸿嚜瀹氫箟鐧诲綍/鐧诲嚭鎺ュ彛鏀捐
|
||||
ignore:
|
||||
httpUrls:
|
||||
- /oauth/login
|
||||
- /oauth/logout
|
||||
- /oauth/logout/giveToken
|
||||
- /oauth/token
|
||||
# 鍏煎榛樿琛ㄥ崟鐧诲綍涓庡唴缃櫥鍑?
|
||||
- /user/login
|
||||
- /oauth/remove/token
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
server:
|
||||
port: 8000
|
||||
servlet:
|
||||
session:
|
||||
cookie:
|
||||
name: OAUTH2SESSION
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: uaa-server
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 124.222.128.40
|
||||
|
||||
encrypt:
|
||||
key-store:
|
||||
location: classpath:zlt.jks
|
||||
secret: zlt!@#$
|
||||
alias: zlt
|
||||
server:
|
||||
port: 8011
|
||||
servlet:
|
||||
session:
|
||||
cookie:
|
||||
name: OAUTH2SESSION
|
||||
encoding:
|
||||
enabled: true
|
||||
force: true
|
||||
charset: UTF-8
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: uaa-server
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 124.222.128.40
|
||||
|
||||
encrypt:
|
||||
key-store:
|
||||
location: classpath:zlt.jks
|
||||
secret: zlt!@#$
|
||||
alias: zlt
|
||||
|
||||
|
||||
Reference in New Issue
Block a user