import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class testClient {
public void testSearch(){
String dn="cn=Manager,dc=xxx,dc=com";
String searchDn1="ou=users,dc=xxx,dc=com";
String searchDnFilter="(|(cn=samwong)(telephoneNumber=12345678))";
Properties hs = new Properties();
hs.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
hs.setProperty(Context.PROVIDER_URL,"ldap://192.168.1.177:389");
hs.setProperty(Context.SECURITY_AUTHENTICATION,"simple");
hs.setProperty(Context.SECURITY_PRINCIPAL,dn);
hs.setProperty(Context.SECURITY_CREDENTIALS,"password");
try {
/*指定了JNDI服务提供者中工厂类(factory class)的名称。Factory负
责为其服务创建适当的InitialContext对象。在上面的代码片断中,为文件
系统服务提供者指定了工厂类*/
DirContext ctx = new InitialDirContext(hs);
System.out.println("成功创建初始化context对象!");
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration en = ctx.search(searchDn1,searchDnFilter, constraints);
while (en != null && en.hasMoreElements()) {
Object obj = en.nextElement();
if (obj instanceof SearchResult) {
SearchResult si = (SearchResult) obj;
System.out.println("name: " + si.getName());
Attributes attrs = si.getAttributes();
if (attrs == null) {
System.out.println("No attributes");
} else {
Attribute attr = attrs.get("userPassword");
if(attr!=null){
Object o = attr.get();
byte[] s = (byte[]) o;
String pwd2 = new String(s);
System.out.println(pwd2);
}
}
} else {
System.out.println(obj);
}
System.out.println();
}
//ctx.lookup(name);
//Person obj=(Person) ctx.lookup(searchDn);
//System.out.print("personname:"+obj.getName()+"psersonage:"+obj.getAge());
ctx.close();
}catch(Exception ex ){
ex.printStackTrace();
System.exit(1);
}
/*
String dn="cn=Manager,dc=xxx,dc=com";
String searchDn="cn=SamWong,ou=users,dc=xxx,dc=com";
Properties hs = new Properties();
hs.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
hs.setProperty(Context.PROVIDER_URL,"ldap://192.168.1.177:389");
hs.setProperty(Context.SECURITY_AUTHENTICATION,"simple");
hs.setProperty(Context.SECURITY_PRINCIPAL,dn);
hs.setProperty(Context.SECURITY_CREDENTIALS,"password");
try {
指定了JNDI服务提供者中工厂类(factory class)的名称。Factory负
责为其服务创建适当的InitialContext对象。在上面的代码片断中,为文件
系统服务提供者指定了工厂类
DirContext ctx = new InitialDirContext(hs);
System.out.println("成功创建初始化context对象!");
//ctx.lookup(name);
Object obj=ctx.lookup(searchDn);
ctx.get(searchDn)
ctx.close();
}catch(Exception ex ){
ex.printStackTrace();
System.exit(1);
}*/
}
/**
* @param args
*/
public static void main(String[] args) {
testClient client=new testClient();
client.testSearch();
}
}
分享到:
相关推荐
JNDI 操作 LDAP的几个例子源码 包括连接、添加、删除、修改、搜寻
Windows_7_下搭建LDAP服务器并使用JNDI Windows_7_下搭建LDAP服务器并使用JNDI Windows_7_下搭建LDAP服务器并使用JNDI
提供了使用fsContext服务器的unbind bind list lookup rename的相关例子,及ldap 连接的一个例子 jndi,就是命名服务(n:naming)和目录服务(d:directory). 命名服务:把对象映射到方便记忆的名字的机制.可以通过域名系统...
027-JNDI之初探 LDAP.pdf
基于Java JNDI 操纵LDAP的基础实现,包括LDAP连接相关生命周期,认证的两种策略demo,条目的操作,schema的基础操作包括(attributeDefinition\objectDefinition\)但未包含相关syntaxDefinition的操纵. 没有资源分的朋友...
NULL 博文链接:https://zzqrj.iteye.com/blog/1279219
import com.sun.jndi.ldap.ctl.VirtualListViewControl;
maven稀缺jar资源
封装JNDI的LDAP服务器所要使用的类的详细介绍。 封装JNDI操作LDAP服务器的工具类.doc
亲测可以使用的,LDAP认证用户名密码,使用JNDI方式认证
SpringLDAP和JNDI增删改查的入门级例子 能够通过编译和运行 已经包含了需要的包,用eclipse导入即可
JNDI修改OpenLDAP条目密码,内容包括一个MD5与Base64的转码操作,以及使用JNDI以MD5的方式修改LDAP条目的密码.
这个是一个初学ldap和jndi的心得,希望对大家有所帮助.
用于JNDI注入攻击的恶意LDAP服务器。 描述 该项目包含LDAP和HTTP服务器,用于利用默认情况下不安全的Java JNDI API。 为了执行攻击,您可以在本地启动这些服务器,然后在易受攻击的客户端上触发JNDI解析,例如: ...
AD ldap java集成
java连接和验证的ldap学习文档,密码的校验,通过jndi连接ldap服务
rmi-jndi-ldap-jrmp-jmx-jms rmi,jndi,ldap,jrmp,jmx,jms一些演示测试
一款用作JNDI注入利用的工具,大量参考/引用了Rogue JNDI项目的代码,支持直接插入植入内存shell ,并集成了常见的bypass 高版本JDK的方式,适用于与自动化工具配合使用。 使用说明 使用java -jar JNDIExploit.jar -...