]>
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
.util
.Collections
;
5 import java
.util
.Dictionary
;
6 import java
.util
.Enumeration
;
7 import java
.util
.HashSet
;
10 import javax
.naming
.InvalidNameException
;
11 import javax
.naming
.ldap
.LdapName
;
13 import org
.osgi
.service
.useradmin
.Authorization
;
14 import org
.osgi
.service
.useradmin
.Role
;
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
, Role
{
25 private final LdapName name
;
26 private Set
<Principal
> causes
= new HashSet
<Principal
>();
28 private int type
= Role
.ROLE
;
30 public ImpliedByPrincipal(String name
, Principal userPrincipal
) {
32 this.name
= new LdapName(name
);
33 } catch (InvalidNameException e
) {
34 throw new IllegalArgumentException("Badly formatted role name", e
);
36 if (userPrincipal
!= null)
37 causes
.add(userPrincipal
);
40 public ImpliedByPrincipal(LdapName name
, Principal userPrincipal
) {
42 if (userPrincipal
!= null)
43 causes
.add(userPrincipal
);
46 public String
getName() {
47 return name
.toString();
50 public boolean addMember(Principal user
) {
51 throw new UnsupportedOperationException();
54 public boolean removeMember(Principal user
) {
55 throw new UnsupportedOperationException();
58 public boolean isMember(Principal member
) {
59 return causes
.contains(member
);
62 public Enumeration
<?
extends Principal
> members() {
63 return Collections
.enumeration(causes
);
71 /** Type of {@link Role}, if known. */
72 public int getType() {
77 /** Not supported for the time being. */
78 public Dictionary
<String
, Object
> getProperties() {
79 throw new UnsupportedOperationException();
87 public int hashCode() {
88 return name
.hashCode();
92 public boolean equals(Object obj
) {
95 if (obj
instanceof ImpliedByPrincipal
) {
96 ImpliedByPrincipal that
= (ImpliedByPrincipal
) obj
;
97 // TODO check members too?
98 return name
.equals(that
.name
);
104 public String
toString() {
105 // return name.toString() + " implied by " + causes;
106 return name
.toString();