ldap 字段解释(JavaUnboundID内存LDAP服务支持)
ldap 字段解释(JavaUnboundID内存LDAP服务支持)
2024-09-26 11:02:52  作者:诂莋堅強  网址:https://m.xinb2b.cn/life/bmi424147.html

轻量目录访问协议,一般都简称为LDAP它是基于X.500标准的,可根据需要定制与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到,今天小编就来说说关于ldap 字段解释?下面更多详细答案一起来看看吧!


ldap 字段解释

LDAP(Lightweight Directory Access Protocol):

轻量目录访问协议,一般都简称为LDAP。它是基于X.500标准的,可根据需要定制。与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的。LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到。

LDAP的主要应用场景:

1、网络服务:DNS服务;2、统一认证服务;3、Linux PAM (ssh, login, cvs. . . );4、Apache访问控制5、各种服务登录(ftpd, php based, perl based, python based. . . );6、个人信息类,如地址簿;7、服务器信息,如帐号管理、邮件服务等;

UnboundID LDAP SDK:

提供了一套快速、强大、用户友好并且开源的Java API来与LDAP目录服务器交互,与其它基于Java的LDAP APIs相比,它具有更好的性能、更易于使用,功能更多,而且还是唯一个不断有活跃开发和增强的SDK。官网地址:https://www.ldap.com/unboundid-ldap-sdk-for-java

代码案例:

pom.xml

<!--使用unboundid嵌入式LDAP--><dependency> <groupId>com.unboundid</groupId> <artifactId>unboundid-ldapsdk</artifactId> <version>3.2.0</version></dependency>

package com.what21.ldap.server;import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;import com.unboundid.ldap.sdk.LDAPException;import org.springframework.util.StringUtils;public class LdapServerConfig { private InMemoryDirectoryServerConfig serverConfig; private String userBaseDN; private String userDN; public LdapServerConfig(String baseDn,String userBaseDN,String userId){ if(!StringUtils.isEmpty(userBaseDN) && userBaseDN.endsWith(",")){ userDN = "uid=" userId userBaseDN; }else{ userDN = "uid=" userId "," userBaseDN; } String[] ldapDnArray = { baseDn, userBaseDN, userDN }; try { serverConfig = new InMemoryDirectoryServerConfig(ldapDnArray); } catch (LDAPException e) { e.printStackTrace(); } } public InMemoryDirectoryServerConfig getLdapServerConfig(){ return serverConfig; } public String getUserBaseDN() { return userBaseDN; } public String getUserDN() { return userDN; } public void setUserDN(String userDN) { this.userDN = userDN; }}

package com.what21.ldap.server;import com.unboundid.ldap.listener.InMemoryListenerConfig;import com.unboundid.ldap.sdk.LDAPException;public class LdapListenerConfig{ private InMemoryListenerConfig config; public LdapListenerConfig(int port){ this("default",port); } public LdapListenerConfig(String name,int port){ try { this.config = new InMemoryListenerConfig(name,null,port,null,null,null); } catch (LDAPException e) { e.printStackTrace(); } } public InMemoryListenerConfig getInMemoryListenerConfig(){ return config; }}

