ldap 字段解释(JavaUnboundID内存LDAP服务支持)
ldap 字段解释(JavaUnboundID内存LDAP服务支持)
2024-07-05 11:32:28  作者:诂莋堅強  网址:https://m.xinb2b.cn/tech/bmi424147.html

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

ldap 字段解释(JavaUnboundID内存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(); } }}

  • 张姓家族族谱字辈(张姓家族繁衍生息的88代的主线历程)
  • 2024-07-05张姓家族繁衍生息的88代的主线历程张氏族谱展示了张姓家族繁衍生息的88代的主线历程,我们还会发现其中很多的历史名人赫然在列,诸如唐朝著名的才子张九龄等中文名张氏族谱包含代数88代张姓始祖张辉公外文名暂无历代名人张九龄,张继等张氏图腾先。
  • 外卖备注的奇葩东西(一鸣惊人的外卖备注)
  • 2024-07-05一鸣惊人的外卖备注这么热的天,出个门都嫌太阳毒,一般人不全副武装是不轻易出门的那么吃饭怎么办呢?小编想大多数的年轻人都是想着点外卖吧!根据这个点外卖的主意,小编给大家总结了一些比较“火爆的”外卖备注,不知道小伙伴们也会。
  • 在家怎样酱牛肉好吃(在家做酱牛肉可以1斤出7两)
  • 2024-07-05在家做酱牛肉可以1斤出7两牛肉最常吃的吃法就是酱牛肉,酱牛肉自古到今就是下酒菜来的首选好的酱牛肉不光颜色好看,刚出锅口感软烂,放凉后肉质紧实,怎么切都不会松散,但是一般好的酱牛肉煮出来,一斤要缩水半斤左右,也就是说1斤牛肉出半。
  • try asher女翻唱(萌妹翻唱治愈歌曲Try)
  • 2024-07-05萌妹翻唱治愈歌曲Try南希在碎乐APP发布了翻唱《try(名扬四海)》的视频,柔和温暖的吟唱,作为晚安曲,实在再合适不过了各大应用商店搜索“碎乐”,发现更多原创好音乐、独家demo,更近距离和音乐人互动,都在碎乐APP更多。
  • 路虎发展历程图(顿悟73年磨一剑的它为何屹立不倒)
  • 2024-07-05顿悟73年磨一剑的它为何屹立不倒01从铃木退出中国市场,看各家汽车厂商的“出路”2021年2月,一直说退出中国市场的铃木,也终于将名字改成了铃耀汽车,而董事长铃木修的卸任也似乎宣告铃木汽车彻底告别了中国市场90年代到21世纪,日本铃。
  • 奇妙之城肖战谈择偶标准了吗(肖战起早吃面接地气)
  • 2024-07-05肖战起早吃面接地气都说家是避风港,在新年在即的各位不知道也不会不会想家呢?《奇妙之城》就是这样一个节目,用六大男神女神携手回故乡,带领观众看遍自己故乡,在科技发展迅速的人文时代,以每一座城市为蓝图,带着镜头回家《奇妙之。
  • 装拖车钩被追尾怎么处罚?私家车私自加装
  • 2024-07-05装拖车钩被追尾怎么处罚?私家车私自加装开车上路最担心的就是交通事故,有的时候并不是你不撞别人,但也保证不了别人不撞你根据交通事故数据显示,一般情况下,多是追尾造成的交通事故发生追尾事故,事故车辆的前后保险杠都会受损,被撞者被动地卷入一起交。
  • 寒假期间吃什么最好(放寒假的小伙伴)
  • 2024-07-05放寒假的小伙伴随着春节临近,学生们开启寒假模式在疫情常态化防控背景下,市健促中心送上这份寒假攻略,提醒大家:假期里精神上可以放松,但仍要保持健康生活方式,个人防护一定不能放松!详见↓疫情防护不放假➪减少出行和聚集,。
  • 无线电新手教学(无线电史话1940年的鱼竿天线)
  • 2024-07-05无线电史话1940年的鱼竿天线说起鱼竿天线,我们最常想到的是城里苦于没地架设天线的业余无线电爱好者,他们只能将钓鱼竿从自家阳台伸出,掉一根长线天线配合天调来进行通联,当然效率也不高,今天,和电台小叔BG5WKP一起来看看在1940。
  • 婚姻中最后一条忠告(婚姻中那些残酷而现实的真相)
  • 2024-07-05婚姻中那些残酷而现实的真相没被催过婚的人都不足以谈人生可婚姻不是小孩子写作业,催着赶着就能快点完成《大男当婚》豆瓣短评“喜欢的不一定合适,合适的不一定靠谱,靠谱的不一定和谐”徐峥主演的最后一部电视剧《大男当婚》,就彻底撕开了这。
  • 芭蕉树和香蕉树是否一样 它们有什么区别
  • 2024-07-05芭蕉树和香蕉树是否一样 它们有什么区别芭蕉树和香蕉树不一样区别如下1、外形不同:香蕉树呈丛生分布,株高约为2-5米,假茎浓绿,而芭蕉树只能长到4米,长有根茎2、叶片不同:香蕉树叶片长约2米,宽度为60厘米,芭蕉树叶片长3米,宽度在30厘米。