当前位置: 首页>>代码示例>>Java>>正文


Java LDAPConnection.search方法代码示例

本文整理汇总了Java中com.novell.ldap.LDAPConnection.search方法的典型用法代码示例。如果您正苦于以下问题:Java LDAPConnection.search方法的具体用法?Java LDAPConnection.search怎么用?Java LDAPConnection.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.novell.ldap.LDAPConnection的用法示例。


在下文中一共展示了LDAPConnection.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadSchema

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testReadSchema() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("127.0.0.1", 50983);
	LDAPSearchResults res = con.search("cn=schema", 0, "(objectClass=*)", new String[0], false);
	res.hasMore();
	LDAPEntry fromserver = res.next();
	con.disconnect();
	
	LDIFReader reader = new LDIFReader(new FileInputStream(System.getenv("PROJ_DIR") + "/dist/conf/openldap_schema.ldif"));
	Util util = new Util();
	LDAPMessage msg = reader.readMessage();
	if (msg == null) {
		fail("number of results dont match");
		return;
	}
	
	
	LDAPEntry fromldif = ((LDAPSearchResult) msg).getEntry();
	if (! util.compareEntry(fromserver, fromldif)) {
		fail("Entries don't match\n from server: \n" + util.toLDIF(fromserver) + "\nfromldif:\n" + util.toLDIF(fromldif));
	}
			
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:25,代码来源:TestSchemaInsert.java

