]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java
Improve ACR attribute typing.
[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.util.HashSet;
5 import java.util.Set;
6
7 import javax.xml.namespace.QName;
8
9 import org.argeo.cms.RoleNameUtils;
10 import org.osgi.service.useradmin.Authorization;
11
12 /**
13 * A {@link Principal} which has been implied by an {@link Authorization}. If it
14 * is empty it means this is an additional identity, otherwise it lists the
15 * users (typically the logged in user but possibly empty
16 * {@link ImpliedByPrincipal}s) which have implied it. When an additional
17 * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
18 * removed.
19 */
20 public final class ImpliedByPrincipal implements Principal {
21 private final String name;
22 private final QName roleName;
23 private final boolean systemRole;
24 private final String context;
25
26 private Set<Principal> causes = new HashSet<Principal>();
27
28 public ImpliedByPrincipal(String name, Principal userPrincipal) {
29 this.name = name;
30 roleName = RoleNameUtils.getLastRdnAsName(name);
31 systemRole = RoleNameUtils.isSystemRole(roleName);
32 context = RoleNameUtils.getContext(name);
33 if (userPrincipal != null)
34 causes.add(userPrincipal);
35 }
36
37 public String getName() {
38 return name;
39 }
40
41 /*
42 * OBJECT
43 */
44
45 public QName getRoleName() {
46 return roleName;
47 }
48
49 public String getContext() {
50 return context;
51 }
52
53 public boolean isSystemRole() {
54 return systemRole;
55 }
56
57 @Override
58 public int hashCode() {
59 return name.hashCode();
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (obj instanceof ImpliedByPrincipal) {
65 ImpliedByPrincipal that = (ImpliedByPrincipal) obj;
66 // TODO check members too?
67 return name.equals(that.name);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return name.toString();
75 }
76 }