jindi 1 år sedan
förälder
incheckning
3a1dbc00b1

+ 52 - 45
.idea/workspace.xml

@@ -43,9 +43,9 @@
       <change afterPath="$PROJECT_DIR$/log/ssp-server/2023_08/2023_08_23/2023_08_23_09(0).log" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/java/com/pj/project/sso/SsoServerController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/pj/project/sso/SsoServerController.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/resources/application.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.yml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/application.yml" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/application.yml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/pj/project/sys_user_acc/SysUserAccController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/pj/project/sys_user_acc/SysUserAccController.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/target/classes/com/pj/project/sso/SsoServerController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/pj/project/sso/SsoServerController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/pj/project/sys_user_acc/SysUserAccController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/pj/project/sys_user_acc/SysUserAccController.class" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -102,14 +102,14 @@
     <property name="settings.editor.selected.configurable" value="preferences.fileTypes" />
   </component>
   <component name="RecentsManager">
-    <key name="MoveFile.RECENT_KEYS">
+    <key name="CopyFile.RECENT_KEYS">
+      <recent name="E:\java\YaoXiangMu\sa-sso-pro\ssp-server" />
       <recent name="E:\java\YaoXiangMu\sa-sso-pro\ssp-server\src\main\resources\static" />
     </key>
     <key name="CopyClassDialog.RECENTS_KEY">
       <recent name="com.pj.project.sys_user" />
     </key>
-    <key name="CopyFile.RECENT_KEYS">
-      <recent name="E:\java\YaoXiangMu\sa-sso-pro\ssp-server" />
+    <key name="MoveFile.RECENT_KEYS">
       <recent name="E:\java\YaoXiangMu\sa-sso-pro\ssp-server\src\main\resources\static" />
     </key>
   </component>
@@ -188,7 +188,7 @@
       <workItem from="1694170221068" duration="88000" />
       <workItem from="1694224377178" duration="4330000" />
       <workItem from="1694240006247" duration="12587000" />
-      <workItem from="1694394248081" duration="5896000" />
+      <workItem from="1694394248081" duration="25464000" />
     </task>
     <task id="LOCAL-00001" summary="项目提交">
       <created>1692754671570</created>
@@ -393,14 +393,20 @@
       <option name="project" value="LOCAL" />
       <updated>1693901584746</updated>
     </task>
-    <option name="localTasksCounter" value="30" />
+    <task id="LOCAL-00030" summary="项目提交">
+      <created>1694400428458</created>
+      <option name="number" value="00030" />
+      <option name="presentableId" value="LOCAL-00030" />
+      <option name="project" value="LOCAL" />
+      <updated>1694400428458</updated>
+    </task>
+    <option name="localTasksCounter" value="31" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
     <option name="version" value="1" />
   </component>
   <component name="VcsManagerConfiguration">
-    <MESSAGE value="项目提交" />
     <MESSAGE value="静态资源+/api" />
     <MESSAGE value="静态资源复原" />
     <MESSAGE value="/import/user接口修改" />
@@ -418,7 +424,8 @@
     <MESSAGE value="/sso/Auth接口修改" />
     <MESSAGE value=" /sso/Auth接口修改" />
     <MESSAGE value="/sso/auth" />
-    <option name="LAST_COMMIT_MESSAGE" value="/sso/auth" />
+    <MESSAGE value="项目提交" />
+    <option name="LAST_COMMIT_MESSAGE" value="项目提交" />
   </component>
   <component name="WindowStateProjectService">
     <state x="2685" y="204" key="#com.intellij.ide.util.MemberChooser" timestamp="1692946298826">
@@ -429,18 +436,18 @@
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
     <state x="2610" y="267" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1692090140484" />
