]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.enterprise/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
.argeo
.naming
.LdapAttrs
;
9 import org
.osgi
.service
.useradmin
.Authorization
;
10 import org
.osgi
.service
.useradmin
.Role
;
11 import org
.osgi
.service
.useradmin
.User
;
13 /** Basic authorization. */
14 class LdifAuthorization
implements Authorization
{
15 private final String name
;
16 private final String displayName
;
17 private final List
<String
> allRoles
;
19 @SuppressWarnings("unchecked")
20 public LdifAuthorization(User user
, List
<Role
> allRoles
) {
23 this.displayName
= "anonymous";
25 this.name
= user
.getName();
26 Dictionary
<String
, Object
> props
= user
.getProperties();
27 Object displayName
= props
.get(LdapAttrs
.displayName
);
28 if (displayName
== null)
29 displayName
= props
.get(LdapAttrs
.cn
);
30 if (displayName
== null)
31 displayName
= props
.get(LdapAttrs
.uid
);
32 if (displayName
== null)
33 displayName
= user
.getName();
34 if (displayName
== null)
35 throw new UserDirectoryException("Cannot set display name for "
37 this.displayName
= displayName
.toString();
40 String
[] roles
= new String
[allRoles
.size()];
41 for (int i
= 0; i
< allRoles
.size(); i
++) {
42 roles
[i
] = allRoles
.get(i
).getName();
44 this.allRoles
= Collections
.unmodifiableList(Arrays
.asList(roles
));
48 public String
getName() {
53 public boolean hasRole(String name
) {
54 return allRoles
.contains(name
);
58 public String
[] getRoles() {
59 return allRoles
.toArray(new String
[allRoles
.size()]);
63 public int hashCode() {
65 return super.hashCode();
66 return name
.hashCode();
70 public boolean equals(Object obj
) {
71 if (!(obj
instanceof Authorization
))
73 Authorization that
= (Authorization
) obj
;
75 return that
.getName() == null;
76 return name
.equals(that
.getName());
80 public String
toString() {