]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/osgi/useradmin/AggregatingAuthorization.java
1 package org
.argeo
.cms
.osgi
.useradmin
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collections
;
5 import java
.util
.HashSet
;
9 import javax
.security
.auth
.x500
.X500Principal
;
11 import org
.argeo
.api
.cms
.directory
.CmsAuthorization
;
12 import org
.osgi
.service
.useradmin
.Authorization
;
14 /** An {@link Authorization} which combines roles form various auth sources. */
15 class AggregatingAuthorization
implements CmsAuthorization
{
16 private final String name
;
17 private final String displayName
;
18 private final Set
<String
> systemRoles
;
19 private final Set
<String
> roles
;
21 public AggregatingAuthorization(String name
, String displayName
, Set
<String
> systemRoles
, String
[] roles
) {
22 this.name
= new X500Principal(name
).getName();
23 this.displayName
= displayName
;
24 this.systemRoles
= Collections
.unmodifiableSet(new HashSet
<>(systemRoles
));
25 Set
<String
> temp
= new HashSet
<>();
26 for (String role
: roles
) {
27 if (!temp
.contains(role
))
30 this.roles
= Collections
.unmodifiableSet(temp
);
34 public String
getName() {
39 public boolean hasRole(String name
) {
40 if (systemRoles
.contains(name
))
42 if (roles
.contains(name
))
48 public String
[] getRoles() {
49 int size
= systemRoles
.size() + roles
.size();
50 List
<String
> res
= new ArrayList
<String
>(size
);
51 res
.addAll(systemRoles
);
53 return res
.toArray(new String
[size
]);
57 public int hashCode() {
59 return super.hashCode();
60 return name
.hashCode();
64 public boolean equals(Object obj
) {
65 if (!(obj
instanceof Authorization
))
67 Authorization that
= (Authorization
) obj
;
69 return that
.getName() == null;
70 return name
.equals(that
.getName());
74 public String
toString() {