本文整理汇总了Java中com.novell.ldap.LDAPConnection类的典型用法代码示例。如果您正苦于以下问题:Java LDAPConnection类的具体用法?Java LDAPConnection怎么用?Java LDAPConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LDAPConnection类属于com.novell.ldap包,在下文中一共展示了LDAPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddBoundFail
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testAddBoundFail() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost",50983);
con.bind(3,"uid=testuser,ou=users,dc=domain,dc=com","secret".getBytes());
LDAPAttributeSet attribs = new LDAPAttributeSet();
attribs.add(new LDAPAttribute("cn","Test Add"));
attribs.add(new LDAPAttribute("sn","Add"));
attribs.add(new LDAPAttribute("uid","tadd"));
attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
LDAPEntry entry = new LDAPEntry("uid=tadd,ou=users,dc=domain,dc=com",attribs);
try {
con.add(entry);
} catch (LDAPException e) {
if (e.getResultCode() != LDAPException.INSUFFICIENT_ACCESS_RIGHTS) {
throw e;
} else {
return;
}
}
fail("add succeeded");
con.disconnect();
}
示例2: testSearchUsersBound
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testSearchUsersBound() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost",50983);
con.bind(3,"uid=testuser,ou=users,dc=domain,dc=com","secret".getBytes());
LDAPAttributeSet attribs = new LDAPAttributeSet();
attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
attribs.add(new LDAPAttribute("cn","Test User1"));
attribs.add(new LDAPAttribute("sn","User1"));
attribs.add(new LDAPAttribute("uid","testuser1"));
attribs.add(new LDAPAttribute("l","location1"));
LDAPSearchResults res = con.search("ou=users,dc=domain,dc=com",1,"(uid=testuser1)",new String[0],false);
if (! res.hasMore()) {
fail("no results");
}
LDAPEntry fromServer = res.next();
LDAPEntry control = new LDAPEntry("uid=testuser1,ou=users,dc=domain,dc=com",attribs);
if (! Util.compareEntry(fromServer,control)) {
fail("invalid entry : " + fromServer.toString());
}
con.disconnect();
}
示例3: testUpdate
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testUpdate() 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,"(sn=sntest)",new String[] {"update"},false);
LDAPEntry fromServer = res.next();
if (! Util.compareEntry(entry,fromServer)) {
fail("Did not retrieve correct data : " + fromServer.toString());
}
con.disconnect();
}
示例4: testAdd
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testAdd() 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,"(cn=testadd)",new String[] {"add"},false);
LDAPEntry fromServer = res.next();
if (! Util.compareEntry(entry,fromServer)) {
fail("Did not retrieve correct data : " + fromServer.toString());
}
con.disconnect();
}
示例5: testDelete
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testDelete() 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,"(sn=add)",new String[] {"delete"},false);
LDAPEntry fromServer = res.next();
if (! Util.compareEntry(entry,fromServer) || res.hasMore()) {
fail("Did not retrieve correct data : " + fromServer.toString());
}
con.disconnect();
}
示例6: testBindAsSysUser
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testBindAsSysUser() throws Exception {
//this should fail
LDAPConnection con = new LDAPConnection();
con.connect("localhost", 50983);
try {
con.bind(3,"uid=apacheadmin,dc=domain,dc=com", "secret".getBytes());
con.delete("uid=tuser1,ou=people,dc=domain,dc=com");
} catch (LDAPException e) {
throw e;
} finally {
con.disconnect();
}
}
示例7: testSearchPrimary
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testSearchPrimary() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost", 50983);
LDAPSearchResults res = con.search("o=mycompany,c=us", 2, "(cn=Test User2)", new String[0], false);
LDIFReader reader = new LDIFReader(new FileInputStream(System.getenv("PROJ_DIR") + "/test/TestJoin/ldifs/filterPrimary.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();
}
示例8: testSearchJoined
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testSearchJoined() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost", 50983);
LDAPSearchResults res = con.search("o=mycompany,c=us", 2, "(appattrib1=sysx)", new String[0], false);
LDIFReader reader = new LDIFReader(new FileInputStream(System.getenv("PROJ_DIR") + "/test/TestJoin/ldifs/filterJoined.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 \nfrom server\n" + Util.toLDIF(fromserver) + "\n\nfrom ldif\n" + Util.toLDIF(fromldif));
}
}
con.disconnect();
}
示例9: testBaseSearch
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testBaseSearch() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost", 50983);
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/baseSearch.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();
}
示例10: testReadSchema
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
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));
}
}
示例11: testExternalWithInternalBase
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testExternalWithInternalBase() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("127.0.0.1", 50983);
LDAPSearchResults res = con.search("ou=internal,o=mycompany,c=us",2, "(|(cn=testrouting)([email protected]))", new String[]{}, false);
try {
if (res.hasMore()) {
LDAPEntry e1 = res.next();
fail("Results came back");
}
} catch (LDAPException e) {
if (e.getResultCode() != 32) {
throw e;
}
}
con.disconnect();
}
示例12: getConnection
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public LDAPConnection getConnection() throws LDAPException {
if (this.con.isConnected() && this.con.isConnectionAlive() && conValid()) {
this.lastAccessed = System.currentTimeMillis();
return this.con;
} else {
this.lastAccessed = System.currentTimeMillis();
this.localReConnect();
return this.con;
}
}
示例13: testANDSearch
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testANDSearch() 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,"(&(l=NY)(l=LA))",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("givenname","Al"));
attribs.add(new LDAPAttribute("sn","Alberts"));
LDAPEntry entry = new LDAPEntry("uid=aalberts,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();
}
示例14: testAddBoundSucceed
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
public void testAddBoundSucceed() throws Exception {
LDAPConnection con = new LDAPConnection();
con.connect("localhost",50983);
con.bind(3,"cn=admin,dc=domain,dc=com","manager".getBytes());
LDAPAttributeSet attribs = new LDAPAttributeSet();
attribs.add(new LDAPAttribute("cn","Test Add"));
attribs.add(new LDAPAttribute("sn","Add"));
attribs.add(new LDAPAttribute("uid","tadd"));
attribs.add(new LDAPAttribute("objectClass","inetOrgPerson"));
LDAPEntry entry = new LDAPEntry("uid=tadd,ou=users,dc=domain,dc=com",attribs);
con.add(entry);
con.disconnect();
}
示例15: testInternalWrongCase
import com.novell.ldap.LDAPConnection; //导入依赖的package包/类
@Test
public void testInternalWrongCase() 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();
}