-    <state x="2635" y="222" width="1024" height="595" key="#xdebugger.evaluate" timestamp="1694395726578">
+    <state x="2635" y="222" width="1024" height="595" key="#xdebugger.evaluate" timestamp="1694402260583">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state x="2635" y="222" width="1024" height="595" key="#xdebugger.evaluate/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694395726578" />
-    <state x="2544" y="170" key="CommitChangelistDialog2" timestamp="1694400279814">
+    <state x="2635" y="222" width="1024" height="595" key="#xdebugger.evaluate/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694402260583" />
+    <state x="2544" y="170" key="CommitChangelistDialog2" timestamp="1694400421408">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state x="2544" y="170" key="CommitChangelistDialog2/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400279814" />
-    <state width="1444" height="466" key="DebuggerActiveHint" timestamp="1694396238468">
+    <state x="2544" y="170" key="CommitChangelistDialog2/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400421408" />
+    <state width="1444" height="466" key="DebuggerActiveHint" timestamp="1694418699725">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1444" height="466" key="DebuggerActiveHint/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694396238468" />
+    <state width="1444" height="466" key="DebuggerActiveHint/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694418699725" />
     <state x="2012" y="92" width="1736" height="856" key="DiffContextDialog" timestamp="1693013173565">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
@@ -449,66 +456,66 @@
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
     <state x="2660" y="275" key="FileChooserDialogImpl/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694249944928" />
-    <state width="1877" height="220" key="GridCell.Tab.0.bottom" timestamp="1694400337231">
+    <state width="1877" height="220" key="GridCell.Tab.0.bottom" timestamp="1694427534106">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="220" key="GridCell.Tab.0.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400337231" />
-    <state width="1877" height="220" key="GridCell.Tab.0.center" timestamp="1694400337231">
+    <state width="1877" height="220" key="GridCell.Tab.0.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427534106" />
+    <state width="1877" height="220" key="GridCell.Tab.0.center" timestamp="1694427534106">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="220" key="GridCell.Tab.0.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400337231" />
-    <state width="1877" height="220" key="GridCell.Tab.0.left" timestamp="1694400337231">
+    <state width="1877" height="220" key="GridCell.Tab.0.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427534106" />
+    <state width="1877" height="220" key="GridCell.Tab.0.left" timestamp="1694427534106">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="220" key="GridCell.Tab.0.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400337231" />
-    <state width="1877" height="220" key="GridCell.Tab.0.right" timestamp="1694400337231">
+    <state width="1877" height="220" key="GridCell.Tab.0.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427534106" />
+    <state width="1877" height="220" key="GridCell.Tab.0.right" timestamp="1694427534106">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="220" key="GridCell.Tab.0.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400337231" />
-    <state width="1877" height="224" key="GridCell.Tab.1.bottom" timestamp="1694400078866">
+    <state width="1877" height="220" key="GridCell.Tab.0.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427534106" />
+    <state width="1877" height="233" key="GridCell.Tab.1.bottom" timestamp="1694427522774">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.1.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078866" />
-    <state width="1877" height="224" key="GridCell.Tab.1.center" timestamp="1694400078866">
+    <state width="1877" height="233" key="GridCell.Tab.1.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522774" />
+    <state width="1877" height="233" key="GridCell.Tab.1.center" timestamp="1694427522774">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.1.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078866" />
-    <state width="1877" height="224" key="GridCell.Tab.1.left" timestamp="1694400078866">
+    <state width="1877" height="233" key="GridCell.Tab.1.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522774" />
+    <state width="1877" height="233" key="GridCell.Tab.1.left" timestamp="1694427522774">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.1.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078866" />
-    <state width="1877" height="224" key="GridCell.Tab.1.right" timestamp="1694400078866">
+    <state width="1877" height="233" key="GridCell.Tab.1.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522774" />
+    <state width="1877" height="233" key="GridCell.Tab.1.right" timestamp="1694427522774">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.1.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078866" />
-    <state width="1877" height="224" key="GridCell.Tab.2.bottom" timestamp="1694400078867">
+    <state width="1877" height="233" key="GridCell.Tab.1.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522774" />
+    <state width="1877" height="233" key="GridCell.Tab.2.bottom" timestamp="1694427522776">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.2.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078867" />
-    <state width="1877" height="224" key="GridCell.Tab.2.center" timestamp="1694400078867">
+    <state width="1877" height="233" key="GridCell.Tab.2.bottom/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522776" />
+    <state width="1877" height="233" key="GridCell.Tab.2.center" timestamp="1694427522775">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.2.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078867" />
-    <state width="1877" height="224" key="GridCell.Tab.2.left" timestamp="1694400078866">
+    <state width="1877" height="233" key="GridCell.Tab.2.center/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522775" />
+    <state width="1877" height="233" key="GridCell.Tab.2.left" timestamp="1694427522775">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.2.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078866" />
-    <state width="1877" height="224" key="GridCell.Tab.2.right" timestamp="1694400078867">
+    <state width="1877" height="233" key="GridCell.Tab.2.left/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522775" />
+    <state width="1877" height="233" key="GridCell.Tab.2.right" timestamp="1694427522776">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state width="1877" height="224" key="GridCell.Tab.2.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694400078867" />
-    <state x="2636" y="231" key="RollbackChangesDialog" timestamp="1693013074093">
+    <state width="1877" height="233" key="GridCell.Tab.2.right/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427522776" />
+    <state x="2636" y="231" key="RollbackChangesDialog" timestamp="1694401544807">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state x="2636" y="231" key="RollbackChangesDialog/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1693013074093" />
+    <state x="2636" y="231" key="RollbackChangesDialog/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694401544807" />
     <state x="2381" y="162" key="SettingsEditor" timestamp="1694170307639">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
     <state x="2381" y="162" key="SettingsEditor/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694170307639" />
