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
.naming
.LdapAttrs
;
14 import org
.argeo
.naming
.LdifParser
;
16 import junit
.framework
.TestCase
;
18 public class LdifParserTest
extends TestCase
implements BasicTestConstants
{
19 public void testBasicLdif() throws Exception
{
20 LdifParser ldifParser
= new LdifParser();
21 SortedMap
<LdapName
, Attributes
> res
= ldifParser
.read(getClass()
22 .getResourceAsStream("basic.ldif"));
23 LdapName rootDn
= new LdapName(ROOT_USER_DN
);
24 Attributes rootAttributes
= res
.get(rootDn
);
25 assertNotNull(rootAttributes
);
26 assertEquals("Superuser",
27 rootAttributes
.get(LdapAttrs
.description
.name()).get());
28 byte[] rawPwEntry
= (byte[]) rootAttributes
.get(
29 LdapAttrs
.userPassword
.name()).get();
30 assertEquals("{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE=",
31 new String(rawPwEntry
));
32 byte[] hashedPassword
= DigestUtils
.sha1("demo".getBytes());
33 assertEquals("{SHA}" + Base64
.getEncoder().encodeToString(hashedPassword
),
34 new String(rawPwEntry
));
36 LdapName adminDn
= new LdapName(ADMIN_GROUP_DN
);
37 Attributes adminAttributes
= res
.get(adminDn
);
38 assertNotNull(adminAttributes
);
39 Attribute memberAttribute
= adminAttributes
.get(LdapAttrs
.member
.name());
40 assertNotNull(memberAttribute
);
41 NamingEnumeration
<?
> members
= memberAttribute
.getAll();
42 List
<String
> users
= new ArrayList
<String
>();
43 while (members
.hasMore()) {
44 Object value
= members
.next();
45 users
.add(value
.toString());
47 assertEquals(1, users
.size());
48 assertEquals(rootDn
, new LdapName(users
.get(0)));