Clarify ACR API
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / ImpliedByPrincipal.java
index 7386d5fe5fedbf6bb9bacd8377adfd11295a30d5..9e0ebce97d230ec24828ccbbb548786855013ae6 100644 (file)
@@ -1,15 +1,12 @@
 package org.argeo.cms.internal.auth;
 
 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.cms.RoleNameUtils;
 import org.osgi.service.useradmin.Authorization;
 
 /**
@@ -21,43 +18,40 @@ import org.osgi.service.useradmin.Authorization;
  * removed.
  */
 public final class ImpliedByPrincipal implements Principal {
-       private final LdapName name;
+       private final String name;
+       private final QName roleName;
+       private final boolean systemRole;
+       private final String context;
+
        private Set<Principal> causes = new HashSet<Principal>();
 
        public ImpliedByPrincipal(String name, Principal userPrincipal) {
-               try {
-                       this.name = new LdapName(name);
-               } catch (InvalidNameException e) {
-                       throw new CmsException("Badly formatted role name", e);
-               }
-               if (userPrincipal != null)
-                       causes.add(userPrincipal);
-       }
-
-       public ImpliedByPrincipal(LdapName 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.toString();
+               return name;
        }
 
-       public boolean addMember(Principal user) {
-               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<? extends Principal> members() {
-               return Collections.enumeration(causes);
+       public boolean isSystemRole() {
+               return systemRole;
        }
 
        @Override
@@ -67,8 +61,6 @@ public final class ImpliedByPrincipal implements Principal {
 
        @Override
        public boolean equals(Object obj) {
-               // if (this == obj)
-               // return true;
                if (obj instanceof ImpliedByPrincipal) {
                        ImpliedByPrincipal that = (ImpliedByPrincipal) obj;
                        // TODO check members too?
@@ -79,7 +71,6 @@ public final class ImpliedByPrincipal implements Principal {
 
        @Override
        public String toString() {
-               // return name.toString() + " implied by " + causes;
                return name.toString();
        }
 }