Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  protected void addMemberOf(Fixture fixture, LdapTemplate template, String user)
      throws NamingException {
    List<String> dns =
        template.search(
            "",
            fixture.config.usernameFilter(user).encode(),
            new ContextMapper() {
              public Object mapFromContext(Object arg0) {
                DirContextAdapter ctx = (DirContextAdapter) arg0;
                return ctx.getNameInNamespace();
              }
            });
    assertEquals(dns.toString(), 1, dns.size());

    DistinguishedName name = new DistinguishedName(dns.get(0));
    DistinguishedName root =
        new DistinguishedName(
            template.getContextSource().getReadOnlyContext().getNameInNamespace());

    // Build a relative name
    for (int i = 0; i < root.size(); i++) {
      name.removeFirst();
    }

    DirContextOperations context = template.lookupContext(name);
    context.setAttributeValues("memberOf", new Object[] {"foo"});
    template.modifyAttributes(context);
  }
Exemplo n.º 2
0
 /** Construction dynamique d'un contact à partir du fullname */
 private Name buildDn(Operator_Ldap o) {
   DistinguishedName dn =
       new DistinguishedName(
           Settings.getString(Settings.SYSTEM.section, Settings.SYSTEM.base_user));
   dn.add("sn", o.getSn());
   return dn;
 }
Exemplo n.º 3
0
 /** Construction dynamique d'un contact à partir de uid */
 private Name buildDn(String sn) {
   DistinguishedName dn =
       new DistinguishedName(
           Settings.getString(Settings.SYSTEM.section, Settings.SYSTEM.base_user));
   dn.add("sn", sn);
   return dn;
 }
  @SuppressWarnings("unchecked")
  public List<Long> groups(
      String username,
      LdapConfig config,
      LdapOperations ldap,
      RoleProvider provider,
      AttributeSet attrSet) {

    Set<String> groupNames = attrSet.getAll(grpAttribute);
    if (groupNames == null) {
      throw new ValidationException(username + " has no attributes " + grpAttribute);
    }

    final GroupAttributeMapper mapper = new GroupAttributeMapper(config);

    // If filtered is activated, then load all group names as mapped
    // via the name field.
    //
    // TODO: this should likely be done via either paged queries
    // or once for each target.
    List<String> filteredNames = null;
    if (filtered) {
      String filter = config.getGroupFilter().encode();
      filteredNames = (List<String>) ldap.search("", filter, mapper);
    }

    List<Long> groups = new ArrayList<Long>();
    for (String grpName : groupNames) {
      // If DN is true, then we need to map from the attribute value
      // to the actual group name before comparing.
      if (dn) {
        DistinguishedName relative = config.relativeDN(grpName);
        String nameAttr = config.getGroupAttribute("name");
        grpName = relative.getValue(nameAttr);
      }

      // Apply filter if necessary.
      if (filtered && !filteredNames.contains(grpName)) {
        log.debug("Group not found by filter: " + grpName);
        continue;
      }

      // Finally, add the grou
      groups.add(provider.createGroup(grpName, null, false, true));
    }
    return groups;
  }
  /** Test the label and group methods */
  @Test
  public void testGetLabelandGroup() {

    Department dept =
        new LdapDepartmentImpl(
            "Applications Development",
            DistinguishedName.immutableDistinguishedName(
                "ou=Applications Development,ou=Applications,ou=Digital Initiatives"));

    assertEquals("APP", dept.getGroupAbbreviation());
    assertEquals("Applications Development (APP)", dept.getLabel());

    dept =
        new LdapDepartmentImpl(
            "Low Level Unit",
            DistinguishedName.immutableDistinguishedName("ou=lowlevel,ou=Digital Initiatives"));

    assertNull(dept.getGroupAbbreviation());
    assertEquals("Low Level Unit", dept.getLabel());
  }
  /** Test that sorting works correctly using the compareTo method */
  @Test
  public void testCompareTo() {

    Department empty = new LdapDepartmentImpl(null, DistinguishedName.EMPTY_PATH);
    Department a =
        new LdapDepartmentImpl(
            "Applications",
            DistinguishedName.immutableDistinguishedName("ou=Applications,ou=Digital Initiatives"));
    Department ap =
        new LdapDepartmentImpl(
            "Applications Development",
            DistinguishedName.immutableDistinguishedName(
                "ou=Applications Development,ou=Applications,ou=Digital Initiatives"));
    Department d =
        new LdapDepartmentImpl(
            "Digital Initiatives",
            DistinguishedName.immutableDistinguishedName("ou=Digital Initiatives"));
    Department h =
        new LdapDepartmentImpl(
            "Help Desk",
            DistinguishedName.immutableDistinguishedName("ou=Help Desk,ou=Digital Initiatives"));
    Department l =
        new LdapDepartmentImpl(
            "Low Level Unit",
            DistinguishedName.immutableDistinguishedName("ou=lowlevel,ou=Digital Initiatives"));
    Department on =
        new LdapDepartmentImpl(
            "Open Systems",
            DistinguishedName.immutableDistinguishedName("ou=Open Systems,ou=Digital Initiatives"));
    Department or =
        new LdapDepartmentImpl(
            "Operations",
            DistinguishedName.immutableDistinguishedName("ou=Operations,ou=Digital Initiatives"));
    Department w =
        new LdapDepartmentImpl(
            "Web Services",
            DistinguishedName.immutableDistinguishedName("ou=Web Services,ou=Digital Initiatives"));

    List<Department> list = new ArrayList<Department>();
    list.add(l);
    list.add(or);
    list.add(a);
    list.add(d);
    list.add(empty);
    list.add(on);
    list.add(h);
    list.add(w);
    list.add(ap);

    Collections.sort(list);

    // Check the sort
    assertEquals(a, list.get(0));
    assertEquals(ap, list.get(1));
    assertEquals(d, list.get(2));
    assertEquals(h, list.get(3));
    assertEquals(l, list.get(4));
    assertEquals(on, list.get(5));
    assertEquals(or, list.get(6));
    assertEquals(w, list.get(7));
    assertEquals(empty, list.get(8));
  }