|  |  |  | @ -66,6 +66,7 @@ import org.springframework.web.bind.annotation.RestController; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import javax.annotation.Resource; | 
		
	
		
			
				|  |  |  |  | import javax.servlet.http.HttpServletRequest; | 
		
	
		
			
				|  |  |  |  | import javax.servlet.http.HttpServletResponse; | 
		
	
		
			
				|  |  |  |  | import java.util.ArrayList; | 
		
	
		
			
				|  |  |  |  | import java.util.Arrays; | 
		
	
		
			
				|  |  |  |  | import java.util.HashMap; | 
		
	
	
		
			
				
					|  |  |  | @ -201,9 +202,20 @@ public class WhiteController extends CoreBaseController { | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     @GetMapping(value = "/auth/set-cookie") | 
		
	
		
			
				|  |  |  |  |     @ApiOperation(value = "设置cookie", notes = "设置cookie") | 
		
	
		
			
				|  |  |  |  |     public ResultBean setCookie(String token, String imppcookie) { | 
		
	
		
			
				|  |  |  |  |         try { | 
		
	
		
			
				|  |  |  |  |             return new ResultBean(true, AuthUtil.getSessionUser().getUserName() + "设置cookie完成。").build(); | 
		
	
		
			
				|  |  |  |  |         } catch (ImppBusiException e) { | 
		
	
		
			
				|  |  |  |  |             return new ResultBean(false, e.getErrorDetail() + "-[解决]" + e.getErrorSolution()); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     @GetMapping(value = "/auth/{loginStrategy}/sso-login") | 
		
	
		
			
				|  |  |  |  |     @ApiOperation(value = "登录", notes = "登录") | 
		
	
		
			
				|  |  |  |  |     public ResultBean ssoLogin(HttpServletRequest request, @PathVariable(name = "loginStrategy") String loginStrategy) throws NoSuchFieldException { | 
		
	
		
			
				|  |  |  |  |     public ResultBean ssoLogin(HttpServletRequest request, HttpServletResponse response, | 
		
	
		
			
				|  |  |  |  |                                @PathVariable(name = "loginStrategy") String loginStrategy) throws NoSuchFieldException { | 
		
	
		
			
				|  |  |  |  |         String fieldMapping = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.SSO_REQUEST_MAPPING); | 
		
	
		
			
				|  |  |  |  |         if (StringUtils.isEmpty(fieldMapping)) { | 
		
	
		
			
				|  |  |  |  |             return ResultBean.fail("请在平台数据库中配置表添加字段映射配置"); | 
		
	
	
		
			
				
					|  |  |  | @ -211,19 +223,25 @@ public class WhiteController extends CoreBaseController { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         SysLoginModel loginModel = assembleLoginModelByRequest(request, fieldMapping); | 
		
	
		
			
				|  |  |  |  |         loginModel.setLoginStrategy(loginStrategy); | 
		
	
		
			
				|  |  |  |  |         LOGGER.info("loginModel {}", loginModel); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         ValidatorBean.beginValid(loginModel) | 
		
	
		
			
				|  |  |  |  |                 .notNull("loginStrategy", loginModel.getLoginStrategy()) | 
		
	
		
			
				|  |  |  |  |                 .notNull("loginName", loginModel.getLoginName()); | 
		
	
		
			
				|  |  |  |  |         try { | 
		
	
		
			
				|  |  |  |  |             SessionUser sessionUser = AuthUtil.getSessionUser(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         String ssoCacheKey = assembleSsoCacheKey(loginModel); | 
		
	
		
			
				|  |  |  |  |         Object loginCacheObject = redisSession.getObject(ssoCacheKey); | 
		
	
		
			
				|  |  |  |  |         if (loginCacheObject != null) { | 
		
	
		
			
				|  |  |  |  |             LOGGER.info("使用原会话 获取缓存不为空"); | 
		
	
		
			
				|  |  |  |  |             SessionUser sessionUser = (SessionUser) redisSession.getObject(loginCacheObject); | 
		
	
		
			
				|  |  |  |  |             if (sessionUser != null) { | 
		
	
		
			
				|  |  |  |  |                 LOGGER.info("使用原会话 sessionUser不为空"); | 
		
	
		
			
				|  |  |  |  |                 if (sessionUser.getUserCode().equals(loginModel.getLoginName()) || sessionUser.getUserName().equals(loginModel.getLoginName())) { | 
		
	
		
			
				|  |  |  |  |                     return new ResultBean(true, AuthUtil.getSession().getId().toString(), AuthUtil.getSessionUser()); | 
		
	
		
			
				|  |  |  |  | //                    AuthUtil.setSessionUser(sessionUser);
 | 
		
	
		
			
				|  |  |  |  |                     LOGGER.info("使用原会话 用户名匹配返回"); | 
		
	
		
			
				|  |  |  |  |                     return new ResultBean(true, sessionUser.getToken(), sessionUser); | 
		
	
		
			
				|  |  |  |  |                 } | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |         } catch (Exception e) { | 
		
	
		
			
				|  |  |  |  |             LOGGER.info("SSO 单点登录 未找到session 跳过"); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         String beanName = ImppEnumUtil.AUTH_LOGIN_STRATEGY.codeOfStrategyName(loginModel.getLoginStrategy()); | 
		
	
	
		
			
				
					|  |  |  | @ -231,7 +249,22 @@ public class WhiteController extends CoreBaseController { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         BaseThreadLocal.setData(PlatformConstWords.IS_SSO_LOGIN, true); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         return loginByStrategy(request, loginModel, loginStrategyService.login()); | 
		
	
		
			
				|  |  |  |  |         ResultBean<SessionUser> resultBean = loginByStrategy(request, loginModel, loginStrategyService.login()); | 
		
	
		
			
				|  |  |  |  |         if (resultBean.isSuccess()) { | 
		
	
		
			
				|  |  |  |  |             String loginFilterKey = assembleLoginFilterKey(loginModel, resultBean); | 
		
	
		
			
				|  |  |  |  |             redisSession.putObject(ssoCacheKey, loginFilterKey); | 
		
	
		
			
				|  |  |  |  |             LOGGER.info("使用新会话 放入缓存 key:{} value:{}", ssoCacheKey, loginFilterKey); | 
		
	
		
			
				|  |  |  |  |             LOGGER.info("使用新会话 sessionUser:{}", resultBean.getResultObject()); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         return resultBean; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     private String assembleLoginFilterKey(SysLoginModel loginModel, ResultBean<SessionUser> resultBean) { | 
		
	
		
			
				|  |  |  |  |         return CommonConstWords.SESSION_USER + ":" + loginModel.getLoginPlatform() + "_" + resultBean.getResultObject().getUserId(); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     private String assembleSsoCacheKey(SysLoginModel loginModel) { | 
		
	
		
			
				|  |  |  |  |         return CommonConstWords.SESSION_USER + ":" + loginModel.getLoginStrategy() + ":" + loginModel.getLoginName(); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     private SysLoginModel assembleLoginModelByRequest(HttpServletRequest request, String fieldMapping) { | 
		
	
	
		
			
				
					|  |  |  | 
 |