|
@@ -3,7 +3,7 @@ package com.tofly.auth.oauth;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tofly.auth.api.MydeskConnectInfo;
|
|
|
-import com.tofly.auth.config.GisBimConfig;
|
|
|
+
|
|
|
import com.tofly.auth.feign.BaseUserService;
|
|
|
import com.tofly.common.core.constant.CommonConstants;
|
|
|
import com.tofly.common.core.constant.SecurityConstants;
|
|
@@ -56,7 +56,7 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
private final BaseUserService baseUserService;
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
private final MydeskConnectInfo mydeskConnectInfo;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@SneakyThrows
|
|
@@ -64,6 +64,7 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
|
|
|
Cache cache = cacheManager.getCache("user_details");
|
|
|
|
|
|
+
|
|
|
String[] userNameSplit = username.split("#");
|
|
|
String usernameWithoutSuf = null;
|
|
|
String suf = null;
|
|
@@ -80,19 +81,18 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
username = useTokenLogin(usernameWithoutSuf);
|
|
|
break;
|
|
|
case "TOKENGISLOGIN":
|
|
|
- username = userTokenLoginGis(usernameWithoutSuf);
|
|
|
+
|
|
|
break;
|
|
|
- case "TOKENLOGINDYG":
|
|
|
+ case "TOKENLOGINDYG_tokenLogin":
|
|
|
username = userTokenLoginDYG(usernameWithoutSuf);
|
|
|
break;
|
|
|
case "#NAMEANDPASSWORDLOGIN":
|
|
|
username = usernameWithoutSuf; break;
|
|
|
- default: username = userNameSplit[0];
|
|
|
+ default: username = userNameSplit[0] ;
|
|
|
}
|
|
|
-
|
|
|
+ username = username.replace("_UNIONLOGIN","");
|
|
|
usernameUpper = username.toUpperCase(Locale.ROOT);
|
|
|
|
|
|
-
|
|
|
log.info("------------baseUserService:{},username:{}",baseUserService,username);
|
|
|
ResultRespone<UserInfo> result = baseUserService.getInfo(username, SecurityConstants.FROM_IN);
|
|
|
log.info("------------result",result.getMessage());
|
|
@@ -103,17 +103,17 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
|
|
|
UserInfo userInfo=result.getResult();
|
|
|
User user=userInfo.getSysUser();
|
|
|
- Date lastUpdateTime = user.getLastUpdateTime();
|
|
|
- if(lastUpdateTime!=null){
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(lastUpdateTime);
|
|
|
- LocalDate newDate = LocalDate.of(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH)+1,calendar.get(Calendar.DAY_OF_MONTH));
|
|
|
- Period period = Period.between(newDate, currentDate);
|
|
|
- if (period.getMonths() >= 6) {
|
|
|
- throw new UserCheckAuthenticationException("用户最后一次修改密码的时间超过6个月,请修改密码!");
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if(!PhoneNumberUtil.isPhone(usernameUpper)){
|
|
|
if (cache != null && cache.get(usernameUpper) != null && cache.get(usernameUpper).get()!=null) {
|
|
@@ -127,6 +127,50 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
return userDetails;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 多异构校验
|
|
|
+ * @param token
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String userTokenLoginDYG(String token){
|
|
|
+
|
|
|
+ MultiValueMap<String, String> requestHeader = new LinkedMultiValueMap<>();
|
|
|
+ token = token.toLowerCase(Locale.ROOT);
|
|
|
+ token = token.replace("#","");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String url="https://tgdcepc.ctg.com.cn:8443/bimp/prod-api/auth/oauth/check_token";
|
|
|
+
|
|
|
+
|
|
|
+ ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
|
|
|
+ RestTemplate restTemplate = new RestTemplate(requestFactory);
|
|
|
+
|
|
|
+ String username =null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("token"+token);
|
|
|
+ final ResponseEntity<Map> mapResponseEntity =
|
|
|
+ restTemplate.getForEntity(url+"?token="+token, Map.class);
|
|
|
+ final Map body = mapResponseEntity.getBody();
|
|
|
+
|
|
|
+ log.info("多异构获取到的body"+JSON.toJSONString(body));
|
|
|
+ log.info(JSON.toJSONString(body));
|
|
|
+
|
|
|
+ if(body!=null){
|
|
|
+ String dygUser = (String)body.get("user_name");
|
|
|
+ return dygUser;
|
|
|
+ }else{
|
|
|
+ log.error("多异构验证失败"+JSON.toJSONString(body));
|
|
|
+ throw new UsernameNotFoundException("多异构验证失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("账号或密码出现异常,请联系管理员",e);
|
|
|
+ throw new UsernameNotFoundException("账号或密码出现异常,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
* 将用户设置为对应的oauth形式
|
|
|
* @param userInfo
|
|
@@ -138,16 +182,16 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
throw new UserCheckAuthenticationException("用户已处于禁用状态,不能登录");
|
|
|
}
|
|
|
|
|
|
- Date lockTime = user.getLockTime();
|
|
|
- if(lockTime!=null && CommonConstants.USER_LOCK_LOCKED.equals(user.getLockFlag())){
|
|
|
- long endTime = new Date().getTime();
|
|
|
- long startTime = lockTime.getTime();
|
|
|
- if(endTime-startTime>1000*60*60){
|
|
|
- user.setPwderrtimes(Short.valueOf("0"));
|
|
|
- user.setLockFlag(CommonConstants.USER_LOCK_UNLOCK);
|
|
|
- SpringContextHolder.publishEvent(new UserLoginEvent(user));
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if(CommonConstants.USER_LOCK_LOCKED.equals(user.getLockFlag())){
|
|
|
throw new UserCheckAuthenticationException("账户已经被锁定,请联系管理人员,或者等待1小时后自动解锁");
|
|
@@ -188,92 +232,7 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private String userTokenLoginGis(String token){
|
|
|
|
|
|
- MultiValueMap<String, String> requestHeader = new LinkedMultiValueMap<>();
|
|
|
- token = token.toLowerCase(Locale.ROOT);
|
|
|
- token = token.replace("#","");
|
|
|
- if(token.indexOf("bearer")==-1){
|
|
|
- token = "bearer "+token;
|
|
|
- }
|
|
|
- requestHeader.add("Authorization", token);
|
|
|
- requestHeader.add("systemid","tgbcepcbim");
|
|
|
- requestHeader.add(SecurityConstants.FROM,SecurityConstants.FROM_IN);
|
|
|
- Map<String, String> urlVariables = new HashMap<>();
|
|
|
- urlVariables.put("systemid", "tgbcepcbim");
|
|
|
-
|
|
|
- HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(requestHeader);
|
|
|
-
|
|
|
- ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
|
|
|
- RestTemplate restTemplate = new RestTemplate(requestFactory);
|
|
|
-
|
|
|
- String username =null;
|
|
|
-
|
|
|
- try {
|
|
|
- final ResponseEntity<Map> mapResponseEntity =
|
|
|
- restTemplate.postForEntity(gisBimConfig.getTokenLoginUrl(), requestEntity, Map.class,urlVariables);
|
|
|
- final Map body = mapResponseEntity.getBody();
|
|
|
- log.info(JSON.toJSONString(body));
|
|
|
- Map ma = (Map)body.get("result");
|
|
|
- if(ma!=null){
|
|
|
- final String username1 = (String)ma.get("username");
|
|
|
- return username1;
|
|
|
- }else{
|
|
|
- log.error("跳转gis失败"+JSON.toJSONString(ma));
|
|
|
- throw new UsernameNotFoundException("跳转失败");
|
|
|
- }
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- log.error("账号或密码出现异常,请联系管理员",e);
|
|
|
- throw new UsernameNotFoundException("账号或密码出现异常,请联系管理员");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 多异构校验
|
|
|
- * @param token
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String userTokenLoginDYG(String token){
|
|
|
-
|
|
|
- MultiValueMap<String, String> requestHeader = new LinkedMultiValueMap<>();
|
|
|
- token = token.toLowerCase(Locale.ROOT);
|
|
|
- token = token.replace("#","");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- String url="https://tgdcepc.ctg.com.cn:8443/bimp/prod-api/auth/oauth/check_token";
|
|
|
-
|
|
|
-
|
|
|
- ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
|
|
|
- RestTemplate restTemplate = new RestTemplate(requestFactory);
|
|
|
-
|
|
|
- String username =null;
|
|
|
-
|
|
|
- try {
|
|
|
- log.info("token"+token);
|
|
|
- final ResponseEntity<Map> mapResponseEntity =
|
|
|
- restTemplate.getForEntity(url+"?token="+token, Map.class);
|
|
|
- final Map body = mapResponseEntity.getBody();
|
|
|
-
|
|
|
- log.info("多异构获取到的body"+JSON.toJSONString(body));
|
|
|
- log.info(JSON.toJSONString(body));
|
|
|
-
|
|
|
- if(body!=null){
|
|
|
- String dygUser = (String)body.get("user_name");
|
|
|
- return dygUser;
|
|
|
- }else{
|
|
|
- log.error("多异构验证失败"+JSON.toJSONString(body));
|
|
|
- throw new UsernameNotFoundException("多异构验证失败");
|
|
|
- }
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- log.error("账号或密码出现异常,请联系管理员",e);
|
|
|
- throw new UsernameNotFoundException("账号或密码出现异常,请联系管理员");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
private String useTokenLogin(String token){
|
|
@@ -287,15 +246,10 @@ public class ToFlyUserDetailsService implements UserDetailsService {
|
|
|
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(requestBody);
|
|
|
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
|
|
|
RestTemplate restTemplate = new RestTemplate(requestFactory);
|
|
|
-
|
|
|
-
|
|
|
- Map<String, String> urlVariables = new HashMap<>();
|
|
|
- urlVariables.put("systemid", "tgbcepcbim");
|
|
|
-
|
|
|
|
|
|
ResponseEntity<String> responseEntity=null;
|
|
|
try {
|
|
|
- responseEntity = restTemplate.postForEntity(mydeskConnectInfo.getGetUserInfoByToken()+"?token="+token+"&systemid="+"tgbcepcbim",requestEntity, String.class);
|
|
|
+ responseEntity = restTemplate.postForEntity(mydeskConnectInfo.getGetUserInfoByToken()+"?token="+token,requestEntity, String.class);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
log.error("token useTokenLogin 账号或密码出现异常,请联系管理员",e);
|