]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java
Improve and simplify OSGi Boot
[lgpl/argeo-commons.git] / org.argeo.security.core / ext / test / org / argeo / osgi / useradmin / LdifParserTest.java
index 75a5c34b3442c4d39129b4c343349dcc2ead8ccc..fecf5dd5a199a7e5cfbe3012b8481e1729ab26fa 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.osgi.useradmin;
 
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
 import java.util.SortedMap;
 
@@ -9,10 +10,9 @@ import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapName;
 
-import junit.framework.TestCase;
+import org.argeo.util.naming.LdifParser;
 
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.digest.DigestUtils;
+import junit.framework.TestCase;
 
 public class LdifParserTest extends TestCase implements BasicTestConstants {
        public void testBasicLdif() throws Exception {
@@ -22,19 +22,20 @@ public class LdifParserTest extends TestCase implements BasicTestConstants {
                LdapName rootDn = new LdapName(ROOT_USER_DN);
                Attributes rootAttributes = res.get(rootDn);
                assertNotNull(rootAttributes);
-               assertEquals("Superuser", rootAttributes.get("description").get());
-               byte[] rawPwEntry = (byte[]) rootAttributes.get("userpassword").get();
+               assertEquals("Superuser",
+                               rootAttributes.get(LdifName.description.name()).get());
+               byte[] rawPwEntry = (byte[]) rootAttributes.get(
+                               LdifName.userPassword.name()).get();
                assertEquals("{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE=",
                                new String(rawPwEntry));
                byte[] hashedPassword = DigestUtils.sha1("demo".getBytes());
-               assertEquals("{SHA}" + Base64.encodeBase64String(hashedPassword),
+               assertEquals("{SHA}" + Base64.getEncoder().encodeToString(hashedPassword),
                                new String(rawPwEntry));
 
-               LdapName adminDn = new LdapName(
-                               ADMIN_GROUP_DN);
+               LdapName adminDn = new LdapName(ADMIN_GROUP_DN);
                Attributes adminAttributes = res.get(adminDn);
                assertNotNull(adminAttributes);
-               Attribute memberAttribute = adminAttributes.get("member");
+               Attribute memberAttribute = adminAttributes.get(LdifName.member.name());
                assertNotNull(memberAttribute);
                NamingEnumeration<?> members = memberAttribute.getAll();
                List<String> users = new ArrayList<String>();