浏览代码

token失效时间设置

vincent 3 年之前
父节点
当前提交
ca24b5985a

+ 153 - 120
maxkey-core/src/main/java/org/maxkey/persistence/redis/RedisConnection.java

@@ -1,19 +1,19 @@
 /*
  * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 
 package org.maxkey.persistence.redis;
 
@@ -25,127 +25,160 @@ import org.maxkey.util.ObjectTransformer;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.Pipeline;
 
-public class RedisConnection {
-
-	Jedis conn ;
-	RedisConnectionFactory connectionFactory;
-	
-	Pipeline pipeline ;
-	 
-	public RedisConnection() {
-		
-	}
-	
-	public RedisConnection(RedisConnectionFactory connectionFactory) {
-		this.conn=connectionFactory.open();
-		this.connectionFactory=connectionFactory;
-	}
-
-	/**
-	 * @param key
-	 * @param value
-	 */
-	public  void set(String key, String value){
-		conn.set(key, value);
-	}
-	
-
-	/**
-	 * @param key
-	 * @param value
-	 */
-	public  void setObject(String key, Serializable object){
-		set(key, ObjectTransformer.serialize(object));
-	}
-	
-	public  void setexObject(String key,int seconds, Serializable object){
-		setex(key, seconds, ObjectTransformer.serialize(object));
-	}
-	
-	/**
-	 * @param key
-	 * @param seconds
-	 * @param value
-	 */
-	public  void setex(String key,long seconds, String value){
-		if(seconds==0){
-			conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
-		}else{
-			conn.setex(key, seconds, value);
-		}
-	}
-	
-	
-	/**
-	 * @param key
-	 * @return String 
-	 */
-	public  String get(String key){
-		String value = null;
-		if(key != null){
-			value = conn.get(key);
-		}
-		return value;
-	}
-	
-	/**
-	 * @param key
-	 * @return String 
-	 */
-	public  <T> T getObject(String key){
-		String value = null;
-		if(key != null){
-			value = get(key);
-			if(value!=null){
-				return ObjectTransformer.deserialize(value);
-			}
-		}
-		return null;
-	}
-	
-	public void expire(String key,long seconds){
-		conn.expire(key, seconds);
-	}
-	
-	public void delete(String key){
-		conn.del(key);
-	}
-	
-	public  void rPush(String key, Serializable object){
-		conn.rpush(key, ObjectTransformer.serialize(object));
-	}
-	public long  lRem(String key,int count,String value){
-		return conn.lrem(key, count, value);
-	}
-	
-	
-	public List<String>  lRange(String key,int start,int end){
-		return conn.lrange(key, start, end);
-	}
-	
-	public void openPipeline(){
-		this.pipeline=conn.pipelined();
-	}
-	
-	public List<Object> closePipeline(){
-		return pipeline.syncAndReturnAll();
-	}
-	/**
+public class RedisConnection
+{
+
+    Jedis conn;
+    RedisConnectionFactory connectionFactory;
+
+    Pipeline pipeline;
+
+    public RedisConnection()
+    {
+
+    }
+
+    public RedisConnection(RedisConnectionFactory connectionFactory)
+    {
+        this.conn = connectionFactory.open();
+        this.connectionFactory = connectionFactory;
+    }
+
+    /**
+     * @param key
+     * @param value
+     */
+    public void set(String key, String value)
+    {
+        conn.set(key, value);
+    }
+
+    public void publish(String channel, String value)
+    {
+        conn.publish(channel, value);
+    }
+
+
+    /**
+     * @param key
+     * @param value
+     */
+    public void setObject(String key, Serializable object)
+    {
+        set(key, ObjectTransformer.serialize(object));
+    }
+
+    public void setexObject(String key, int seconds, Serializable object)
+    {
+        setex(key, seconds, ObjectTransformer.serialize(object));
+    }
+
+    /**
+     * @param key
+     * @param seconds
+     * @param value
+     */
+    public void setex(String key, long seconds, String value)
+    {
+        if (seconds == 0)
+        {
+            conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
+        } else
+        {
+            conn.setex(key, seconds, value);
+        }
+    }
+
+
+    /**
+     * @param key
+     * @return String
+     */
+    public String get(String key)
+    {
+        String value = null;
+        if (key != null)
+        {
+            value = conn.get(key);
+        }
+        return value;
+    }
+
+    /**
+     * @param key
+     * @return String
+     */
+    public <T> T getObject(String key)
+    {
+        String value = null;
+        if (key != null)
+        {
+            value = get(key);
+            if (value != null)
+            {
+                return ObjectTransformer.deserialize(value);
+            }
+        }
+        return null;
+    }
+
+    public void expire(String key, long seconds)
+    {
+        conn.expire(key, seconds);
+    }
+
+    public void delete(String key)
+    {
+        conn.del(key);
+    }
+
+    public void rPush(String key, Serializable object)
+    {
+        conn.rpush(key, ObjectTransformer.serialize(object));
+    }
+
+    public long lRem(String key, int count, String value)
+    {
+        return conn.lrem(key, count, value);
+    }
+
+
+    public List<String> lRange(String key, int start, int end)
+    {
+        return conn.lrange(key, start, end);
+    }
+
+    public void openPipeline()
+    {
+        this.pipeline = conn.pipelined();
+    }
+
+    public List<Object> closePipeline()
+    {
+        return pipeline.syncAndReturnAll();
+    }
+
+    /**
      * 释放jedis资源
+     *
      * @param jedis
      */
