Multiple user referentials working with IPA.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / osgi / useradmin / LdifGroup.java
index 72b08a8c3d0fc59c78fd3a0f3dc35ec45a0ffbd1..bdf34aa91414ea77bcc7799bef02e7fa7a260011 100644 (file)
@@ -4,23 +4,18 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.InvalidNameException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapName;
 
-import org.argeo.util.directory.FunctionalGroup;
-import org.argeo.util.directory.Organization;
-import org.argeo.util.directory.SystemPermissions;
+import org.argeo.util.directory.ldap.AbstractLdapDirectory;
 import org.osgi.service.useradmin.Role;
 
 /** Directory group implementation */
-abstract class LdifGroup extends LdifUser implements DirectoryGroup {
+class LdifGroup extends LdifUser implements DirectoryGroup {
        private final String memberAttributeId;
 
-       LdifGroup(AbstractUserDirectory userAdmin, LdapName dn, Attributes attributes) {
-               super(userAdmin, dn, attributes);
+       LdifGroup(AbstractLdapDirectory userAdmin, LdapName dn) {
+               super(userAdmin, dn);
                memberAttributeId = userAdmin.getMemberAttributeId();
        }
 
@@ -74,7 +69,7 @@ abstract class LdifGroup extends LdifUser implements DirectoryGroup {
        @Override
        public Role[] getMembers() {
                List<Role> directMembers = new ArrayList<Role>();
-               for (LdapName ldapName : getMemberNames()) {
+               for (LdapName ldapName : getReferences(memberAttributeId)) {
                        Role role = findRole(ldapName);
                        if (role == null) {
                                throw new IllegalStateException("Role " + ldapName + " not found.");
@@ -98,23 +93,23 @@ abstract class LdifGroup extends LdifUser implements DirectoryGroup {
                return role;
        }
 
-       @Override
-       public List<LdapName> getMemberNames() {
-               Attribute memberAttribute = getAttributes().get(memberAttributeId);
-               if (memberAttribute == null)
-                       return new ArrayList<LdapName>();
-               try {
-                       List<LdapName> roles = new ArrayList<LdapName>();
-                       NamingEnumeration<?> values = memberAttribute.getAll();
-                       while (values.hasMore()) {
-                               LdapName dn = new LdapName(values.next().toString());
-                               roles.add(dn);
-                       }
-                       return roles;
-               } catch (NamingException e) {
-                       throw new IllegalStateException("Cannot get members", e);
-               }
-       }
+//     @Override
+//     public List<LdapName> getMemberNames() {
+//             Attribute memberAttribute = getAttributes().get(memberAttributeId);
+//             if (memberAttribute == null)
+//                     return new ArrayList<LdapName>();
+//             try {
+//                     List<LdapName> roles = new ArrayList<LdapName>();
+//                     NamingEnumeration<?> values = memberAttribute.getAll();
+//                     while (values.hasMore()) {
+//                             LdapName dn = new LdapName(values.next().toString());
+//                             roles.add(dn);
+//                     }
+//                     return roles;
+//             } catch (NamingException e) {
+//                     throw new IllegalStateException("Cannot get members", e);
+//             }
+//     }
 
        @Override
        public Role[] getRequiredMembers() {
@@ -126,30 +121,7 @@ abstract class LdifGroup extends LdifUser implements DirectoryGroup {
                return GROUP;
        }
 
-       /*
-        * KIND
-        */
-       static class LdifFunctionalGroup extends LdifGroup implements FunctionalGroup {
-
-               public LdifFunctionalGroup(AbstractUserDirectory userAdmin, LdapName dn, Attributes attributes) {
-                       super(userAdmin, dn, attributes);
-               }
-
-       }
-
-       static class LdifOrganization extends LdifGroup implements Organization {
-
-               public LdifOrganization(AbstractUserDirectory userAdmin, LdapName dn, Attributes attributes) {
-                       super(userAdmin, dn, attributes);
-               }
-
-       }
-
-       static class LdifSystemPermissions extends LdifGroup implements SystemPermissions {
-
-               public LdifSystemPermissions(AbstractUserDirectory userAdmin, LdapName dn, Attributes attributes) {
-                       super(userAdmin, dn, attributes);
-               }
-
+       protected DirectoryUserAdmin getUserAdmin() {
+               return (DirectoryUserAdmin) getDirectory();
        }
 }