]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifAuthorization.java
1 package org
.argeo
.osgi
.useradmin
;
3 import java
.util
.Arrays
;
4 import java
.util
.Collections
;
5 import java
.util
.Dictionary
;
8 import org
.osgi
.service
.useradmin
.Authorization
;
9 import org
.osgi
.service
.useradmin
.Role
;
10 import org
.osgi
.service
.useradmin
.User
;
12 public class LdifAuthorization
implements Authorization
{
13 private final String name
;
14 private final String displayName
;
15 private final List
<String
> allRoles
;
17 @SuppressWarnings("unchecked")
18 public LdifAuthorization(User user
, List
<Role
> allRoles
) {
21 this.displayName
= "anonymous";
23 this.name
= user
.getName();
24 Dictionary
<String
, Object
> props
= user
.getProperties();
25 Object displayName
= props
.get(LdifName
.displayName
);
26 if (displayName
== null)
27 displayName
= props
.get(LdifName
.cn
);
28 if (displayName
== null)
29 displayName
= props
.get(LdifName
.uid
);
30 if (displayName
== null)
31 displayName
= user
.getName();
32 if (displayName
== null)
33 throw new UserDirectoryException("Cannot set display name for "
35 this.displayName
= displayName
.toString();
38 String
[] roles
= new String
[allRoles
.size()];
39 for (int i
= 0; i
< allRoles
.size(); i
++) {
40 roles
[i
] = allRoles
.get(i
).getName();
42 this.allRoles
= Collections
.unmodifiableList(Arrays
.asList(roles
));
46 public String
getName() {
51 public boolean hasRole(String name
) {
52 return allRoles
.contains(name
);
56 public String
[] getRoles() {
57 return allRoles
.toArray(new String
[allRoles
.size()]);
61 public int hashCode() {
63 return super.hashCode();
64 return name
.hashCode();
68 public boolean equals(Object obj
) {
69 if (!(obj
instanceof Authorization
))
71 Authorization that
= (Authorization
) obj
;
73 return that
.getName() == null;
74 return name
.equals(that
.getName());
78 public String
toString() {