示例2: testSimpleSearchCNSubstr1

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testSimpleSearchCNSubstr1() throws LDAPException {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost",50983);
	Util util = new Util();
	LDAPSearchResults res = con.search("dc=nam,dc=compinternal,dc=com",2,"(cn=A*Alberts)",new String[0],false);
	
	LDAPAttributeSet attribs = new LDAPAttributeSet();
	attribs.add(new LDAPAttribute("l","LA"));
	attribs.getAttribute("l").addValue("NY");
	attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
	attribs.add(new LDAPAttribute("uid","aalberts"));
	attribs.add(new LDAPAttribute("empid","2"));
	attribs.add(new LDAPAttribute("givenname","Al"));
	attribs.add(new LDAPAttribute("sn","Alberts"));
	attribs.add(new LDAPAttribute("cn","Al Alberts"));
	
	
	LDAPEntry entry = new LDAPEntry("empid=2,dc=nam,dc=compinternal,dc=com",attribs);
	
	if (! res.hasMore()) {
		fail("entries not returned");
		return;
	}
	
	if (! util.compareEntry(entry,res.next())) {
		fail("1st entry failed");
	}
	
	
	
	
	
	if (res.hasMore()) {
		fail("too many entries");
	}
	
	con.disconnect();
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:39,代码来源:TestJDBCUid.java

示例3: testUpdateEntry

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testUpdateEntry() throws LDAPException {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost",50983);
	con.bind(3,"cn=admin,o=mycompany,c=us","manager".getBytes());
	
	LDAPAttributeSet attribs = new LDAPAttributeSet();
	
	
	LDAPEntry entry = new LDAPEntry("cn=testadd,o=mycompany,c=us",attribs);
	LDAPSearchResults res = con.search("o=mycompany,c=us",2,"(uid=testuid)",new String[] {"updateentry"},false);
	LDAPEntry fromServer = res.next();
	if (! Util.compareEntry(entry,fromServer)) {
		fail("Did not retrieve correct data : " + fromServer.toString());
	}
	con.disconnect();
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:18,代码来源:TestJDBCLDAP.java

示例4: testSimpleSearchUIDSubstr2

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testSimpleSearchUIDSubstr2() throws LDAPException {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost",50983);
	Util util = new Util();
	LDAPSearchResults res = con.search("dc=nam,dc=compinternal,dc=com",2,"(uid=a*erts)",new String[0],false);
	
	LDAPAttributeSet attribs = new LDAPAttributeSet();
	attribs.add(new LDAPAttribute("l","LA"));
	attribs.getAttribute("l").addValue("NY");
	attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
	attribs.add(new LDAPAttribute("uid","aalberts"));
	attribs.add(new LDAPAttribute("empid","2"));
	attribs.add(new LDAPAttribute("givenname","Al"));
	attribs.add(new LDAPAttribute("sn","Alberts"));
	attribs.add(new LDAPAttribute("cn","Al Alberts"));
	
	
	LDAPEntry entry = new LDAPEntry("empid=2,dc=nam,dc=compinternal,dc=com",attribs);
	
	if (! res.hasMore()) {
		fail("entries not returned");
		return;
	}
	
	if (! util.compareEntry(entry,res.next())) {
		fail("1st entry failed");
	}
	
	
	
	
	
	if (res.hasMore()) {
		fail("too many entries");
	}
	
	con.disconnect();
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:39,代码来源:TestJDBCUid.java

示例5: testWildcardSearchOneLevel

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testWildcardSearchOneLevel() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost", 50983);
	
	LDAPSearchResults res = con.search("dc=nam,dc=compinternal,dc=com", 1, "(uniqueMember=Marc*)", new String[] {}, false);
	this.checkSearch(res, "groupBaseSearch.ldif");
	
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:9,代码来源:TestDBGroup.java

示例6: testSearchSynGroupSMember2

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testSearchSynGroupSMember2() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost", 50983);
	LDAPSearchResults res = con.search("ou=groups,o=ad", 2, "(&(cn=Sales)(objectClass=groupOfUniqueNames)(uniqueMember=uid=tuser4,ou=people,o=ad))", new String[] {}, false);
	LDIFReader reader = new LDIFReader(new FileInputStream(System.getenv("PROJ_DIR") + "/test/DynGroups/domainGroupSearch2.ldif"));
	Util util = new Util();
	
	boolean found = false;
	
	while (res.hasMore()) {
		found = true;
		LDAPMessage msg = reader.readMessage();
		if (msg == null) {
			fail("number of results dont match");
			return;
		}
		
		
		LDAPEntry fromldif = ((LDAPSearchResult) msg).getEntry();
		LDAPEntry fromserver = res.next();
		if (! util.compareEntry(fromserver, fromldif)) {
			fail("Entries don't match\n from server: \n" + util.toLDIF(fromserver) + "\nfromldif:\n" + util.toLDIF(fromldif));
		}
		
	}
	
	con.disconnect();
	
	if (! found) {
		fail("no entries returned");
	}
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:33,代码来源:TestDynGroup.java

示例7: testControl

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testControl() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("127.0.0.1", 50983);
	LDAPSearchResults res = con.search("o=mycompany,c=us",2, "(cn=testrouting)", new String[]{}, false);
	String chkRes = checkSearch(res, "control-results.ldif");
	
	if (! chkRes.isEmpty()) {
		fail(chkRes);
	}
	
	con.disconnect();
	
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:15,代码来源:TestAttributeRouter.java

示例8: testSubtreeFromUser

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testSubtreeFromUser() throws LDAPException {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost",50983);
	Util util = new Util();
	LDAPSearchResults res = con.search("empid=2,dc=nam,dc=compinternal,dc=com",2,"(objectClass=*)",new String[0],false);
	
	LDAPAttributeSet attribs = new LDAPAttributeSet();
	attribs.add(new LDAPAttribute("l","LA"));
	attribs.getAttribute("l").addValue("NY");
	attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
	attribs.add(new LDAPAttribute("uid","aalberts"));
	attribs.add(new LDAPAttribute("empid","2"));
	attribs.add(new LDAPAttribute("givenname","Al"));
	attribs.add(new LDAPAttribute("sn","Alberts"));
	attribs.add(new LDAPAttribute("cn","Al Alberts"));
	
	LDAPEntry entry = new LDAPEntry("empid=2,dc=nam,dc=compinternal,dc=com",attribs);
	
	if (! res.hasMore()) {
		fail("entries not returned");
		return;
	}
	
	if (! util.compareEntry(entry,res.next())) {
		fail("1st entry failed");
	}
	
	
	
	
	
	if (res.hasMore()) {
		fail("too many entries");
	}
	
	con.disconnect();
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:39,代码来源:TestJDBCUid.java

示例9: testDelete

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testDelete() throws LDAPException {

		HashMap session = new HashMap();
		session.put(SessionVariables.BOUND_INTERCEPTORS,new ArrayList<String>());
		DeleteInterceptorChain chain = new DeleteInterceptorChain(
				new DistinguishedName(new DN("cn=admin,o=mycompany,c=us")),
				new Password("manager".getBytes()), 0, this.chain,
				session, new HashMap<Object, Object>());

		chain.nextDelete(new DistinguishedName(
				"cn=Test User,ou=internal,o=company"), new LDAPConstraints());

		LDAPConnection con = new LDAPConnection();
		con.connect("localhost", 10983);
		con.bind(3, "cn=admin,dc=domain,dc=com", "manager".getBytes());

		try {
			LDAPSearchResults res = con.search(
					"cn=Test User,ou=internal,o=company,c=us", 0,
					"(objectClass=*)", new String[0], false);
			LDAPEntry result = res.next();
			fail("Entry not deleted");
		} catch (LDAPException e) {

		}
		
		con.disconnect();

	}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:30,代码来源:TestLocalChainLDAP.java

示例10: testInternal

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testInternal() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("127.0.0.1", 50983);
	LDAPSearchResults res = con.search("o=mycompany,c=us",2, "(|(cn=testrouting)([email protected]))", new String[]{}, false);
	String chkRes = checkSearch(res, "internal-results.ldif");
	
	if (! chkRes.isEmpty()) {
		fail(chkRes);
	}
	
	con.disconnect();
	
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:15,代码来源:TestAttributeRouter.java

示例11: testModPrimary

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testModPrimary() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost", 50983);
	
	LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute("givenName","TestName"));
	
	con.modify("uid=user3,ou=people,o=mycompany,c=us", mod);
	
	LDAPSearchResults res = con.search("uid=user3,ou=people,o=mycompany,c=us", 0, "(objectClass=*)", new String[0], false);
	LDIFReader reader = new LDIFReader(new FileInputStream(System.getenv("PROJ_DIR") + "/test/TestJoin/ldifs/afterModifyPrimary.ldif"));
	Util util = new Util();
	
	while (res.hasMore()) {
		LDAPMessage msg = reader.readMessage();
		if (msg == null) {
			fail("number of results dont match");
			return;
		}
		
		
		LDAPEntry fromldif = ((LDAPSearchResult) msg).getEntry();
		LDAPEntry fromserver = res.next();
		if (! util.compareEntry(fromserver, fromldif)) {
			fail("Entries don't match : " + fromserver + "/" + fromldif);
		}
		
	}
	
	con.disconnect();
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:31,代码来源:TestJoin.java

示例12: testLinuxLogin

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testLinuxLogin() throws Exception {
	LDAPConnection con = new LDAPConnection();
	con.connect("localhost", 50983);
	
	//need to pre-search to keep the numeric ids
	LDAPSearchResults res = con.search("o=mycompany,c=us", 2, "(objectClass=*)", new String[0], false);
	checkSearch(res,"fulldir.ldif");
	
	//nismap test
	res = con.search("cn=users,o=mycompany,c=us", 2, "(&(objectclass=nisMap)(nisMapName=auto.master))", new String[]{"1.1"}, false);
	if (res.hasMore()) {
		fail("Should be no resutls");
	}
	
	//system account, not existant
	res = con.search("cn=users,o=mycompany,c=us", 2, "(&(objectClass=posixAccount)(uid=gdm))", new String[]{}, false);
	if (res.hasMore()) {
		fail("Should be no resutls");
	}
	
	//system acount's group, non existant
	res = con.search("cn=users,o=mycompany,c=us", 2, "(&(objectClass=posixGroup)(memberUid=gdm))", new String[]{"gidNumber"}, false);
	if (res.hasMore()) {
		fail("Should be no resutls");
	}
	
	//user typed in their username
	res = con.search("cn=users,o=mycompany,c=us",2,"(uid=mlb)",new String[] {},false);
	String str = this.checkSearch(res, "uidSearch.ldif");
	if (str.length() > 0) {
		fail(str);
	}
	
	//search and bind
	res = con.search("cn=users,o=mycompany,c=us",2,"(uid=mlb)",new String[] {},false);
	res.hasMore();
	LDAPEntry entry = res.next();
	String dn = entry.getDN();
	
	if(res.hasMore()) {
		fail("more then one user returned");
	}
	
	con.bind(3,dn, "mlbsecret".getBytes());
	
	//rebind as anon
	con.bind(3, "", new byte[0]);
	
	
	res = con.search("cn=users,o=mycompany,c=us", 2, "(&(objectClass=posixAccount)(uidNumber=505))", new String[] {"uid","uidNumber","gidNumber","cn","homeDirectory","loginShell","gecos","description","objectClass","userPassword"}, false);
	str = this.checkSearch(res, "uidNumberSearch.ldif");
	if (str.length() > 0) {
		fail(str);
	}
	
	res = con.search("cn=users,o=mycompany,c=us",2,"(&(objectClass=posixAccount)(uid=mlb))",new String[] {},false);
	str = this.checkSearch(res, "uidSearch.ldif");
	if (str.length() > 0) {
		fail(str);
	}
	
	//group memberships?
	res = con.search("cn=users,o=mycompany,c=us",2,"(&(objectClass=posixGroup)(|(memberUid=mlb)(uniqueMember=cn=Marc Boorshtein,cn=Users,o=mycompany,c=us)))",new String[] {"gidNumber"},false);
	str = this.checkSearch(res, "groupMemberships.ldif");
	if (str.length() > 0) {
		fail(str);
	}
	
	
	
	con.disconnect();
	
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:75,代码来源:ADPosix.java

示例13: testAndNotOr

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testAndNotOr() throws LDAPException {

		LDAPAttributeSet attribs = new LDAPAttributeSet();
		attribs.add(new LDAPAttribute("objectClass", "customPerson"));
		attribs.add(new LDAPAttribute("cn", "Test User"));
		attribs.add(new LDAPAttribute("sn", "User"));
		// attribs.add(new LDAPAttribute("testAttrib", "testVal"));
		attribs.add(new LDAPAttribute("uid", "testUser"));
		attribs.add(new LDAPAttribute("userPassword", "secret"));
		attribs.add(new LDAPAttribute("sumNum", "5"));
		// attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal"));
		LDAPEntry entry2 = new LDAPEntry(
				"cn=Test User,ou=internal,o=mycompany,c=us", attribs);

		LDAPConnection con = new LDAPConnection();
		con.connect("localhost", 50983);
		// con.bind(3,"cn=admin,o=mycompany","manager".getBytes());
		LDAPSearchResults res = con
				.search("o=mycompany,c=us",
						2,
						"(&(!(cn=Test Group))(!(cn=Test Cust))(!(|(objectClass=organizationalUnit)(objectClass=domain))))",
						new String[0], false);

		/*
		 * if (results.size() != 3) { fail("incorrect number of result sets : "
		 * + results.size()); return; }
		 */

		int size = 0;

		while (res.hasMore()) {
			LDAPEntry fromDir = res.next();
			LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN());

			if (size == 0) {
				controlEntry = entry2;
			} else if (size == 1) {
				controlEntry = null;
			} else {
				controlEntry = null;
			}

			if (controlEntry == null) {
				fail("Entry " + fromDir.getDN() + " should not be returned");
				return;
			}

			if (!Util.compareEntry(fromDir, controlEntry)) {
				fail("The entry was not correct : " + fromDir.toString());
				return;
			}

			size++;
		}

		if (size != 1) {
			fail("Not the correct number of entries : " + size);
		}

		con.disconnect();

	}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:63,代码来源:TestLDAPSearch.java

示例14: testUidSearch

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
@Test
public void testUidSearch() throws LDAPException {

	LDAPAttributeSet attribs = new LDAPAttributeSet();
	attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson"));
	// attribs.getAttribute("objectClass").addValue("customPerson");
	attribs.add(new LDAPAttribute("cn", "Test1 User"));
	attribs.add(new LDAPAttribute("sn", "User"));
	// attribs.add(new LDAPAttribute("testAttrib", "testVal"));
	attribs.add(new LDAPAttribute("uid", "tuser001"));
	attribs.add(new LDAPAttribute("userPassword", "secret"));

	// attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal"));
	LDAPEntry entry2 = new LDAPEntry("uid=tuser001,cn=users,dc=ad,dc=com", attribs);

	LDAPConnection con = new LDAPConnection();
	con.connect("localhost", 50983);
	// con.bind(3,"cn=admin,o=mycompany","manager".getBytes());
	LDAPSearchResults res = con.search("dc=ad,dc=com", 2, "(uid=tuser001)", new String[0], false);

	int size = 0;

	while (res.hasMore()) {
		LDAPEntry fromDir = res.next();
		LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN());

		if (size == 0) {
			controlEntry = entry2;
		} else if (size == 1) {
			controlEntry = null;
		} else {
			controlEntry = null;
		}

		if (controlEntry == null) {
			fail("Entry " + fromDir.getDN() + " should not be returned");
			return;
		}

		if (!Util.compareEntry(fromDir, controlEntry)) {
			fail("The entry was not correct : " + fromDir.toString());
			return;
		}

		size++;
	}

	if (size != 1) {
		fail("Not the correct number of entries : " + size);
	}

	con.disconnect();

}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:55,代码来源:SetRDNAD.java

示例15: testGroupMemberComma

import com.novell.ldap.LDAPConnection; //导入方法依赖的package包/类
public void testGroupMemberComma() throws LDAPException {

		LDAPAttributeSet attribs = new LDAPAttributeSet();

		// attribs.getAttribute("objectClass").addValue("customPerson");
		attribs.add(new LDAPAttribute("cn", "With Comma"));

		// attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal"));
		LDAPEntry entry2 = new LDAPEntry("cn=With Comma,cn=users,dc=ad,dc=com",
				attribs);

		LDAPConnection con = new LDAPConnection();
		con.connect("localhost", 50983);
		// con.bind(3,"cn=admin,o=mycompany","manager".getBytes());
		LDAPSearchResults res = con.search("cn=\"users\",dc=\"ad\",dc=\"com\"",
				2, "(uniqueMember=cn=User\\\\, Test3,cn=users,dc=ad,dc=com)",
				new String[] { "cn" }, false);

		/*
		 * if (results.size() != 3) { fail("incorrect number of result sets : "
		 * + results.size()); return; }
		 */

		int size = 0;

		while (res.hasMore()) {
			LDAPEntry fromDir = res.next();
			LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN());

			if (size == 0) {
				controlEntry = entry2;
			} else {
				controlEntry = null;
			}

			if (controlEntry == null) {
				fail("Entry " + fromDir.getDN() + " should not be returned");
				return;
			}

			if (!Util.compareEntry(fromDir, controlEntry)) {
				fail("The entry was not correct : " + fromDir.toString());
				return;
			}

			size++;
		}

		if (size != 1) {
			fail("Not the correct number of entries : " + size);
		}

		con.disconnect();

	}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:56,代码来源:TestLDAPSearch.java


注:本文中的com.novell.ldap.LDAPConnection.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。