]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java
Fix automated Kerberos config
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / ImpliedByPrincipal.java
1 package org.argeo.cms.internal.auth;
2
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;
8 import java.util.Set;
9
10 import javax.naming.InvalidNameException;
11 import javax.naming.ldap.LdapName;
12
13 import org.argeo.cms.CmsException;
14 import org.osgi.service.useradmin.Authorization;
15
16 /**
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
22 * removed.
23 */
24 public final class ImpliedByPrincipal implements Group {
25 private final LdapName name;
26 private Set<Principal> causes = new HashSet<Principal>();
27
28 public ImpliedByPrincipal(String name, Principal userPrincipal) {
29 try {
30 this.name = new LdapName(name);
31 } catch (InvalidNameException e) {
32 throw new CmsException("Badly formatted role name", e);
33 }
34 if (userPrincipal != null)
35 causes.add(userPrincipal);
36 }
37
38 public ImpliedByPrincipal(LdapName name, Principal userPrincipal) {
39 this.name = name;
40 if (userPrincipal != null)
41 causes.add(userPrincipal);
42 }
43
44 @Override
45 public String getName() {
46 return name.toString();
47 }
48
49 @Override
50 public boolean addMember(Principal user) {
51 throw new UnsupportedOperationException();
52 }
53
54 @Override
55 public boolean removeMember(Principal user) {
56 throw new UnsupportedOperationException();
57 }
58
59 @Override
60 public boolean isMember(Principal member) {
61 return causes.contains(member);
62 }
63
64 @Override
65 public Enumeration<? extends Principal> members() {
66 return Collections.enumeration(causes);
67 }
68
69 @Override
70 public int hashCode() {
71 return name.hashCode();
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 // if (this == obj)
77 // return true;
78 if (obj instanceof ImpliedByPrincipal) {
79 ImpliedByPrincipal that = (ImpliedByPrincipal) obj;
80 // TODO check members too?
81 return name.equals(that.name);
82 }
83 return false;
84 }
85
86 @Override
87 public String toString() {
88 // return name.toString() + " implied by " + causes;
89 return name.toString();
90 }
91 }