-    <state x="2472" y="253" key="Vcs.Push.Dialog.v2" timestamp="1693901623669">
+    <state x="2472" y="253" key="Vcs.Push.Dialog.v2" timestamp="1694427695172">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state x="2472" y="253" key="Vcs.Push.Dialog.v2/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1693901623669" />
+    <state x="2472" y="253" key="Vcs.Push.Dialog.v2/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694427695172" />
     <state width="968" height="528" key="XDebugger.FullValuePopup" timestamp="1693907767752">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
@@ -521,10 +528,10 @@
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
     <state x="2672" y="437" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1693547334479" />
-    <state x="2135" y="81" width="1115" height="669" key="find.popup" timestamp="1694399659608">
+    <state x="2135" y="81" width="1115" height="669" key="find.popup" timestamp="1694415673474">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>
-    <state x="2135" y="81" width="1115" height="669" key="find.popup/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694399659608" />
+    <state x="2135" y="81" width="1115" height="669" key="find.popup/1920.0.1920.1040/0.0.1920.1040@1920.0.1920.1040" timestamp="1694415673474" />
     <state x="2581" y="147" key="refactoring.ChangeSignatureDialog" timestamp="1692685608267">
       <screen x="1920" y="0" width="1920" height="1040" />
     </state>

+ 61 - 0
src/main/java/com/pj/project/sso/CorsFilter.java

@@ -0,0 +1,61 @@
+//package com.pj.project.sso;
+//
+//import java.io.IOException;
+//
+//import javax.servlet.Filter;
+//import javax.servlet.FilterChain;
+//import javax.servlet.FilterConfig;
+//import javax.servlet.ServletException;
+//import javax.servlet.ServletRequest;
+//import javax.servlet.ServletResponse;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//
+//import org.springframework.core.annotation.Order;
+//import org.springframework.stereotype.Component;
+//
+///**
+// * 跨域过滤器
+// * @author click33
+// */
+//@Component
+//@Order(-200)
+//public class CorsFilter implements Filter {
+//
+//	static final String OPTIONS = "OPTIONS";
+//
+//	@Override
+//	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+//			throws IOException, ServletException {
+//		HttpServletRequest request = (HttpServletRequest) req;
+//		HttpServletResponse response = (HttpServletResponse) res;
+//
+//		// 允许指定域访问跨域资源
+//		response.setHeader("Access-Control-Allow-Origin", "*");
+//		// 允许所有请求方式
+//		response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
+//		// 有效时间
+//		response.setHeader("Access-Control-Max-Age", "3600");
+//		// 允许的header参数
+//		response.setHeader("Access-Control-Allow-Headers", "x-requested-with,satoken");
+//
+//		// 如果是预检请求,直接返回
+//		if (OPTIONS.equals(request.getMethod())) {
+//			System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
+//			response.getWriter().print("");
+//			return;
+//		}
+//
+//		// System.out.println("*********************************过滤器被使用**************************");
+//		chain.doFilter(req, res);
+//	}
+//
+//	@Override
+//	public void init(FilterConfig filterConfig) {
+//	}
+//
+//	@Override
+//	public void destroy() {
+//	}
+//
+//}

+ 104 - 0
src/main/java/com/pj/project/sso/H5Controller.java

@@ -0,0 +1,104 @@
+//package com.pj.project.sso;
+//
+//import cn.dev33.satoken.sso.SaSsoProcessor;
+//import com.pj.current.satoken.StpUserUtil;
+//import com.pj.project.sys_user.SysUser;
+//import com.pj.utils.sg.AjaxJson;
+//import com.pj.utils.so.SoMap;
+//import io.netty.util.internal.StringUtil;
+//import org.springframework.web.bind.annotation.ExceptionHandler;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//
+//import cn.dev33.satoken.sso.SaSsoConsts;
+//import cn.dev33.satoken.sso.SaSsoUtil;
+//import cn.dev33.satoken.stp.StpUtil;
+//import cn.dev33.satoken.util.SaFoxUtil;
+//import cn.dev33.satoken.util.SaResult;
+//
+//import java.util.LinkedHashMap;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.stream.Collectors;
+//
+///**
+// * 前后台分离架构下集成SSO所需的代码 (SSO-Server端)
+// * <p>(注:如果不需要前后端分离架构下集成SSO,可删除此包下所有代码)</p>
+// *
+// * @author click33
+// */
+//@RestController
+//public class H5Controller {
+//
+//    /**
+//     * 获取 redirectUrl
+//     */
+///*	@RequestMapping("/sso/getRedirectUrl")
+//	private Object getRedirectUrl(String redirect, String mode, String client) {
+//		// 未登录情况下,返回 code=401
+//		if(StpUtil.isLogin() == false) {
+//			return SaResult.code(401);
+//		}
+//		// 已登录情况下,构建 redirectUrl
+//		if(SaSsoConsts.MODE_SIMPLE.equals(mode)) {
+//			// 模式一
+//			SaSsoUtil.checkRedirectUrl(SaFoxUtil.decoderUrl(redirect));
+//			return SaResult.data(redirect);
+//		} else {
+//			// 模式二或模式三
+//			String redirectUrl = SaSsoUtil.buildRedirectUrl(StpUtil.getLoginId(), client, redirect);
+//			return SaResult.data(redirectUrl);
+//		}
+//	}*/
+//    @RequestMapping("/sso/getRedirectUrl")
+//    public Object getRedirectUrl(String redirect, String client, String satoken) {
+//        // 未登录情况下,返回 code=401
+//        if (StringUtil.isNullOrEmpty(satoken)) {
+//            return SaResult.code(401);
+//        }
+//        SoMap so = SoMap.getRequestSoMap();
+//        // 查询该id是否在线
+//        List<String> sessionIdList = StpUserUtil.searchSessionId(satoken, so.getStartIndex(), so.getKeyPageSize(), false);
+//        if (sessionIdList != null && sessionIdList.size() > 0) {
+//            //已登录,返回数据
+//            Map map = new LinkedHashMap();
+//            map.put("satoken", satoken);
+//            map.put("redirect", redirect);
+//            return SaResult.data(map);
+//        } else {
+//            return SaResult.code(401);
+//        }
+//    }
+//
+////	// 当前是否登录
+////	@RequestMapping("/sso/isLogin")
+////	public Object isLogin() {
+////		return SaResult.data(StpUtil.isLogin());
+////	}
+////
+////	// 返回SSO认证中心登录地址
+////	@RequestMapping("/sso/getSsoAuthUrl")
+////	public SaResult getSsoAuthUrl(String clientLoginUrl) {
+////		String serverAuthUrl = SaSsoUtil.buildServerAuthUrl(clientLoginUrl, "");
+////		return SaResult.data(serverAuthUrl);
+////	}
+////
+////	// 根据ticket进行登录
+////	@RequestMapping("/sso/doLoginByTicket")
+////	public SaResult doLoginByTicket(String ticket) {
+////		Object loginId = SaSsoProcessor.instance.checkTicket(ticket, "/sso/doLoginByTicket");
+////		if(loginId != null) {
+////			StpUtil.login(loginId);
+////			return SaResult.data(StpUtil.getTokenValue());
+////		}
+////		return SaResult.error("无效ticket:" + ticket);
+////	}
+//
+////    // 全局异常拦截
+////    @ExceptionHandler
+////    public SaResult handlerException(Exception e) {
+////        e.printStackTrace();
+////        return SaResult.error(e.getMessage());
+////    }
+//
+//}

