]> git.argeo.org Git - lgpl/argeo-commons.git/blob - useradmin/LdifUser.java
Prepare next development cycle
[lgpl/argeo-commons.git] / useradmin / LdifUser.java
1 package org.argeo.osgi.useradmin;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Dictionary;
6 import java.util.List;
7
8 import javax.naming.directory.Attributes;
9 import javax.naming.ldap.LdapName;
10
11 import org.osgi.service.useradmin.User;
12
13 class LdifUser implements User {
14 // optimisation
15 List<LdifGroup> directMemberOf = new ArrayList<LdifGroup>();
16
17 private final LdapName dn;
18 private Attributes attributes;
19
20 private final AttributeDictionary properties;
21 private final AttributeDictionary credentials;
22
23 private List<String> credentialAttributes = Arrays
24 .asList(new String[] { "userpassword" });
25
26 LdifUser(LdapName dn, Attributes attributes) {
27 this.dn = dn;
28 this.attributes = attributes;
29 properties = new AttributeDictionary(attributes, credentialAttributes,
30 false);
31 credentials = new AttributeDictionary(attributes, credentialAttributes,
32 true);
33 }
34
35 @Override
36 public String getName() {
37 return dn.toString();
38 }
39
40 @Override
41 public int getType() {
42 return USER;
43 }
44
45 @Override
46 public Dictionary<String, Object> getProperties() {
47 return properties;
48 }
49
50 @Override
51 public Dictionary<String, Object> getCredentials() {
52 return credentials;
53 }
54
55 @Override
56 public boolean hasCredential(String key, Object value) {
57 Object storedValue = getCredentials().get(key);
58 if (storedValue == null || value == null)
59 return false;
60 if (!(value instanceof String || value instanceof byte[]))
61 return false;
62 if (storedValue instanceof String && value instanceof String)
63 return storedValue.equals(value);
64 if (storedValue instanceof byte[] && value instanceof byte[])
65 return Arrays.equals((byte[]) storedValue, (byte[]) value);
66 return false;
67 }
68
69 protected LdapName getDn() {
70 return dn;
71 }
72
73 protected Attributes getAttributes() {
74 return attributes;
75 }
76
77 @Override
78 public int hashCode() {
79 return dn.hashCode();
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj)
85 return true;
86 if (obj instanceof LdifUser) {
87 LdifUser that = (LdifUser) obj;
88 return this.dn.equals(that.dn);
89 }
90 return false;
91 }
92
93 @Override
94 public String toString() {
95 return dn.toString();
96 }
97 }