X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fauth%2FImpliedByPrincipal.java;h=73f474637750a2f61aa825cddbdc0d12861df99e;hb=25316bb35087da302a0916c1e0bdf2fc09e8feb0;hp=7386d5fe5fedbf6bb9bacd8377adfd11295a30d5;hpb=2cdcc7410782f46eac9a4a505de12e33f67acf15;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java b/org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java index 7386d5fe5..73f474637 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/auth/ImpliedByPrincipal.java @@ -1,15 +1,16 @@ package org.argeo.cms.internal.auth; +import static org.argeo.api.acr.RuntimeNamespaceContext.getNamespaceContext; + import java.security.Principal; -import java.util.Collections; -import java.util.Enumeration; import java.util.HashSet; import java.util.Set; -import javax.naming.InvalidNameException; -import javax.naming.ldap.LdapName; +import javax.xml.namespace.QName; -import org.argeo.cms.CmsException; +import org.argeo.api.acr.CrName; +import org.argeo.api.acr.NamespaceUtils; +import org.argeo.cms.auth.RoleNameUtils; import org.osgi.service.useradmin.Authorization; /** @@ -21,43 +22,86 @@ import org.osgi.service.useradmin.Authorization; * removed. */ public final class ImpliedByPrincipal implements Principal { - private final LdapName name; + private final String name; private Set causes = new HashSet(); + private QName roleName; +// private int type = Role.ROLE; + + private boolean systemRole = false; + private String context; + public ImpliedByPrincipal(String name, Principal userPrincipal) { - try { - this.name = new LdapName(name); - } catch (InvalidNameException e) { - throw new CmsException("Badly formatted role name", e); + this.name = name; + String cn = RoleNameUtils.getLastRdnValue(name); + roleName = NamespaceUtils.parsePrefixedName(getNamespaceContext(), cn); + if (roleName.getNamespaceURI().equals(CrName.ROLE_NAMESPACE_URI)) { + systemRole = true; } + context = RoleNameUtils.getContext(name); +// try { +// this.name = new LdapName(name); +// } catch (InvalidNameException e) { +// throw new IllegalArgumentException("Badly formatted role name", e); +// } if (userPrincipal != null) causes.add(userPrincipal); } - public ImpliedByPrincipal(LdapName name, Principal userPrincipal) { - this.name = name; - if (userPrincipal != null) - causes.add(userPrincipal); - } +// public ImpliedByPrincipal(LdapName name, Principal userPrincipal) { +// this.name = name; +// if (userPrincipal != null) +// causes.add(userPrincipal); +// } public String getName() { - return name.toString(); + return name; } - public boolean addMember(Principal user) { - throw new UnsupportedOperationException(); - } + /* + * USER ADMIN + */ +// public boolean addMember(Principal user) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean removeMember(Principal user) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean isMember(Principal member) { +// return causes.contains(member); +// } +// +// public Enumeration members() { +// return Collections.enumeration(causes); +// } +// +// +// /** Type of {@link Role}, if known. */ +// public int getType() { +// return type; +// } +// +// /** Not supported for the time being. */ +// public Dictionary getProperties() { +// throw new UnsupportedOperationException(); +// } + + /* + * OBJECT + */ - public boolean removeMember(Principal user) { - throw new UnsupportedOperationException(); + public QName getRoleName() { + return roleName; } - public boolean isMember(Principal member) { - return causes.contains(member); + public String getContext() { + return context; } - public Enumeration members() { - return Collections.enumeration(causes); + public boolean isSystemRole() { + return systemRole; } @Override