]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - internal/auth/ImpliedByPrincipal.java
1 package org
.argeo
.cms
.internal
.auth
;
3 import static org
.argeo
.api
.acr
.RuntimeNamespaceContext
.getNamespaceContext
;
5 import java
.security
.Principal
;
6 import java
.util
.HashSet
;
9 import javax
.xml
.namespace
.QName
;
11 import org
.argeo
.api
.acr
.CrName
;
12 import org
.argeo
.api
.acr
.NamespaceUtils
;
13 import org
.argeo
.cms
.auth
.RoleNameUtils
;
14 import org
.osgi
.service
.useradmin
.Authorization
;
17 * A {@link Principal} which has been implied by an {@link Authorization}. If it
18 * is empty it means this is an additional identity, otherwise it lists the
19 * users (typically the logged in user but possibly empty
20 * {@link ImpliedByPrincipal}s) which have implied it. When an additional
21 * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
24 public final class ImpliedByPrincipal
implements Principal
{
25 private final String name
;
26 private Set
<Principal
> causes
= new HashSet
<Principal
>();
28 private QName roleName
;
29 // private int type = Role.ROLE;
31 private boolean systemRole
= false;
32 private String context
;
34 public ImpliedByPrincipal(String name
, Principal userPrincipal
) {
36 String cn
= RoleNameUtils
.getLastRdnValue(name
);
37 roleName
= NamespaceUtils
.parsePrefixedName(getNamespaceContext(), cn
);
38 if (roleName
.getNamespaceURI().equals(CrName
.ROLE_NAMESPACE_URI
)) {
41 context
= RoleNameUtils
.getContext(name
);
43 // this.name = new LdapName(name);
44 // } catch (InvalidNameException e) {
45 // throw new IllegalArgumentException("Badly formatted role name", e);
47 if (userPrincipal
!= null)
48 causes
.add(userPrincipal
);
51 // public ImpliedByPrincipal(LdapName name, Principal userPrincipal) {
53 // if (userPrincipal != null)
54 // causes.add(userPrincipal);
57 public String
getName() {
64 // public boolean addMember(Principal user) {
65 // throw new UnsupportedOperationException();
68 // public boolean removeMember(Principal user) {
69 // throw new UnsupportedOperationException();
72 // public boolean isMember(Principal member) {
73 // return causes.contains(member);
76 // public Enumeration<? extends Principal> members() {
77 // return Collections.enumeration(causes);
81 // /** Type of {@link Role}, if known. */
82 // public int getType() {
86 // /** Not supported for the time being. */
87 // public Dictionary<String, Object> getProperties() {
88 // throw new UnsupportedOperationException();
95 public QName
getRoleName() {
99 public String
getContext() {
103 public boolean isSystemRole() {
108 public int hashCode() {
109 return name
.hashCode();
113 public boolean equals(Object obj
) {
116 if (obj
instanceof ImpliedByPrincipal
) {
117 ImpliedByPrincipal that
= (ImpliedByPrincipal
) obj
;
118 // TODO check members too?
119 return name
.equals(that
.name
);
125 public String
toString() {
126 // return name.toString() + " implied by " + causes;
127 return name
.toString();