1 package org
.argeo
.osgi
.useradmin
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Base64
;
6 import java
.util
.SortedMap
;
8 import javax
.naming
.NamingEnumeration
;
9 import javax
.naming
.directory
.Attribute
;
10 import javax
.naming
.directory
.Attributes
;
11 import javax
.naming
.ldap
.LdapName
;
13 import org
.argeo
.util
.naming
.LdifParser
;
15 import junit
.framework
.TestCase
;
17 public class LdifParserTest
extends TestCase
implements BasicTestConstants
{
18 public void testBasicLdif() throws Exception
{
19 LdifParser ldifParser
= new LdifParser();
20 SortedMap
<LdapName
, Attributes
> res
= ldifParser
.read(getClass()
21 .getResourceAsStream("basic.ldif"));
22 LdapName rootDn
= new LdapName(ROOT_USER_DN
);
23 Attributes rootAttributes
= res
.get(rootDn
);
24 assertNotNull(rootAttributes
);
25 assertEquals("Superuser",
26 rootAttributes
.get(LdifName
.description
.name()).get());
27 byte[] rawPwEntry
= (byte[]) rootAttributes
.get(
28 LdifName
.userPassword
.name()).get();
29 assertEquals("{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE=",
30 new String(rawPwEntry
));
31 byte[] hashedPassword
= DigestUtils
.sha1("demo".getBytes());
32 assertEquals("{SHA}" + Base64
.getEncoder().encodeToString(hashedPassword
),
33 new String(rawPwEntry
));
35 LdapName adminDn
= new LdapName(ADMIN_GROUP_DN
);
36 Attributes adminAttributes
= res
.get(adminDn
);
37 assertNotNull(adminAttributes
);
38 Attribute memberAttribute
= adminAttributes
.get(LdifName
.member
.name());
39 assertNotNull(memberAttribute
);
40 NamingEnumeration
<?
> members
= memberAttribute
.getAll();
41 List
<String
> users
= new ArrayList
<String
>();
42 while (members
.hasMore()) {
43 Object value
= members
.next();
44 users
.add(value
.toString());
46 assertEquals(1, users
.size());
47 assertEquals(rootDn
, new LdapName(users
.get(0)));