]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifAuthorization.java
3a2aeca2ea5c2715a58ee84815d82b700b82819f
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 public LdifAuthorization(User user
, List
<Role
> allRoles
) {
20 this.displayName
= "anonymous";
22 this.name
= user
.getName();
23 Dictionary
<String
, Object
> props
= user
.getProperties();
24 Object displayName
= props
.get(LdifName
.displayName
);
25 if (displayName
== null)
26 displayName
= props
.get(LdifName
.cn
);
27 if (displayName
== null)
28 displayName
= props
.get(LdifName
.uid
);
29 if (displayName
== null)
30 displayName
= user
.getName();
31 if (displayName
== null)
32 throw new UserDirectoryException("Cannot set display name for "
34 this.displayName
= displayName
.toString();
37 String
[] roles
= new String
[allRoles
.size()];
38 for (int i
= 0; i
< allRoles
.size(); i
++) {
39 roles
[i
] = allRoles
.get(i
).getName();
41 this.allRoles
= Collections
.unmodifiableList(Arrays
.asList(roles
));
45 public String
getName() {
50 public boolean hasRole(String name
) {
51 return allRoles
.contains(name
);
55 public String
[] getRoles() {
56 return allRoles
.toArray(new String
[allRoles
.size()]);
60 public int hashCode() {
62 return super.hashCode();
63 return name
.hashCode();
67 public boolean equals(Object obj
) {
68 if (!(obj
instanceof Authorization
))
70 Authorization that
= (Authorization
) obj
;
72 return that
.getName() == null;
73 return name
.equals(that
.getName());
77 public String
toString() {