ad域同步其他ldap账号_搭建一套完整的LDAP体系

搭建一套生产可以用的openldap

1、搭建OpenLDAP

   1、安装Openldap 

         基本环境

         1.1、安装LDAP

         1.2、初始配置

   2、安装phpldapadmin

   3、openldap安全

         3.1、关闭匿名访问

         3.2、启用TLS证书

         3.3、其他安全

2、搭建自助密码修改服务

3、配置密码策略

4、接入相关业务

5、LDAP备份与还原

6、。。。。。。

1、搭建OpenLDAP

1、安装OpenLdap

     基本环境

应用

版本

备注

Centos

7.6

OpenLdap

2.4.44-21.el7_6.x86_64

phpldapadmin

1.2.3-10

openssl

1.0.2k-19

1.1、安装LDAP

#这里使用yum安装##1.关闭防火墙systemctl stop firewalldsystemctl disable firewalldsed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config##2.yum安装ldap组件yum install epel-release -yyum install openldap openldap-servers openldap-clients -y##3.拷贝openldap数据库cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG##4.启动ldapsystemctl start slapdsystemctl enable slapd

1.2、初始配置

####标注需要修改的地方,修改成你自己信息,然后把(#后面的文本删除掉);配置文件每行行尾千万不要有空格,不然会出现错误。#5.将111111密码加密成为SHA格式的密码slappasswd -s 111111  #这里的111111不是固定的,是可变的。你自己设置的密码${SSHA}eH4KblvoCn3C1I3svaJsD+787uKLbpkY#6.创建管理员配置文件cat <root_pass.ldifdn: olcDatabase={0}config,cn=configchangetype: modifyadd: olcRoo
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过Java使用LDAP获取AD用户和组织信息,需要使用Java的JNDI API。 以下是一个简单的Java程序,演示如何使用JNDI API连接到AD并获取用户和组织信息: ``` import java.util.*; import javax.naming.*; import javax.naming.directory.*; public class ADInfo { public static void main(String[] args) { String ldapURL = "ldap://AD服务器地址:389"; String ldapUser = "CN=LDAP查询用户,OU=xxx,DC=xxx,DC=xxx"; String ldapPassword = "LDAP查询用户密码"; String searchBase = "OU=xxx,DC=xxx,DC=xxx"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, ldapUser); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); try { DirContext ctx = new InitialDirContext(env); SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); String filter = "(objectCategory=user)"; NamingEnumeration<SearchResult> results = ctx.search(searchBase, filter, searchControls); while (results.hasMore()) { SearchResult searchResult = results.next(); Attributes attributes = searchResult.getAttributes(); Attribute attribute = attributes.get("cn"); String cn = (String) attribute.get(); System.out.println(cn); } filter = "(objectCategory=organizationalUnit)"; results = ctx.search(searchBase, filter, searchControls); while (results.hasMore()) { SearchResult searchResult = results.next(); Attributes attributes = searchResult.getAttributes(); Attribute attribute = attributes.get("ou"); String ou = (String) attribute.get(); System.out.println(ou); } ctx.close(); } catch (NamingException e) { e.printStackTrace(); } } } ``` 在上面的代码中,替换以下变量: - ldapURL:AD服务器地址和端口号 - ldapUser:用于查询ADLDAP用户的DN - ldapPassword:用于查询ADLDAP用户的密码 - searchBase:要搜索的AD的基本DN 该程序连接到AD并搜索用户和组织。它使用过滤器来限制搜索结果,只搜索用户和组织单位对象。它还使用SearchControls对象来设置搜索范围。 对于每个搜索结果,程序从属性中提取cn或ou,并将其打印到控制台上。 请注意,此代码需要在Java应用程序中包含JNDI API类路径。如果您使用Maven或Gradle之类的构建工具,则可以将以下依赖项添加到项目中: ``` <dependency> <groupId>com.sun.jndi</groupId> <artifactId>ldap</artifactId> <version>1.2.1</version> </dependency> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值