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

Loading…
Cancel
Save