+ 146 - 32
src/main/java/com/pj/project/sso/SsoServerController.java

@@ -16,6 +16,8 @@ import com.pj.project.sys_client.SysClient;
 import com.pj.project.sys_client.SysClientMapper;
 import com.pj.project.sys_client_visit.SysClientVisit;
 import com.pj.project.sys_client_visit.SysClientVisitMapper;
+import com.pj.project.sys_login_log.SysLoginLog;
+import com.pj.project.sys_login_log.SysLoginLogUtil;
 import com.pj.project.sys_user.SysUser;
 import com.pj.project.sys_user.SysUserMapper;
 import com.pj.project.sys_user_acc.*;
@@ -25,8 +27,10 @@ import com.pj.project4sp.config.SpConfig;
 import com.pj.project4sp.config.SpConfigMapper;
 import com.pj.project4sp.config.SpConfigUtil;
 import com.pj.utils.sg.AjaxError;
+import com.pj.utils.sg.IpUtil;
 import com.pj.utils.sg.NbUtil;
 import com.pj.utils.so.SoMap;
+import eu.bitwalker.useragentutils.UserAgent;
 import io.netty.util.internal.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -50,8 +54,11 @@ import cn.dev33.satoken.sso.SaSsoUtil;
 import cn.dev33.satoken.sso.exception.SaSsoException;
 import org.springframework.web.servlet.view.RedirectView;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -96,9 +103,41 @@ public class SsoServerController {
         return SaSsoProcessor.instance.serverDister();
     }
 
+    @RequestMapping("/sso/getRedirectUrl")
+    public Object getRedirectUrl(@RequestBody String jsonBody) {
+        JSONObject jsonObject = JSON.parseObject(jsonBody);
+        String redirect = (String) jsonObject.get("redirect");
+        String client = (String) jsonObject.get("client");
+        String satoken = (String) jsonObject.get("satoken");
+        // 未登录情况下,返回 code=505
+        if (StringUtil.isNullOrEmpty(satoken)) {
+            SaResult saResult = new SaResult();
+            saResult.setCode(505);
+            saResult.setMsg("暂未登录,请登录");
+            return saResult;
+        }
+        SoMap so = SoMap.getRequestSoMap();
+        // 查询该id是否在线
+        List<String> sessionIdList = StpUserUtil.searchSessionId(satoken, so.getStartIndex(), so.getKeyPageSize(), false);
+        if (sessionIdList != null && sessionIdList.size() > 0) {
+            //已登录,返回数据
+            String ticket = saSsoTemplate.createTicket(satoken, "ssp-client3-nosdk");
+
+            Map map = new LinkedHashMap();
+//            map.put("satoken", satoken);
+            map.put("ticket", ticket);
+            map.put("redirect", redirect);
+            return SaResult.data(map);
+        } else {
+            SaResult saResult = new SaResult();
+            saResult.setCode(505);
+            saResult.setMsg("暂未登录,请登录");
+            return saResult;
+        }
+    }
 
     // 重写 /sso/auth 统一认证请求处理,增加日志记录
