X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.api.cms%2Fsrc%2Forg%2Fargeo%2Fapi%2Fcms%2Fauth%2FImpliedByPrincipal.java;fp=org.argeo.api.cms%2Fsrc%2Forg%2Fargeo%2Fapi%2Fcms%2Fauth%2FImpliedByPrincipal.java;h=21a6325942160023b8a641de3df74aa23aede7c9;hp=0000000000000000000000000000000000000000;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e diff --git a/org.argeo.api.cms/src/org/argeo/api/cms/auth/ImpliedByPrincipal.java b/org.argeo.api.cms/src/org/argeo/api/cms/auth/ImpliedByPrincipal.java new file mode 100644 index 000000000..21a632594 --- /dev/null +++ b/org.argeo.api.cms/src/org/argeo/api/cms/auth/ImpliedByPrincipal.java @@ -0,0 +1,72 @@ +package org.argeo.api.cms.auth; + +import java.security.Principal; +import java.util.HashSet; +import java.util.Set; + +import javax.xml.namespace.QName; + +/** + * A {@link Principal} which has been implied by an authorisation. If it is + * empty it means this is an additional identity, otherwise it lists the users + * (typically the logged-in user but possibly empty {@link ImpliedByPrincipal}s) + * which have implied it. When an additional identity is removed, the related + * {@link ImpliedByPrincipal}s can thus be removed. + */ +public final class ImpliedByPrincipal implements Principal { + private final String name; + private final QName roleName; + private final boolean systemRole; + private final String context; + + private Set causes = new HashSet(); + + public ImpliedByPrincipal(String name, Principal userPrincipal) { + this.name = name; + roleName = RoleNameUtils.getLastRdnAsName(name); + systemRole = RoleNameUtils.isSystemRole(roleName); + context = RoleNameUtils.getContext(name); + if (userPrincipal != null) + causes.add(userPrincipal); + } + + public String getName() { + return name; + } + + /* + * OBJECT + */ + + public QName getRoleName() { + return roleName; + } + + public String getContext() { + return context; + } + + public boolean isSystemRole() { + return systemRole; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ImpliedByPrincipal) { + ImpliedByPrincipal that = (ImpliedByPrincipal) obj; + // TODO check members too? + return name.equals(that.name); + } + return false; + } + + @Override + public String toString() { + return name.toString(); + } +}