X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.security.core%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifGroup.java;h=4154d55a74ffec26983324055449d80ff55eebae;hb=40c3800ea57d5de136137e3fb0ff07cf54f2df48;hp=c2c666700710c994aa6af93c080c066854ba2cca;hpb=e96c7f26228b70f604e41b7a56ce6c5836da9e12;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifGroup.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifGroup.java index c2c666700..4154d55a7 100644 --- a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifGroup.java +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifGroup.java @@ -12,6 +12,8 @@ import org.osgi.service.useradmin.Group; import org.osgi.service.useradmin.Role; public class LdifGroup extends LdifUser implements Group { + // optimisation + List directMembers = null; public LdifGroup(LdapName dn, Attributes attributes) { super(dn, attributes); @@ -34,17 +36,55 @@ public class LdifGroup extends LdifUser implements Group { @Override public Role[] getMembers() { + if (directMembers != null) + return directMembers.toArray(new Role[directMembers.size()]); + else + throw new ArgeoUserAdminException("Members have not been loaded."); + + // Attribute memberAttribute = getAttributes().get("member"); + // if (memberAttribute == null) + // return new Role[0]; + // try { + // List roles = new ArrayList(); + // NamingEnumeration values = memberAttribute.getAll(); + // while (values.hasMore()) { + // LdapName dn = new LdapName(values.next().toString()); + // roles.add(new LdifUser(dn, null)); + // } + // return roles.toArray(new Role[roles.size()]); + // } catch (Exception e) { + // throw new ArgeoUserAdminException("Cannot get members", e); + // } + } + + void loadMembers(LdifUserAdmin userAdmin) { + directMembers = new ArrayList(); + for (LdapName ldapName : getMemberNames()) { + LdifUser role; + if (userAdmin.groups.containsKey(ldapName)) + role = userAdmin.groups.get(ldapName); + else if (userAdmin.users.containsKey(ldapName)) + role = userAdmin.users.get(ldapName); + else + throw new ArgeoUserAdminException("No roel found for " + + ldapName); + role.directMemberOf.add(this); + directMembers.add(role); + } + } + + List getMemberNames() { Attribute memberAttribute = getAttributes().get("member"); if (memberAttribute == null) - return new Role[0]; + return new ArrayList(); try { - List roles = new ArrayList(); - NamingEnumeration values = memberAttribute.getAll(); + List roles = new ArrayList(); + NamingEnumeration values = memberAttribute.getAll(); while (values.hasMore()) { LdapName dn = new LdapName(values.next().toString()); - roles.add(new LdifUser(dn, null)); + roles.add(dn); } - return roles.toArray(new Role[roles.size()]); + return roles; } catch (Exception e) { throw new ArgeoUserAdminException("Cannot get members", e); } @@ -59,5 +99,4 @@ public class LdifGroup extends LdifUser implements Group { public int getType() { return GROUP; } - }