-    @RequestMapping("/sso/auth")
+    /*@RequestMapping("/sso/auth")
     public Object ssoAuth() {
         //查出重定向地址
         SpConfig config = spConfigMapper.getByName("title");
@@ -106,27 +145,26 @@ public class SsoServerController {
 
         // 1. 记录一下登录日志: xx 账号登录了 xx 应用
         String loginId = StpUserUtil.getLoginId("");
-//    	if(loginId != 0L) {
         if (!StringUtil.isNullOrEmpty(loginId)) {
 
             // 1. 校验 redirect 是否有效
             String redirect = SaHolder.getRequest().getParam("redirect");
             Long clientId = SysClientUtil.getClientIdByUrl(redirect);
             if (clientId == null) {
-                SpringMVCUtil.getRequest().setAttribute("errorMessage", "无效 redirect:" + redirect);
-                return new ModelAndView("login.html");
-//                RedirectView redirectView = new RedirectView(url);
-//                redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
-//                return redirectView;
+//                SpringMVCUtil.getRequest().setAttribute("errorMessage", "无效 redirect:" + redirect);
+//                return new ModelAndView("login.html");
+                RedirectView redirectView = new RedirectView(url);
+                redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
+                return redirectView;
             }
 
             // 2. 判断这个用户是否被禁止登录此应用,如果已被禁止,则立即截断登录
             if (SysClientVisitUtil.isSureLogin(loginId, redirect) == false) {
-                SpringMVCUtil.getRequest().setAttribute("errorMessage", "当前账号暂无权限登入此应用,请更换账号");
-                return new ModelAndView("login.html");
-//                RedirectView redirectView = new RedirectView(url);
-//                redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
-//                return redirectView;
+//                SpringMVCUtil.getRequest().setAttribute("errorMessage", "当前账号暂无权限登入此应用,请更换账号");
+//                return new ModelAndView("login.html");
+                RedirectView redirectView = new RedirectView(url);
+                redirectView.setStatusCode(HttpStatus.FOUND);
+                return redirectView;
             }
 
             // 3. 记录登录日志
@@ -155,6 +193,49 @@ public class SsoServerController {
 //                return res.redirect(redirectUrl);
 //            }
 //        }
+    }*/
+    @RequestMapping("/sso/auth")
+    public Object ssoAuth() {
+        //查出重定向地址
+        SpConfig config = spConfigMapper.getByName("title");
+        String url = (config != null && !StringUtil.isNullOrEmpty(config.getValue())) ? config.getValue() : "/";
+
+        // 1. 记录一下登录日志: xx 账号登录了 xx 应用
+        String loginId = StpUserUtil.getLoginId("");
+        String redirect = SaHolder.getRequest().getParam("redirect");
+
+        if (!StringUtil.isNullOrEmpty(loginId)) {
+            // 1. 校验 redirect 是否有效
+            Long clientId = SysClientUtil.getClientIdByUrl(redirect);
+            if (clientId == null) {
+                RedirectView redirectView = new RedirectView(url + "?client=ssp-client3-nosdk&redirect=" + redirect);
+                redirectView.setStatusCode(HttpStatus.NOT_FOUND);
+                return redirectView;
+            }
+            // 2. 判断这个用户是否被禁止登录此应用,如果已被禁止,则立即截断登录
+            if (SysClientVisitUtil.isSureLogin(loginId, redirect) == false) {
+                RedirectView redirectView = new RedirectView(url + "?client=ssp-client3-nosdk&redirect=" + redirect);
+                redirectView.setStatusCode(HttpStatus.FORBIDDEN);
+                return redirectView;
+            }
+            // 3. 记录登录日志
+            sysUserAccService.successLogin(loginId, redirect);
+        } else {
+            // 1. 校验 redirect 是否有效
+            Long clientId = SysClientUtil.getClientIdByUrl(redirect);
+            if (clientId == null) {
+                RedirectView redirectView = new RedirectView(url);
+                redirectView.setStatusCode(HttpStatus.NOT_FOUND);
+                return redirectView;
+            } else {
+                RedirectView redirectView = new RedirectView(url + "?client=ssp-client3-nosdk&redirect=" + redirect);
+                redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
+                return redirectView;
+            }
+        }
+        RedirectView redirectView = new RedirectView(url + "?client=ssp-client3-nosdk&redirect=" + redirect);
+        redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
+        return redirectView;
     }
 
 
@@ -177,27 +258,60 @@ public class SsoServerController {
             return new ModelAndView("login.html");
         });
         // 配置:登录处理函数
