Browse Source

工具优化

master
DouDou 4 months ago
parent
commit
e345bc77c6
  1. 10
      src/main/java/com/spring/modules/sys/task/LdapAccountRefreshTask.java

10
src/main/java/com/spring/modules/sys/task/LdapAccountRefreshTask.java

@ -1,5 +1,6 @@
package com.spring.modules.sys.task;
import com.alibaba.fastjson.JSONArray;
import com.spring.common.utils.LdapReadUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -24,7 +25,9 @@ import java.util.Properties;
@Component
@EnableScheduling
public class LdapAccountRefreshTask {
private static final Logger logger = LoggerFactory.getLogger(LdapAccountRefreshTask.class);
@Value("${spring.ldap.urls}")
private String ldapUrl;
@Value("${spring.ldap.base}")
@ -49,16 +52,17 @@ public class LdapAccountRefreshTask {
env.put(Context.REFERRAL, "ignore");
LdapContext ctx = null;
//尝试解析数据
try{
// 创建DirContext对象建立与LDAP服务器的连接
ctx = new InitialLdapContext(env, null);
//调用方法读取数据
Map<String, String> ldapAccountMap = LdapReadUtils.getAllLdapAccount(ctx, ldapBase);
Map<String, String> ldapAccountMap = LdapReadUtils.getAllLdapAccount(ctx, ldapBase, redisTemplate);
logger.info("域控账号缓存的数量:"+ldapAccountMap.size());
// 数据放到redis中去
redisTemplate.opsForHash().putAll("ldapAccount", ldapAccountMap);
// redisTemplate.opsForHash().putAll("ldapAccount", ldapAccountMap);
logger.info("域控账号缓存:"+ JSONArray.toJSONString(ldapAccountMap));
} catch (NamingException | IOException e) {
logger.error("Failed to connect to the LDAP server.");

Loading…
Cancel
Save