-	public  void close() {
-        if (conn != null) {
-        	connectionFactory.close(conn);
+    public void close()
+    {
+        if (conn != null)
+        {
+            connectionFactory.close(conn);
         }
     }
 
-	public Jedis getConn() {
-		return conn;
-	}
+    public Jedis getConn()
+    {
+        return conn;
+    }
+
+    public void setConn(Jedis conn)
+    {
+        this.conn = conn;
+    }
 
-	public void setConn(Jedis conn) {
-		this.conn = conn;
-	}
-	
 }

+ 7 - 0
maxkey-identitys/maxkey-synchronizers-dingding/src/main/java/org/maxkey/synchronizer/dingding/DingdingUsersService.java

@@ -38,6 +38,9 @@ import com.dingtalk.api.response.OapiV2UserListResponse;
 import com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse;
 import com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @Service
 public class DingdingUsersService implements ISynchronizerService
 {
@@ -77,6 +80,7 @@ public class DingdingUsersService implements ISynchronizerService
 
                 if (rsp.getErrcode() == 0)
                 {
+                    List<UserInfo> userInfoList = new ArrayList<UserInfo>();
                     for (ListUserResponse user : rsp.getResult().getList())
                     {
                         _logger.info("name : " + user.getName() + " , " + user.getLoginId() + " , " + user.getUserid());
@@ -95,6 +99,7 @@ public class DingdingUsersService implements ISynchronizerService
                         } else
                         {
                             userInfoService.insert(userInfo);
+//                            userInfoService.syncUser(userInfo);
                             //绑定用户
                             SocialsAssociate socialsAssociate = new SocialsAssociate();
                             socialsAssociate.setProvider("dingtalk");
@@ -104,6 +109,8 @@ public class DingdingUsersService implements ISynchronizerService
                             socialsAssociateService.merge(socialsAssociate);
                             _logger.info("bind user  " + socialsAssociate);
                         }
+                        userInfoList.add(userInfo);
+                        userInfoService.syncUser(userInfoList);
                         _logger.info("userInfo " + userInfo);
                     }
                 }

+ 384 - 282
maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java

@@ -1,23 +1,24 @@
 /*
  * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 
 package org.maxkey.persistence.service;
 
 
+import com.alibaba.fastjson.JSONObject;
 import org.apache.mybatis.jpa.persistence.JpaBaseService;
 import org.maxkey.constants.ConstantsStatus;
 import org.maxkey.crypto.ReciprocalUtils;
@@ -30,377 +31,478 @@ import org.maxkey.persistence.kafka.KafkaIdentityAction;
 import org.maxkey.persistence.kafka.KafkaIdentityTopic;
 import org.maxkey.persistence.kafka.KafkaPersistService;
 import org.maxkey.persistence.mapper.UserInfoMapper;
+import org.maxkey.persistence.redis.RedisConnection;
+import org.maxkey.persistence.redis.RedisConnectionFactory;
 import org.maxkey.util.DateUtils;
 import org.maxkey.util.StringUtils;
 import org.maxkey.web.WebContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.data.redis.connection.ReactiveStreamCommands;
+import org.springframework.http.*;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Repository;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.List;
 
 
 /**
  * @author Crystal.Sea
- *
  */
 @Repository
-public class UserInfoService extends JpaBaseService<UserInfo> {
-	final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
-	
-	@Autowired
-	private PasswordEncoder passwordEncoder;
-	
-	@Autowired
-	PasswordPolicyValidator passwordPolicyValidator;
-	
-	@Autowired
-	KafkaPersistService kafkaPersistService;
-	
-	 @Autowired
-	 protected JdbcTemplate jdbcTemplate;
-	 
-	 AccountsService accountsService;
-	
-	public UserInfoService() {
-		super(UserInfoMapper.class);
-	}
-
-	/* (non-Javadoc)
-	 * @see com.connsec.db.service.BaseService#getMapper()
-	 */
-	@Override
-	public UserInfoMapper getMapper() {
-		return (UserInfoMapper)super.getMapper();
-	}
-	
-    public boolean insert(UserInfo userInfo) {
+public class UserInfoService extends JpaBaseService<UserInfo>
+{
+    final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
+
+    @Autowired
+    private PasswordEncoder passwordEncoder;
+
+    @Autowired
+    PasswordPolicyValidator passwordPolicyValidator;
+
+    @Autowired
+    KafkaPersistService kafkaPersistService;
+
+    @Autowired
+    protected JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    RedisConnectionFactory redisConnectionFactory;
+
+    AccountsService accountsService;
+
+    public UserInfoService()
+    {
+        super(UserInfoMapper.class);
+    }
+
+    /* (non-Javadoc)
+     * @see com.connsec.db.service.BaseService#getMapper()
+     */
+    @Override
+    public UserInfoMapper getMapper()
+    {
+        return (UserInfoMapper) super.getMapper();
+    }
+
+    public boolean insert(UserInfo userInfo)
+    {
         userInfo = passwordEncoder(userInfo);
-        if (super.insert(userInfo)) {
-            if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
+        if (super.insert(userInfo))
+        {
+            if (kafkaPersistService.getApplicationConfig().isKafkaSupport())
+            {
                 UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
                 kafkaPersistService.send(
-                        KafkaIdentityTopic.USERINFO_TOPIC, 
+                        KafkaIdentityTopic.USERINFO_TOPIC,
                         loadUserInfo,
                         KafkaIdentityAction.CREATE_ACTION);
             }
-            
+
             return true;
         }
 
         return false;
     }
-	
-    public boolean update(UserInfo userInfo) {
+
+    public boolean update(UserInfo userInfo)
+    {
         userInfo = passwordEncoder(userInfo);
-        if (super.update(userInfo)) {
-            if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
+        if (super.update(userInfo))
+        {
+            if (kafkaPersistService.getApplicationConfig().isKafkaSupport())
+            {
                 UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
                 accountUpdate(loadUserInfo);
                 kafkaPersistService.send(
-                        KafkaIdentityTopic.USERINFO_TOPIC, 
+                        KafkaIdentityTopic.USERINFO_TOPIC,
                         loadUserInfo,
                         KafkaIdentityAction.UPDATE_ACTION);
             }
-            
+
             changePasswordProvisioning(userInfo);
             return true;
         }
         return false;
     }
-	
-	public boolean delete(UserInfo userInfo) {
-	    UserInfo loadUserInfo = null;
-	    if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
-	        loadUserInfo = loadUserRelated(userInfo.getId());
-	    }
-	    
-		if( super.delete(userInfo)){
-			kafkaPersistService.send(
-		            KafkaIdentityTopic.USERINFO_TOPIC, 
-		            loadUserInfo, 
-		            KafkaIdentityAction.DELETE_ACTION);
-			accountUpdate(loadUserInfo);
-			 return true;
-		}
-		return false;
-	}
-	
+
+    public boolean delete(UserInfo userInfo)
+    {
+        UserInfo loadUserInfo = null;
+        if (kafkaPersistService.getApplicationConfig().isKafkaSupport())
+        {
+            loadUserInfo = loadUserRelated(userInfo.getId());
+        }
+
+        if (super.delete(userInfo))
+        {
+            kafkaPersistService.send(
+                    KafkaIdentityTopic.USERINFO_TOPIC,
+                    loadUserInfo,
+                    KafkaIdentityAction.DELETE_ACTION);
+            accountUpdate(loadUserInfo);
+            return true;
+        }
+        return false;
+    }
+
     //更新账号状态
-    public void accountUpdate(UserInfo userInfo) {
-        if(userInfo.getStatus() != ConstantsStatus.ACTIVE) {
-            if(accountsService==null) {
-                accountsService = 
-                       WebContext.getBean("accountsService",AccountsService.class); 
+    public void accountUpdate(UserInfo userInfo)
+    {
+        if (userInfo.getStatus() != ConstantsStatus.ACTIVE)
+        {
+            if (accountsService == null)
+            {
+                accountsService =
+                        WebContext.getBean("accountsService", AccountsService.class);
             }
-            Accounts queryAcount =new Accounts();
+            Accounts queryAcount = new Accounts();
             queryAcount.setUserId(userInfo.getId());
-            for (Accounts acount : accountsService.query(queryAcount)) {
+            for (Accounts acount : accountsService.query(queryAcount))
+            {
                 acount.setStatus(ConstantsStatus.INACTIVE);
                 accountsService.update(acount);
             }
         }
     }
 
-	public UserInfo loadUserRelated(String userId) {
-	    UserInfo loadUserInfo =this.get(userId);
-	    loadUserInfo.setDepts(getMapper().loadDeptsByUserId(userId));
-	    loadUserInfo.setAdjoints(getMapper().loadAdjointsByUserId(userId));
-	    return loadUserInfo;
-	}
-	
-	public boolean updateGridList(String gridList) {
-	    try {
-    	    if (gridList != null && !gridList.equals("")) {
+    public UserInfo loadUserRelated(String userId)
+    {
+        UserInfo loadUserInfo = this.get(userId);
+        loadUserInfo.setDepts(getMapper().loadDeptsByUserId(userId));
+        loadUserInfo.setAdjoints(getMapper().loadAdjointsByUserId(userId));
+        return loadUserInfo;
+    }
+
+    public boolean updateGridList(String gridList)
+    {
+        try
+        {
+            if (gridList != null && !gridList.equals(""))
+            {
                 WebContext.getUserInfo().setGridList(Integer.parseInt(gridList));
                 getMapper().updateGridList(WebContext.getUserInfo());
             }
-	    }catch(Exception e) {
+        } catch (Exception e)
+        {
             e.printStackTrace();
             return false;
         }
-	    return true;
-	}
-	
-	
-	public boolean updateProtectedApps(UserInfo userinfo) {
-		try {
-			if(WebContext.getUserInfo() != null) {
-				userinfo.setModifiedBy(WebContext.getUserInfo().getId());
-			}
-			userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-			return getMapper().updateProtectedApps(userinfo) > 0;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return false;
-	}
-
-	public UserInfo loadByUsername(String username) {
-		return getMapper().loadByUsername(username);
-	}
-	
-	public UserInfo loadByAppIdAndUsername(String appId,String username){
-		try {
-			UserInfo userinfo = new UserInfo();
-			userinfo.setUsername(username);
-			return getMapper().loadByAppIdAndUsername(userinfo) ;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-	
-
-	public void logisticDeleteAllByCid(String cid){
-		try {
-			 getMapper().logisticDeleteAllByCid(cid);
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-	
-	public UserInfo passwordEncoder(UserInfo userInfo) {
-	    //密码不为空,则需要进行加密处理
-	    if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
-    	    String password = passwordEncoder.encode(userInfo.getPassword());
+        return true;
+    }
+
+
+    public boolean updateProtectedApps(UserInfo userinfo)
+    {
+        try
+        {
+            if (WebContext.getUserInfo() != null)
+            {
+                userinfo.setModifiedBy(WebContext.getUserInfo().getId());
+            }
+            userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
+            return getMapper().updateProtectedApps(userinfo) > 0;
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public UserInfo loadByUsername(String username)
+    {
+        return getMapper().loadByUsername(username);
+    }
+
+    public UserInfo loadByAppIdAndUsername(String appId, String username)
+    {
+        try
+        {
+            UserInfo userinfo = new UserInfo();
+            userinfo.setUsername(username);
+            return getMapper().loadByAppIdAndUsername(userinfo);
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    public void logisticDeleteAllByCid(String cid)
+    {
+        try
+        {
+            getMapper().logisticDeleteAllByCid(cid);
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    public UserInfo passwordEncoder(UserInfo userInfo)
+    {
+        //密码不为空,则需要进行加密处理
+        if (userInfo.getPassword() != null && !userInfo.getPassword().equals(""))
+        {
+            String password = passwordEncoder.encode(userInfo.getPassword());
             userInfo.setDecipherable(ReciprocalUtils.encode(PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), userInfo.getPassword())));
-            _logger.debug("decipherable : "+userInfo.getDecipherable());
+            _logger.debug("decipherable : " + userInfo.getDecipherable());
             userInfo.setPassword(password);
             userInfo.setPasswordLastSetTime(DateUtils.getCurrentDateTimeAsString());
-            
+
             userInfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-	    }
+        }
         return userInfo;
-	}
-	
-	
-	public boolean changePassword(  String oldPassword,
-                                    String newPassword,
-                                    String confirmPassword,
-                                    int passwordSetType) {
-		try {
-		    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, "");
-	        UserInfo userInfo = WebContext.getUserInfo();
-	        UserInfo changeUserInfo = new UserInfo();
-	        changeUserInfo.setUsername(userInfo.getUsername());
-	        changeUserInfo.setPassword(newPassword);
-	        changeUserInfo.setId(userInfo.getId());
-	        changeUserInfo.setDecipherable(userInfo.getDecipherable());
-	        changeUserInfo.setPasswordSetType(passwordSetType);
-	        
-	        if(newPassword.equals(confirmPassword)){
-	            if(oldPassword==null || 
-	                    passwordEncoder.matches(oldPassword, userInfo.getPassword())){
-	                if(changePassword(changeUserInfo,true) ){
-	                    userInfo.setPassword(changeUserInfo.getPassword());
+    }
+
+
+    public boolean changePassword(String oldPassword,
+                                  String newPassword,
+                                  String confirmPassword,
+                                  int passwordSetType)
+    {
+        try
+        {
+            WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, "");
+            UserInfo userInfo = WebContext.getUserInfo();
+            UserInfo changeUserInfo = new UserInfo();
+            changeUserInfo.setUsername(userInfo.getUsername());
+            changeUserInfo.setPassword(newPassword);
+            changeUserInfo.setId(userInfo.getId());
+            changeUserInfo.setDecipherable(userInfo.getDecipherable());
+            changeUserInfo.setPasswordSetType(passwordSetType);
+
+            if (newPassword.equals(confirmPassword))
+            {
+                if (oldPassword == null ||
+                        passwordEncoder.matches(oldPassword, userInfo.getPassword()))
+                {
+                    if (changePassword(changeUserInfo, true))
+                    {
+                        userInfo.setPassword(changeUserInfo.getPassword());
                         userInfo.setDecipherable(changeUserInfo.getDecipherable());
-	                    return true;
-	                }
-	                return false;	               
-	            }else {
-	                if(oldPassword!=null &&
-	                        passwordEncoder.matches(newPassword, userInfo.getPassword())) {
-	                    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, 
-	                            WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH"));
-	                }else {
-	                    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, 
-	                        WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH"));
-	                }
-	            }
-	        }else {
-	            WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, 
-	                    WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH"));
-	        }
-		 } catch (Exception e) {
-             e.printStackTrace();
-         }    
-		    
-		return false;
-	}
-	
-    public boolean changePassword(UserInfo changeUserInfo,boolean passwordPolicy) {
-        try {
+                        return true;
+                    }
+                    return false;
+                } else
+                {
+                    if (oldPassword != null &&
+                            passwordEncoder.matches(newPassword, userInfo.getPassword()))
+                    {
+                        WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                                WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH"));
+                    } else
+                    {
+                        WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                                WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH"));
+                    }
+                }
+            } else
+            {
+                WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                        WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH"));
+            }
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+        return false;
+    }
+
+    public boolean changePassword(UserInfo changeUserInfo, boolean passwordPolicy)
+    {
+        try
+        {
             _logger.debug("decipherable old : " + changeUserInfo.getDecipherable());
             _logger.debug("decipherable new : " + ReciprocalUtils.encode(PasswordReciprocal.getInstance()
                     .rawPassword(changeUserInfo.getUsername(), changeUserInfo.getPassword())));
 
-            if (passwordPolicy && passwordPolicyValidator.validator(changeUserInfo) == false) {
+            if (passwordPolicy && passwordPolicyValidator.validator(changeUserInfo) == false)
+            {
                 return false;
             }
 
-            if (WebContext.getUserInfo() != null) {
+            if (WebContext.getUserInfo() != null)
+            {
                 changeUserInfo.setModifiedBy(WebContext.getUserInfo().getId());
             }
 
             changeUserInfo = passwordEncoder(changeUserInfo);
 
-            if (getMapper().changePassword(changeUserInfo) > 0) {
+            if (getMapper().changePassword(changeUserInfo) > 0)
+            {
                 changePasswordProvisioning(changeUserInfo);
                 return true;
             }
             return false;
 
-        } catch (Exception e) {
+        } catch (Exception e)
+        {
             e.printStackTrace();
         }
 
         return false;
     }
-	
-	public String randomPassword() {
-	    return passwordPolicyValidator.generateRandomPassword();
-	}
-	
-	public void changePasswordProvisioning(UserInfo userInfo) {
-	    if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
-    	    ChangePassword changePassword=new ChangePassword();
+
+    public String randomPassword()
+    {
+        return passwordPolicyValidator.generateRandomPassword();
+    }
+
+    public void changePasswordProvisioning(UserInfo userInfo)
+    {
+        if (userInfo.getPassword() != null && !userInfo.getPassword().equals(""))
+        {
+            ChangePassword changePassword = new ChangePassword();
             changePassword.setId(userInfo.getId());
             changePassword.setUserId(userInfo.getId());
             changePassword.setUsername(userInfo.getUsername());
             changePassword.setDecipherable(userInfo.getDecipherable());
             changePassword.setPassword(userInfo.getPassword());
             kafkaPersistService.send(
-                    KafkaIdentityTopic.PASSWORD_TOPIC, 
-                    changePassword, 
+                    KafkaIdentityTopic.PASSWORD_TOPIC,
+                    changePassword,
                     KafkaIdentityAction.PASSWORD_ACTION);
-	    }
-	}
-	
-	public boolean changeAppLoginPassword(UserInfo userinfo) {
-		try {
-			if(WebContext.getUserInfo() != null) {
-				userinfo.setModifiedBy(WebContext.getUserInfo().getId());
-			}
-			userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-			return getMapper().changeAppLoginPassword(userinfo) > 0;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return false;
-	}
-	
-	
-	/**
-	 * 锁定用户:islock:1 用户解锁 2 用户锁定
-	 * @param userInfo
-	 */
-	public void locked(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				userInfo.setIsLocked(ConstantsStatus.STOP);
-				getMapper().locked(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * 用户登录成功后,重置错误密码次数和解锁用户
-	 * @param userInfo
-	 */
-	public void unlock(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				userInfo.setIsLocked(ConstantsStatus.START);
-				userInfo.setBadPasswordCount(0);
-				getMapper().unlock(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * 更新错误密码次数
-	 * @param userInfo
-	 */
-	public void updateBadPasswordCount(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				int updateBadPWDCount = userInfo.getBadPasswordCount() + 1;
-				userInfo.setBadPasswordCount(updateBadPWDCount);
-				getMapper().updateBadPWDCount(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
- 
-	
-	public boolean changeSharedSecret(UserInfo userInfo){
-		return getMapper().changeSharedSecret(userInfo)>0;
-	}
-	
-	public boolean changePasswordQuestion(UserInfo userInfo){
-		return getMapper().changePasswordQuestion(userInfo)>0;
-	}
-	
-	public boolean changeAuthnType(UserInfo userInfo){
-		return getMapper().changeAuthnType(userInfo)>0;
-	}
-	
-	public boolean changeEmail(UserInfo userInfo){
-		return getMapper().changeEmail(userInfo)>0;
-	}
-	
-	public boolean changeMobile(UserInfo userInfo){
-		return getMapper().changeMobile(userInfo)>0;
-	}
-	
-    public UserInfo queryUserInfoByEmailMobile(String emailMobile) {
+        }
+    }
+
+    public boolean changeAppLoginPassword(UserInfo userinfo)
+    {
+        try
+        {
+            if (WebContext.getUserInfo() != null)
+            {
+                userinfo.setModifiedBy(WebContext.getUserInfo().getId());
+            }
+            userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
+            return getMapper().changeAppLoginPassword(userinfo) > 0;
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+
+    /**
+     * 锁定用户:islock:1 用户解锁 2 用户锁定
+     *
+     * @param userInfo
+     */
+    public void locked(UserInfo userInfo)
+    {
+        try
+        {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId()))
+            {
+                userInfo.setIsLocked(ConstantsStatus.STOP);
+                getMapper().locked(userInfo);
+            }
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 用户登录成功后,重置错误密码次数和解锁用户
+     *
+     * @param userInfo
+     */
+    public void unlock(UserInfo userInfo)
+    {
+        try
+        {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId()))
+            {
+                userInfo.setIsLocked(ConstantsStatus.START);
+                userInfo.setBadPasswordCount(0);
+                getMapper().unlock(userInfo);
+            }
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 更新错误密码次数
+     *
+     * @param userInfo
+     */
+    public void updateBadPasswordCount(UserInfo userInfo)
+    {
+        try
+        {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId()))
+            {
+                int updateBadPWDCount = userInfo.getBadPasswordCount() + 1;
+                userInfo.setBadPasswordCount(updateBadPWDCount);
+                getMapper().updateBadPWDCount(userInfo);
+            }
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    public void syncUser(List<UserInfo> userInfos)
+    {
+        _logger.debug("redis open ...");
+        // redis 连接
+        RedisConnection redisConnection = redisConnectionFactory.getConnection();
+        redisConnection.set("syncUser",JSONObject.toJSONString(userInfos));
+        redisConnection.publish("syncUser",JSONObject.toJSONString(userInfos));
+        _logger.debug("redis close ...");
+        redisConnection.close();
+    }
+
+
+    public boolean changeSharedSecret(UserInfo userInfo)
+    {
+        return getMapper().changeSharedSecret(userInfo) > 0;
+    }
+
+    public boolean changePasswordQuestion(UserInfo userInfo)
+    {
+        return getMapper().changePasswordQuestion(userInfo) > 0;
+    }
+
+    public boolean changeAuthnType(UserInfo userInfo)
+    {
+        return getMapper().changeAuthnType(userInfo) > 0;
+    }
+
+    public boolean changeEmail(UserInfo userInfo)
+    {
+        return getMapper().changeEmail(userInfo) > 0;
+    }
+
+    public boolean changeMobile(UserInfo userInfo)
+    {
+        return getMapper().changeMobile(userInfo) > 0;
+    }
+
+    public UserInfo queryUserInfoByEmailMobile(String emailMobile)
+    {
         return getMapper().queryUserInfoByEmailMobile(emailMobile);
     }
-    
-    public int updateProfile(UserInfo userInfo){
-        
+
+    public int updateProfile(UserInfo userInfo)
+    {
+
         return getMapper().updateProfile(userInfo);
     }
 
-    public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator) {
+    public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator)
+    {
         this.passwordPolicyValidator = passwordPolicyValidator;
     }
 

+ 5 - 3
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ThirdLoginController.java

@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
 import org.springframework.web.bind.annotation.*;
 import org.maxkey.util.RetResult;
 
@@ -102,8 +103,8 @@ public class ThirdLoginController
                 redisConnection.delete(userInfo.getId());
                 redisConnection.delete(oldToken);
             }
-            redisConnection.setex(userInfo.getId(), 1800, token);
-            redisConnection.setex(token, 1800, JSON.toJSONString(userInfo));
+            redisConnection.setex(userInfo.getId(), 60 * 60 * 24 * 7, token);
+            redisConnection.setex(token, 60 * 60 * 24 * 7, JSON.toJSONString(userInfo));
             redisConnection.close();
             _logger.debug("token >>>" + token);
             result.setData(data);
@@ -135,10 +136,11 @@ public class ThirdLoginController
         // 1天
         RedisConnection redisConnection = redisConnectionFactory.getConnection();
         String userInfo = redisConnection.get(token);
+        Jackson2JsonRedisSerializer<UserInfo> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<UserInfo>(UserInfo.class);
         UserInfo user = JSONObject.parseObject(userInfo,UserInfo.class);
         result.put("token",token);
         result.put("user",user);
-        redisConnection.setex(ticket, 60 * 60 * 24 * 7, result.toJSONString());
+        redisConnection.setex(ticket, 60 * 60 * 24 * 1,JSON.toJSONString(user));
         redisConnection.close();
         result = new JSONObject();
         result.put("ticket",ticket);

+ 4 - 5
maxkey-webs/maxkey-web-maxkey/src/main/resources/application-http.properties

@@ -16,7 +16,7 @@
 #spring.profiles.active=http                                               #
 ############################################################################
 #server port
-server.port                                     =8080
+server.port                                     =8888
 #session default 1800
 #1800s =30m
 #28800s=8h
@@ -119,15 +119,14 @@ mybatis.table-column-case                       =lowercase
 ############################################################################
 #redis server  configuration                                               #
 ############################################################################
-spring.redis.host                               =${REDIS_HOST:61.132.52.38}
-spring.redis.port                               =${REDIS_PORT:20003}
-spring.redis.password                           =${REDIS_PWD:}
+spring.redis.host                               =localhost
+spring.redis.port                               =6379
+spring.redis.password                           =
 spring.redis.timeout                            =10000
 spring.redis.jedis.pool.max-wait                =1000
 spring.redis.jedis.pool.max-idle                =200
 spring.redis.lettuce.pool.max-active            =-1
 spring.redis.lettuce.pool.min-idle              =0
-spring.redis.database                           =0
 
 ############################################################################
 #mail configuration                                                        #

+ 3 - 3
maxkey-webs/maxkey-web-mgt/src/main/resources/application-http.properties

@@ -103,9 +103,9 @@ mybatis.table-column-case                       =lowercase
 ############################################################################
 #redis server  configuration                                               #
 ############################################################################
-spring.redis.host                               =${REDIS_HOST:61.132.52.38}
-spring.redis.port                               =${REDIS_PORT:20003}
-spring.redis.password                           =${REDIS_PWD:password}
+spring.redis.host                               =localhost
+spring.redis.port                               =6379
+spring.redis.password                           =
 spring.redis.timeout                            =10000
 spring.redis.jedis.pool.max-wait                =1000
 spring.redis.jedis.pool.max-idle                =200