-//        sso.setDoLoginHandle((name, pwd) -> {
-//            // 此处仅做模拟登录,真实环境应该查询数据进行登录
-//            // 校验参数
-//            if (NbUtil.hasNull(name, pwd)) {
-//                return SaResult.error("请输入账号/密码");
-//            }
-//            //对加密密码进行解密
-//            //pwd = BtoAAtoB.atob(pwd);
-//            // 获取相应用户
-//            SysUserAcc userAcc = sysUserAccMapper.getByUsername(name);
-//
-//            // 2、开始校验
-//            if (userAcc == null) return SaResult.error("无此账号");
-//            if (NbUtil.isNull(userAcc.getPassword())) return SaResult.error("此账号尚未设置密码,无法登陆");
-//            String md5Password = SystemObject.getPasswordMd5Str(userAcc.getId(), pwd);
-//            if (userAcc.getPassword().equals(md5Password) == false) return SaResult.error("密码错误");
-//            if (userAcc.getStatus() == 2) return SaResult.error("此账号已被禁用,如有疑问,请联系管理员");
-//
+        sso.setDoLoginHandle((name, pwd) -> {
+            // 此处仅做模拟登录,真实环境应该查询数据进行登录
+            // 校验参数
+            if (NbUtil.hasNull(name, pwd)) {
+                return SaResult.error("请输入账号/密码");
+            }
+            //对加密密码进行解密
+            //pwd = BtoAAtoB.atob(pwd);
+            // 获取相应用户
+            SysUserAcc userAcc = sysUserAccMapper.getByUsername(name);
+
+            // 2、开始校验
+            if (userAcc == null) return SaResult.error("无此账号");
+            if (NbUtil.isNull(userAcc.getPassword())) return SaResult.error("此账号尚未设置密码,无法登陆");
+            String md5Password = SystemObject.getPasswordMd5Str(userAcc.getId(), pwd);
+            if (userAcc.getPassword().equals(md5Password) == false) return SaResult.error("密码错误");
+            if (userAcc.getStatus() == 2) return SaResult.error("此账号已被禁用,如有疑问,请联系管理员");
+
+//            StpUtil.stpLogic.setLoginType("user");
 //            StpUtil.login(userAcc.getId());
-//            return SaResult.ok("登录成功!").setData(StpUtil.getTokenValue());
-//        });
+
+
+            // 调用 Sa-Token 登录会话
+            StpUserUtil.login(userAcc.getId());
+
+            // 将User对象写入User-Session,以便所有Client端可以取到
+            Object user = SysUserAccUtil.getUserById(userAcc.getId());
+            StpUserUtil.getSession().set("user", user);
+
+            // 更新User表记录
+            HttpServletRequest request = SpringMVCUtil.getRequest();
+            UserAgent ua = UserAgent.parseUserAgentString(request.getHeader("user-agent"));
+            String loginIp = IpUtil.getIP(request);
+
+            int line = sysUserAccMapper.successLogin(userAcc.getId(), loginIp);
+            AjaxError.notLine(line, "登录记录更新失败");
+
+            // 更新登录日志表记录
+            SysLoginLog s = new SysLoginLog();    // 声明对象
+            s.setUserId(userAcc.getId());            // 用户id
+            s.setAccToken(StpUserUtil.getTokenInfo().getTokenValue());        // 本次登录Token
+            s.setLoginIp(loginIp);            // 登陆IP
+            s.setLoginAddress(IpUtil.getAddres(loginIp));    // 登陆地
+            s.setLoginDevice(ua.getBrowser().getName());        // 设备标识
+            s.setLoginSystem(ua.getOperatingSystem().getName());    // 系统标识
+            s.setClientDomain("redirect");    // Client端Url
+//        s.setClientId(SysClientUtil.getClientIdByUrl(redirect));	// 所属应用id
+            SysLoginLogUtil.sysLoginLogMapper.add(s);
+
+            // 更新Session中对象
+            StpUserUtil.getSessionByLoginId(userAcc.getId()).set("user", SysUserAccUtil.getUserById(userAcc.getId()));
+
+            return SaResult.ok("登录成功!").setData(StpUtil.getTokenValue());
+        });
 
         // 配置 Http 请求处理器 (在模式三的单点注销功能下用到,如不需要可以注释掉) 
         sso.setSendHttp(url -> {

+ 47 - 4
src/main/java/com/pj/project/sys_user_acc/SysUserAccController.java

@@ -1,7 +1,9 @@
 package com.pj.project.sys_user_acc;
 
 import cn.dev33.satoken.spring.SpringMVCUtil;
+import cn.dev33.satoken.sso.SaSsoTemplate;
 import cn.dev33.satoken.util.SaFoxUtil;
+import cn.dev33.satoken.util.SaResult;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.pj.current.config.SystemObject;
@@ -9,7 +11,9 @@ import com.pj.project.sys_client.SysClientUtil;
 import com.pj.project.sys_login_log.SysLoginLog;
 import com.pj.project.sys_login_log.SysLoginLogUtil;
 import com.pj.utils.sg.IpUtil;
+import com.pj.utils.so.SoMap;
 import eu.bitwalker.useragentutils.UserAgent;
+import io.netty.util.internal.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -29,6 +33,9 @@ import com.pj.utils.sg.NbUtil;
 
 import javax.servlet.http.HttpServletRequest;
 import java.net.URLDecoder;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 用户模块,有关验证码的相关操作UserMapper.xml
@@ -46,6 +53,9 @@ public class SysUserAccController {
     @Autowired
     SysUserAccService sysUserAccService;
 
+    @Autowired
+    private SaSsoTemplate saSsoTemplate;
+
     // -------------------------- 登录相关 --------------------------
 
     /**
@@ -132,23 +142,56 @@ public class SysUserAccController {
         // 获取相应用户
         SysUserAcc userAcc = sysUserAccMapper.getByUsername(name);
         // 2、开始校验
-        if(userAcc == null){
+        if (userAcc == null) {
             return AjaxJson.getSuccess(422, "无此账号");
         }
-        if(NbUtil.isNull(userAcc.getPassword())) {
+        if (NbUtil.isNull(userAcc.getPassword())) {
             return AjaxJson.getSuccess(422, "此账号尚未设置密码,无法登陆");
         }
         String md5Password = SystemObject.getPasswordMd5Str(userAcc.getId(), pwd);
-        if(userAcc.getPassword().equals(md5Password) == false){
+        if (userAcc.getPassword().equals(md5Password) == false) {
             return AjaxJson.getSuccess(422, "密码错误");
         }
-        if(userAcc.getStatus() == 2) {
+        if (userAcc.getStatus() == 2) {
             return AjaxJson.getSuccess(422, "此账号已被禁用,如有疑问,请联系管理员");
         }
         // 返回信息
         return successLoginInfo(userAcc.getId());
     }
 
+    //判断是否登陆接口
+    @RequestMapping("/getRedirectUrl")
+    public Object getRedirectUrl(@RequestBody String jsonBody) {
+        JSONObject jsonObject = JSON.parseObject(jsonBody);
+        String redirect = (String) jsonObject.get("redirect");
+        String client = (String) jsonObject.get("client");
+        String satoken = (String) jsonObject.get("satoken");
+        // 未登录情况下,返回 code=505
+        if (StringUtil.isNullOrEmpty(satoken)) {
+            SaResult saResult = new SaResult();
+            saResult.setCode(505);
+            saResult.setMsg("暂未登录,请登录");
+            return saResult;
+        }
+        SoMap so = SoMap.getRequestSoMap();
+        // 查询该id是否在线
+        List<String> sessionIdList = StpUserUtil.searchSessionId(satoken, so.getStartIndex(), so.getKeyPageSize(), false);
+        if (sessionIdList != null && sessionIdList.size() > 0) {
+            //已登录,返回数据
+            String ticket = saSsoTemplate.createTicket(satoken, "ssp-client3-nosdk");
+            Map map = new LinkedHashMap();
+//            map.put("satoken", satoken);
+            map.put("ticket", ticket);
+            map.put("redirect", redirect);
+            return SaResult.data(map);
+        } else {
+            SaResult saResult = new SaResult();
+            saResult.setCode(505);
+            saResult.setMsg("暂未登录,请登录");
+            return saResult;
+        }
+    }
+
 
     /**
      * 注销登录

BIN
target/classes/com/pj/project/sso/SsoServerController.class


BIN
target/classes/com/pj/project/sys_user_acc/SysUserAccController.class


BIN
xmnk-sso-1.0.jar