]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java
5afacf69db134c522274dbe812a0291bd40c5efa
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
.argeo
.cms
.CmsException
;
14 import org
.osgi
.service
.useradmin
.Authorization
;
15 import org
.osgi
.service
.useradmin
.Role
;
18 * A {@link Principal} which has been implied by an {@link Authorization}. If it
19 * is empty it means this is an additional identity, otherwise it lists the
20 * users (typically the logged in user but possibly empty
21 * {@link ImpliedByPrincipal}s) which have implied it. When an additional
22 * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
25 public final class ImpliedByPrincipal
implements Principal
, Role
{
26 private final LdapName name
;
27 private Set
<Principal
> causes
= new HashSet
<Principal
>();
29 private int type
= Role
.ROLE
;
31 public ImpliedByPrincipal(String name
, Principal userPrincipal
) {
33 this.name
= new LdapName(name
);
34 } catch (InvalidNameException e
) {
35 throw new CmsException("Badly formatted role name", e
);
37 if (userPrincipal
!= null)
38 causes
.add(userPrincipal
);
41 public ImpliedByPrincipal(LdapName name
, Principal userPrincipal
) {
43 if (userPrincipal
!= null)
44 causes
.add(userPrincipal
);
47 public String
getName() {
48 return name
.toString();
51 public boolean addMember(Principal user
) {
52 throw new UnsupportedOperationException();
55 public boolean removeMember(Principal user
) {
56 throw new UnsupportedOperationException();
59 public boolean isMember(Principal member
) {
60 return causes
.contains(member
);
63 public Enumeration
<?
extends Principal
> members() {
64 return Collections
.enumeration(causes
);
72 /** Type of {@link Role}, if known. */
73 public int getType() {
78 /** Not supported for the time being. */
79 public Dictionary
<String
, Object
> getProperties() {
80 throw new UnsupportedOperationException();
88 public int hashCode() {
89 return name
.hashCode();
93 public boolean equals(Object obj
) {
96 if (obj
instanceof ImpliedByPrincipal
) {
97 ImpliedByPrincipal that
= (ImpliedByPrincipal
) obj
;
98 // TODO check members too?
99 return name
.equals(that
.name
);
105 public String
toString() {
106 // return name.toString() + " implied by " + causes;
107 return name
.toString();