| 
					
				 | 
			
			
				@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.google.code.kaptcha.impl.DefaultKaptcha; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.google.code.kaptcha.util.Config; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.auth.OauthRsaKeyDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.login.BaseLoginLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -18,10 +19,7 @@ import com.yihu.jw.security.model.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.oauth2.core.redis.WlyyRedisVerifyCodeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.oauth2.provider.WlyyTokenGranter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.oauth2.provider.error.WlyyOAuth2ExceptionTranslator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.service.OauthCaConfigSerivce; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.service.OauthWjwConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.service.OauthWlyyConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.service.OauthYlzConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.utils.AES; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.utils.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.security.utils.SerializeUtil; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -126,6 +124,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OauthCaConfigSerivce oauthCaConfigSerivce; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OauthWjwConfigService oauthWjwConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OauthSsoService oauthSsoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @PostConstruct 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1085,4 +1085,83 @@ public class WlyyLoginEndpoint extends AbstractEndpoint { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return pass; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/oauth/getSsoPublicKey", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("获取通用公钥") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop getSsoPublicKey(String code,String appId)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getSuccess("success",oauthSsoService.getSsoPublic(code,appId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/oauth/test", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("test dd") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop test()throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getSuccess("success",oauthSsoService.getAuthCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/oauth/ssoPatientLogin", method = RequestMethod.POST) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop ssoPatientLogin(String authCode,String client_id,String code,String appId,String login_type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(client_id)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new InvalidRequestException("client_id is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(authCode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new InvalidRequestException("authCode is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(code)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new InvalidRequestException("code is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(appId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new InvalidRequestException("appId is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("authCode :"+authCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BasePatientDO patientDO = oauthSsoService.savePatient(code,appId,authCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(patientDO == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ObjEnvelop.getError("授权登录失败!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, String> parameters = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parameters.put("username",patientDO.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parameters.put("grant_type", "ihealthCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (authenticatedClient != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (token == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wlyyUserSimple.setAccessToken(token.getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wlyyUserSimple.setTokenType(token.getTokenType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wlyyUserSimple.setExpiresIn(token.getExpiresIn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wlyyUserSimple.setUser(parameters.get("username")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String loginType = parameters.get("login_type"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BaseLoginLogDO baseLoginLogDO = new BaseLoginLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userDetailsService.setRolePhth(loginType, token, wlyyUserSimple.getId(), redisTemplate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseLoginLogDO.setUserId(wlyyUserSimple.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseLoginLogDO.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String userAgent = JSONObject.toJSONString(wlyyUserSimple); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseLoginLogDO.setUserAgent(userAgent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseLoginLogDO.setLoginType(loginType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseLoginLogService.save(baseLoginLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getSuccess("success",wlyyUserSimple); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error(e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getError("登录失败!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |