]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java
1 package org
.argeo
.cms
.internal
.auth
;
3 import java
.security
.Principal
;
4 import java
.security
.acl
.Group
;
5 import java
.util
.Collections
;
6 import java
.util
.Enumeration
;
7 import java
.util
.HashSet
;
10 import javax
.naming
.InvalidNameException
;
11 import javax
.naming
.ldap
.LdapName
;
13 import org
.argeo
.cms
.CmsException
;
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 meeans 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 * identityx is removed, the related {@link ImpliedByPrincipal}s can thus be
24 public final class ImpliedByPrincipal
implements Group
{
25 private final LdapName name
;
26 private Set
<Principal
> causes
= new HashSet
<Principal
>();
28 public ImpliedByPrincipal(String name
, Principal userPrincipal
) {
30 this.name
= new LdapName(name
);
31 } catch (InvalidNameException e
) {
32 throw new CmsException("Badly formatted role name", e
);
34 if (userPrincipal
!= null)
35 causes
.add(userPrincipal
);
38 public ImpliedByPrincipal(LdapName name
, Principal userPrincipal
) {
40 if (userPrincipal
!= null)
41 causes
.add(userPrincipal
);
45 public String
getName() {
46 return name
.toString();
50 public boolean addMember(Principal user
) {
51 throw new UnsupportedOperationException();
55 public boolean removeMember(Principal user
) {
56 throw new UnsupportedOperationException();
60 public boolean isMember(Principal member
) {
61 return causes
.contains(member
);
65 public Enumeration
<?
extends Principal
> members() {
66 return Collections
.enumeration(causes
);
70 public int hashCode() {
71 return name
.hashCode();
75 public boolean equals(Object obj
) {
78 if (obj
instanceof ImpliedByPrincipal
) {
79 ImpliedByPrincipal that
= (ImpliedByPrincipal
) obj
;
80 // TODO check members too?
81 return name
.equals(that
.name
);
87 public String
toString() {
88 // return name.toString() + " implied by " + causes;
89 return name
.toString();