Improve CMS security layer documentation.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / ImpliedByPrincipal.java
index 7386d5fe5fedbf6bb9bacd8377adfd11295a30d5..c753601296657c9e69d03499a7b931ad9bdf8ee4 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.cms.internal.auth;
 
 import java.security.Principal;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
@@ -9,8 +10,8 @@ import java.util.Set;
 import javax.naming.InvalidNameException;
 import javax.naming.ldap.LdapName;
 
-import org.argeo.cms.CmsException;
 import org.osgi.service.useradmin.Authorization;
+import org.osgi.service.useradmin.Role;
 
 /**
  * A {@link Principal} which has been implied by an {@link Authorization}. If it
@@ -20,15 +21,17 @@ import org.osgi.service.useradmin.Authorization;
  * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
  * removed.
  */
-public final class ImpliedByPrincipal implements Principal {
+public final class ImpliedByPrincipal implements Principal, Role {
        private final LdapName name;
        private Set<Principal> causes = new HashSet<Principal>();
 
+       private int type = Role.ROLE;
+
        public ImpliedByPrincipal(String name, Principal userPrincipal) {
                try {
                        this.name = new LdapName(name);
                } catch (InvalidNameException e) {
-                       throw new CmsException("Badly formatted role name", e);
+                       throw new IllegalArgumentException("Badly formatted role name", e);
                }
                if (userPrincipal != null)
                        causes.add(userPrincipal);
@@ -60,6 +63,26 @@ public final class ImpliedByPrincipal implements Principal {
                return Collections.enumeration(causes);
        }
 
+       /*
+        * USER ADMIN
+        */
+
+       @Override
+       /** Type of {@link Role}, if known. */
+       public int getType() {
+               return type;
+       }
+
+       @Override
+       /** Not supported for the time being. */
+       public Dictionary<String, Object> getProperties() {
+               throw new UnsupportedOperationException();
+       }
+
+       /*
+        * OBJECT
+        */
+
        @Override
        public int hashCode() {
                return name.hashCode();