1 5 6 12 package org.exoplatform.services.ldap; 13 14 import netscape.ldap.LDAPAttribute; 15 import netscape.ldap.LDAPAttributeSet; 16 import netscape.ldap.LDAPEntry; 17 import netscape.ldap.LDAPSearchResults; 18 import netscape.ldap.LDAPv2; 19 import org.exoplatform.container.PortalContainer; 20 import org.exoplatform.services.log.LogService; 21 import org.exoplatform.test.BasicTestCase; 22 23 public class TestLDAPService extends BasicTestCase { 24 25 private LDAPServiceContainer ldapServiceContainer; 26 private LDAPService ldapService; 27 private LogService logService; 28 29 public TestLDAPService(String s) { 30 super(s); 31 } 32 33 protected String getDescription() { 34 return "test ldap service"; 35 } 36 37 public void setUp() throws Exception { 38 39 if (ldapServiceContainer == null) { 40 PortalContainer pcontainer = PortalContainer.getInstance(); 41 ldapServiceContainer = 42 (LDAPServiceContainer) pcontainer.getComponentInstanceOfType( 43 LDAPServiceContainer.class); 44 ldapService = ldapServiceContainer.createLDAPService(); 46 } 47 } 48 49 public void testLDAPAddEntry() throws Exception { 50 51 String objectclasses[] = { "exouser" }; 52 LDAPAttribute attr1 = new LDAPAttribute("objectclass", objectclasses); 53 LDAPAttribute attr2 = new LDAPAttribute("uid", "danny_xcz"); 54 LDAPAttribute attr3 = new LDAPAttribute("userPassword", "pass"); 55 LDAPAttributeSet attrSet = new LDAPAttributeSet(); 56 attrSet.add(attr1); 57 attrSet.add(attr2); 58 attrSet.add(attr3); 59 String dn = "uid=danny_xcz,ou=users,dc=exoplatform,dc=com"; 60 LDAPEntry newEntry = new LDAPEntry(dn, attrSet); 61 ldapService.add(newEntry); 62 } 63 64 public void testLDAPSearch() throws Exception { 65 66 String baseDN = "dc=exoplatform,dc=com"; 67 int searchScope = LDAPv2.SCOPE_SUB; 68 String searchFilter = "(uid=danny_xcz)"; 69 String getAttrs[] = { "userPassword", "mail" }; 70 71 LDAPSearchResults res = 72 ldapService.search( 73 baseDN, 74 searchScope, 75 searchFilter, 76 getAttrs, 77 false); 78 79 LDAPEntry nextEntry = res.next(); 80 LDAPAttribute passwordAttr = nextEntry.getAttribute("userPassword"); 81 assertEquals(1, passwordAttr.size()); 82 } 83 84 } 85 | Popular Tags |