]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ImpliedByPrincipal.java
7386d5fe5fedbf6bb9bacd8377adfd11295a30d5
1 package org
.argeo
.cms
.internal
.auth
;
3 import java
.security
.Principal
;
4 import java
.util
.Collections
;
5 import java
.util
.Enumeration
;
6 import java
.util
.HashSet
;
9 import javax
.naming
.InvalidNameException
;
10 import javax
.naming
.ldap
.LdapName
;
12 import org
.argeo
.cms
.CmsException
;
13 import org
.osgi
.service
.useradmin
.Authorization
;
16 * A {@link Principal} which has been implied by an {@link Authorization}. If it
17 * is empty it means this is an additional identity, otherwise it lists the
18 * users (typically the logged in user but possibly empty
19 * {@link ImpliedByPrincipal}s) which have implied it. When an additional
20 * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
23 public final class ImpliedByPrincipal
implements Principal
{
24 private final LdapName name
;
25 private Set
<Principal
> causes
= new HashSet
<Principal
>();
27 public ImpliedByPrincipal(String name
, Principal userPrincipal
) {
29 this.name
= new LdapName(name
);
30 } catch (InvalidNameException e
) {
31 throw new CmsException("Badly formatted role name", e
);
33 if (userPrincipal
!= null)
34 causes
.add(userPrincipal
);
37 public ImpliedByPrincipal(LdapName name
, Principal userPrincipal
) {
39 if (userPrincipal
!= null)
40 causes
.add(userPrincipal
);
43 public String
getName() {
44 return name
.toString();
47 public boolean addMember(Principal user
) {
48 throw new UnsupportedOperationException();
51 public boolean removeMember(Principal user
) {
52 throw new UnsupportedOperationException();
55 public boolean isMember(Principal member
) {
56 return causes
.contains(member
);
59 public Enumeration
<?
extends Principal
> members() {
60 return Collections
.enumeration(causes
);
64 public int hashCode() {
65 return name
.hashCode();
69 public boolean equals(Object obj
) {
72 if (obj
instanceof ImpliedByPrincipal
) {
73 ImpliedByPrincipal that
= (ImpliedByPrincipal
) obj
;
74 // TODO check members too?
75 return name
.equals(that
.name
);
81 public String
toString() {
82 // return name.toString() + " implied by " + causes;
83 return name
.toString();