package com.what21.ldap.server;import lombok.extern.slf4j.Slf4j;import com.unboundid.ldap.listener.interceptor.InMemoryInterceptedSimpleBindRequest;import com.unboundid.ldap.listener.interceptor.InMemoryOperationInterceptor;import com.unboundid.ldap.sdk.LDAPException;import com.unboundid.ldap.sdk.ResultCode;import com.unboundid.ldap.sdk.SimpleBindRequest;@Slf4jpublic class LdapOptInterceptor extends InMemoryOperationInterceptor { String userBaseDN; String userDN; String userId; String passwd; public LdapOptInterceptor(String userBaseDN, String userDN, String userId, String passwd) { this.userBaseDN = userBaseDN; this.userDN = userDN; this.userId = userId; this.passwd = passwd; } @Override public void processSimpleBindRequest(InMemoryInterceptedSimpleBindRequest request) throws LDAPException { String bindDN = request.getRequest().getBindDN(); String passwd = request.getRequest().getPassword().stringValue(); log.debug("request bindDN ->" bindDN); log.debug("request passwd ->" passwd); if (bindDN.contains(userBaseDN)) { bindDN = bindDN.replace("," userBaseDN, ""); } if (bindDN.contains("=")) { try { bindDN = bindDN.substring(bindDN.indexOf("="), bindDN.length()); } catch (Exception e) { } } log.debug("do treatment bindDN ->" bindDN); String result = "-1"; // 假设认证成功 result = "1000"; // 认证逻辑 if ("1000".equals(result)) { request.setRequest(new SimpleBindRequest(this.userDN, this.passwd)); } else if ("1001".equals(result)) { throw new LDAPException(ResultCode.AUTH_UNKNOWN, "Unable to bind user,because the provided password was incorrect."); } else if ("1002".equals(result)) { throw new LDAPException(ResultCode.AUTH_UNKNOWN, "Unable to bind user,because user is not authorized."); } else { throw new LDAPException(ResultCode.AUTH_UNKNOWN, "Unable to bind user,because unknown error."); } super.processSimpleBindRequest(request); }}

package com.what21.ldap.server;import com.unboundid.ldap.listener.InMemoryDirectoryServer;import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;import com.unboundid.ldap.sdk.Attribute;import com.unboundid.ldap.sdk.LDAPException;public class LdapMemoryServer { private int port; private String baseDN; private String userBaseDN; private final String userId = "default"; private final String passwd = "default"; private InMemoryDirectoryServer dirServer; public LdapMemoryServer(int port, String baseDN, String userBaseDN) { this.port = port; this.baseDN = baseDN; this.userBaseDN = userBaseDN; } public void startServer() { // LDAPServer配置 LdapServerConfig serverConfig = new LdapServerConfig(baseDN, userBaseDN, userId); // 监听配置 LdapListenerConfig listenerConfig = new LdapListenerConfig(port); String userDN = serverConfig.getUserDN(); // 监听 LdapOptInterceptor interceptor = new LdapOptInterceptor(userBaseDN, userDN, userId, passwd); // LDAP try { InMemoryDirectoryServerConfig config = serverConfig.getLdapServerConfig(); config.addInMemoryOperationInterceptor(interceptor); config.setListenerConfigs(listenerConfig.getInMemoryListenerConfig()); config.setSchema(null); dirServer = new InMemoryDirectoryServer(config); // 添加属性 dirServer.add(userDN, getUidAttr(), getPasswdAttr()); dirServer.startListening(); } catch (LDAPException e) { e.printStackTrace(); } } private Attribute getUidAttr() { return new Attribute("uid", passwd); } private Attribute getPasswdAttr() { return new Attribute("userPassword", userId); } public void stopServer() { if (dirServer != null) { dirServer.shutDown(true); } } public static void main(String[] args) { int port = 1389; String baseDN = "dc=what21,dc=com"; String userBaseDN = "ou=users" "," baseDN; LdapMemoryServer server = new LdapMemoryServer(port, baseDN, userBaseDN); server.startServer(); try { Thread.sleep(10000000L); } catch (InterruptedException e) { e.printStackTrace(); } }}

客户端认证实现:

package com.what21.ldap.client;import java.util.Properties;import javax.naming.NamingException;import javax.naming.ldap.InitialLdapContext;public class LdapClientAuthen { public static InitialLdapContext auth(String url, String domain, String name, String passwd) { Properties mEnv = new Properties(); mEnv.put(InitialLdapContext.AUTHORITATIVE, "true"); mEnv.put(InitialLdapContext.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); mEnv.put(InitialLdapContext.PROVIDER_URL, url); mEnv.put(InitialLdapContext.SECURITY_AUTHENTICATION, "simple"); mEnv.put(InitialLdapContext.SECURITY_PRINCIPAL, name); mEnv.put(InitialLdapContext.SECURITY_CREDENTIALS, passwd); try { return new InitialLdapContext(mEnv, null); } catch (NamingException e) { e.printStackTrace(); } return null; } public static void main(String[] args) { String url = "ldap://127.0.0.1:1389"; String domain = "what21.com"; String username = "uid=account,ou=users,dc=what21,dc=com"; String passwd = "password"; InitialLdapContext content = auth(url, domain, username, passwd); if(content!=null){ System.out.println("认证成功:" content); }else{ System.out.println("认证失败:" content); } try { content.close(); } catch (Exception e) { e.printStackTrace(); } }}

  • 女人梦见到处都是水什么兆头(梦见到处都是水预示什么兆头)
  • 2024-09-27梦见到处都是水预示什么兆头女人梦见到处都是水,预示近期梦者的运势很好,可能是最近会获得一笔财富,会因此而特别的高兴,好运也可能就此开始怀孕的女人梦见到处都是水,预示生女,忌动土,饮食小心做生意的女人梦见到处都是水,代表起初要先。
  • 浪漫语句爱情句子说说(浪漫语句爱情句子)
  • 2024-09-27浪漫语句爱情句子与你的相识,我才知道缘分是多么的奇妙,让我来照顾你,我会珍惜我们遇见的每一分每一秒我遇见你,我记得你,这座城市天生就适合恋爱,你天生就适合我的灵魂我爱你,所以我的眼里只能看见你,我爱你,所以我的世界只。
  • 什么样的人生观才是正确的人生观
  • 2024-09-27什么样的人生观才是正确的人生观1、首先应该是对自己人生的目标、价值、意义做个正确的定位.我们的人生目标该是积极的,向上的,我们应该做个有价值的人,我们人生的意义应该对自己甚至他人产生影响,我们的人生不是碌碌无为的,不是灰暗的,不是。
  • 大瓦什么意思(都瓦什么意思)
  • 2024-09-27都瓦什么意思都瓦什么意思1、“都瓦”(祈祷与祝福)2、作“都瓦”时把两只手伸开并在一起,手心朝脸默祷几秒种或者更长些,然后轻轻从上到下摸一下脸(这一动作在维吾尔民间习俗里表示吉祥如意),“都瓦”就完毕了默祷的时间。
  • 大头绿衣斗僵尸超清(大头绿衣斗僵尸小时候又菜又爱看)
  • 2024-09-27大头绿衣斗僵尸小时候又菜又爱看让他把你的棺木挖出来,放在一块至阴至寒的地方,一般至阴至寒地方泥土是黑色,不仅寸草不生,在军中最适合暴走尸土,所以也出了养尸地棺木出来之后,要将它法藏,所谓法藏,就是把棺材立起来放,还要记住棺材一定要。
  • 华为总监孟晚舟事件结果怎么样? 孟晚舟出任华为轮值董事长
  • 2024-09-27华为总监孟晚舟事件结果怎么样? 孟晚舟出任华为轮值董事长读创/深圳商报记者陈姝4月1日,华为发布公告,完成了监事会换届选举,选举产生了监事会主席、监事,以及候补监事其官网显示,华为副董事长、CFO孟晚舟出任轮值董事长,郭平不再担任轮值董事长一职,转任监事会。
  • 厨房风水禁忌(厨房风水禁忌是什么)
  • 2024-09-27厨房风水禁忌是什么最忌直线风水中十分忌讳大门,厨房门,炉灶在三点一线,这样的格局会导致财运和健康都很不顺厨房格局要方正要么是长方形或者正方形,正方形为佳,倘若格局不规整,可以在斜角处打橱柜,让格局变得工整开放式厨房现在。
  • 植物园科普标识(植物园里的科学节)
  • 2024-09-27植物园里的科学节长江日报大武汉客户端11月13日讯(记者杨晓雨通讯员李文璇)11月13日,中科院第四届“科学节”暨2021年武汉植物园科普开放日主题活动在武汉植物园磨山园区举行本次活动邀请了17家科教机构以互动形式展。
  • 卖萌胡闹和严肃正经都有(卖萌胡闹和严肃正经都有)
  • 2024-09-27卖萌胡闹和严肃正经都有作者:千里茜十月的热门新番中有不少非热血战斗向的作品,它们有些在严肃正经地讲故事,而有些则在卖萌胡闹本期同样将介绍七部新番动画,对于Stage1st论坛坛友们来说究竟哪种才好看呢?就让我们走进今天的首。
  • 东北年夜饭16道菜谱(东北大骨头炖酸菜)
  • 2024-09-27东北大骨头炖酸菜作者:晓晓雨用料大骨头500g酸菜适量土豆两个葱半棵姜四片蒜一瓣盐适量蚝油适量大料一瓣做法步骤1、大骨头洗净,沥水冷水下锅,因为骨头里面有一些血水什么的,渐渐的水开了,撇锅上面的沫中火2、准备以上辅食。
  • 红薯高产种植技术和方法(农民种植红薯教你3招)
  • 2024-09-27农民种植红薯教你3招​种植户老赵,种植红薯也有很多年了,这些年由于管理技术不到位,红薯产量不但一直都不高,而且红薯品质也比较差红薯种植户老赵说:种红薯到底该如何管理才能亩产万斤呢?为啥我的产量不高呢?种植红薯高产红薯管理。