From 507a7f7a09bc3e93314109e12a4140c31b91ab85 Mon Sep 17 00:00:00 2001
From: cdf <857448963@qq.com>
Date: Wed, 17 Jun 2026 14:19:52 +0800
Subject: [PATCH] =?UTF-8?q?=E8=BE=BD=E5=AE=81CAS=E7=BB=9F=E4=B8=80?=
=?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=85=BC=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pqs-auth/pom.xml | 9 +-
.../njcn/auth/config/LnSsoClientConfig.java | 26 ++
.../njcn/auth/config/WebSecurityConfig.java | 2 +-
.../njcn/auth/controller/AuthController.java | 190 +++++++++++-
.../src/main/resources/bootstrap-sjzx.yml | 19 ++
.../njcn/gateway/filter/AuthGlobalFilter.java | 2 +-
.../src/main/resources/bootstrap-sjzx.yml | 3 +
pqs-gateway/src/main/resources/bootstrap.yml | 284 +-----------------
.../com/njcn/user/enums/UserResponseEnum.java | 2 +
9 files changed, 238 insertions(+), 299 deletions(-)
create mode 100644 pqs-auth/src/main/java/com/njcn/auth/config/LnSsoClientConfig.java
diff --git a/pqs-auth/pom.xml b/pqs-auth/pom.xml
index ac24251dd..5dfc8848e 100644
--- a/pqs-auth/pom.xml
+++ b/pqs-auth/pom.xml
@@ -66,6 +66,13 @@
common-oss
${project.version}
+
+
+
+ com.sgcc.epri.auth
+ sso-client-base
+ 2.1.1
+
@@ -138,4 +145,4 @@
-
\ No newline at end of file
+
diff --git a/pqs-auth/src/main/java/com/njcn/auth/config/LnSsoClientConfig.java b/pqs-auth/src/main/java/com/njcn/auth/config/LnSsoClientConfig.java
new file mode 100644
index 000000000..6fbcf4a6f
--- /dev/null
+++ b/pqs-auth/src/main/java/com/njcn/auth/config/LnSsoClientConfig.java
@@ -0,0 +1,26 @@
+package com.njcn.auth.config;
+
+/**
+ * pqs
+ *
+ * @author cdf
+ * @date 2026/6/8
+ */
+
+import com.sgcc.epri.auth.config.EnableSSOClient;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 仅控制 SSO 客户端开关,不影响任何其他功能
+ */
+@Configuration
+@ConditionalOnProperty(
+ prefix = "cas.client", // 配置前缀
+ name = "enabled", // 配置项名称
+ havingValue = "true", // 值为true才生效
+ matchIfMissing = false // 不配置默认关闭
+)
+@EnableSSOClient
+public class LnSsoClientConfig {
+}
diff --git a/pqs-auth/src/main/java/com/njcn/auth/config/WebSecurityConfig.java b/pqs-auth/src/main/java/com/njcn/auth/config/WebSecurityConfig.java
index bba915ca9..773d503c0 100644
--- a/pqs-auth/src/main/java/com/njcn/auth/config/WebSecurityConfig.java
+++ b/pqs-auth/src/main/java/com/njcn/auth/config/WebSecurityConfig.java
@@ -37,7 +37,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
- .antMatchers("/oauth/getPublicKey","/oauth/logout","/auth/getImgCode","/judgeToken/guangZhou","/judgeToken/heBei","/oauth/autoLogin").permitAll()
+ .antMatchers("/oauth/getPublicKey","/oauth/logout","/auth/getImgCode","/judgeToken/guangZhou","/judgeToken/heBei","/oauth/autoLogin","/oauth/lnLogin","/oauth/lnCheck","/oauth/lnRefreshToken").permitAll()
// @link https://gitee.com/xiaoym/knife4j/issues/I1Q5X6 (接口文档knife4j需要放行的规则)
.antMatchers("/webjars/**","/doc.html","/swagger-resources/**","/v2/api-docs").permitAll()
.anyRequest().authenticated()
diff --git a/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java b/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java
index f3d832e22..7b2a1f370 100644
--- a/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java
+++ b/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java
@@ -25,13 +25,17 @@ import com.njcn.user.pojo.po.UserStrategy;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.RequestUtil;
import com.njcn.web.utils.RestTemplateUtil;
+import com.sgcc.epri.auth.session.HttpSessionManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
-import lombok.AllArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
import org.springframework.web.HttpRequestMethodNotSupportedException;
@@ -39,6 +43,10 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriComponentsBuilder;
import springfox.documentation.annotations.ApiIgnore;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
import java.net.URI;
import java.security.KeyPair;
import java.security.Principal;
@@ -55,7 +63,7 @@ import java.util.stream.Collectors;
@Slf4j
@RestController
@RequestMapping("/oauth")
-@AllArgsConstructor
+@RequiredArgsConstructor
public class AuthController extends BaseController {
@@ -71,6 +79,11 @@ public class AuthController extends BaseController {
private final UserTokenService userTokenService;
+ @Value("${cas.redirect-url:http://10.21.30.11:8088/#/login?flag=1}")
+ private String redirectUrl;
+
+ private String UsernamePrefix = "CAS_";
+
@ApiIgnore
@OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.AUTHENTICATE)
@@ -91,7 +104,6 @@ public class AuthController extends BaseController {
String methodDescribe = getMethodDescribe("postAccessToken");
String username = parameters.get(SecurityConstants.USERNAME);
-
String grantType = parameters.get(SecurityConstants.GRANT_TYPE);
if (grantType.equalsIgnoreCase(SecurityConstants.GRANT_CAPTCHA) || grantType.equalsIgnoreCase(SecurityConstants.REFRESH_TOKEN_KEY)) {
username = DesUtils.aesDecrypt(username);
@@ -104,19 +116,19 @@ public class AuthController extends BaseController {
UserStrategy data = passWordRuleFeugnClient.getUserStrategy().getData();
String onlineUserKey = SecurityConstants.TOKEN_ONLINE_PREFIX;
List onLineUser = (List) redisUtil.getLikeListAllValues(onlineUserKey);
- if(CollectionUtil.isNotEmpty(onLineUser)){
+ if (CollectionUtil.isNotEmpty(onLineUser)) {
String finalUsername = username;
- onLineUser = onLineUser.stream().filter(item->{
+ onLineUser = onLineUser.stream().filter(item -> {
JSONObject jsonObject = AuthPubUtil.getLoginByToken(item.getRefreshToken());
String login = jsonObject.getStr(SecurityConstants.USER_NAME_KEY);
long exp = Long.parseLong(jsonObject.getStr(SecurityConstants.JWT_EXP));
- long now = Calendar.getInstance().getTimeInMillis()/1000;
- return (exp > now) && !login.equals(finalUsername);
+ long now = Calendar.getInstance().getTimeInMillis() / 1000;
+ return (exp > now) && !login.equals(finalUsername);
}).collect(Collectors.toList());
}
Integer maxNum = data.getMaxNum();
- if((CollectionUtil.isNotEmpty(onLineUser)?onLineUser.size():0)>=maxNum){
+ if ((CollectionUtil.isNotEmpty(onLineUser) ? onLineUser.size() : 0) >= maxNum) {
throw new BusinessException(UserResponseEnum.LOGIN_USER_OVERLIMIT);
}
@@ -143,7 +155,7 @@ public class AuthController extends BaseController {
@OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
@ApiOperation("用户登出系统")
@DeleteMapping("/logout")
- public HttpResult