Improve integration.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / ImpliedByPrincipal.java
index 829c17e35d78be824cc5913445fcbe020cb1b952..5afacf69db134c522274dbe812a0291bd40c5efa 100644 (file)
@@ -1,8 +1,8 @@
 package org.argeo.cms.internal.auth;
 
 import java.security.Principal;
-import java.security.acl.Group;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
@@ -12,19 +12,22 @@ 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
- * is empty it meeans this is an additional identity, otherwise it lists the
+ * 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
- * identityx is removed, the related {@link ImpliedByPrincipal}s can thus be
+ * identity is removed, the related {@link ImpliedByPrincipal}s can thus be
  * removed.
  */
-public final class ImpliedByPrincipal implements Group {
+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);
@@ -41,31 +44,46 @@ public final class ImpliedByPrincipal implements Group {
                        causes.add(userPrincipal);
        }
 
-       @Override
        public String getName() {
                return name.toString();
        }
 
-       @Override
        public boolean addMember(Principal user) {
                throw new UnsupportedOperationException();
        }
 
-       @Override
        public boolean removeMember(Principal user) {
                throw new UnsupportedOperationException();
        }
 
-       @Override
        public boolean isMember(Principal member) {
                return causes.contains(member);
        }
 
-       @Override
        public Enumeration<? extends Principal> members() {
                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();
@@ -85,6 +103,7 @@ public final class ImpliedByPrincipal implements Group {
 
        @Override
        public String toString() {
-               return name.toString() + " implied by " + causes;
+               // return name.toString() + " implied by " + causes;
+               return name.toString();
        }
 }