示例#1
0
 /**
  * Reads JSON data from the reader and returns a search result.
  *
  * @return search result derived from the JSON
  * @throws IOException if an error occurs using the reader
  */
 @Override
 @SuppressWarnings("unchecked")
 public SearchResult read() throws IOException {
   final SearchResult result = new SearchResult(sortBehavior);
   try {
     final JSONParser parser = new JSONParser();
     final JSONArray jsonArray = (JSONArray) parser.parse(jsonReader);
     for (Object o : jsonArray) {
       final LdapEntry entry = new LdapEntry(sortBehavior);
       final JSONObject jsonObject = (JSONObject) o;
       for (Object k : jsonObject.keySet()) {
         final String attrName = (String) k;
         if ("dn".equalsIgnoreCase(attrName)) {
           entry.setDn((String) jsonObject.get(k));
         } else {
           final LdapAttribute attr = new LdapAttribute(sortBehavior);
           attr.setName(attrName);
           attr.addStringValues((List<String>) jsonObject.get(k));
           entry.addAttribute(attr);
         }
       }
       result.addEntry(entry);
     }
   } catch (ParseException e) {
     throw new IOException(e);
   }
   return result;
 }
示例#2
0
 /**
  * Creates a new ldap entry.
  *
  * @param dn dn for this entry
  * @param attr ldap attribute for this entry
  */
 public LdapEntry(final String dn, final LdapAttribute... attr) {
   this();
   setDn(dn);
   for (LdapAttribute a : attr) {
     addAttribute(a);
   }
 }
  /**
   * Creates an ldap entry containing float based string values.
   *
   * @return ldap entry
   */
  public static LdapEntry createLdapEntry() {
    final LdapAttribute typeArray1 = new LdapAttribute(SortBehavior.ORDERED);
    typeArray1.setName("typeArray1");
    typeArray1.addStringValue("301.1", "302.2");

    final LdapAttribute typeArray2 = new LdapAttribute(SortBehavior.ORDERED);
    typeArray2.setName("typeArray2");
    typeArray2.addStringValue("301.1", "302.2");

    final LdapAttribute typeCol1 = new LdapAttribute(SortBehavior.ORDERED);
    typeCol1.setName("typeCol1");
    typeCol1.addStringValue("501.5", "502.5");

    final LdapAttribute typeCol2 = new LdapAttribute(SortBehavior.ORDERED);
    typeCol2.setName("typeCol2");
    typeCol2.addStringValue("501.5", "502.5");

    final LdapAttribute typeSet1 = new LdapAttribute(SortBehavior.ORDERED);
    typeSet1.setName("typeSet1");
    typeSet1.addStringValue("601.6", "602.6");

    final LdapAttribute typeSet2 = new LdapAttribute(SortBehavior.ORDERED);
    typeSet2.setName("typeSet2");
    typeSet2.addStringValue("601.6", "602.6");

    final LdapAttribute typeList1 = new LdapAttribute(SortBehavior.ORDERED);
    typeList1.setName("typeList1");
    typeList1.addStringValue("701.7", "702.7");

    final LdapAttribute typeList2 = new LdapAttribute(SortBehavior.ORDERED);
    typeList2.setName("typeList2");
    typeList2.addStringValue("701.7", "702.7");

    final LdapEntry entry = new LdapEntry();
    entry.setDn("cn=Float Entry,ou=people,dc=ldaptive,dc=org");
    entry.addAttribute(
        new LdapAttribute("type1", "100.1"),
        new LdapAttribute("type2", "200.2"),
        new LdapAttribute("numberthree", "300.3"),
        typeArray1,
        typeArray2,
        typeCol1,
        typeCol2,
        typeSet1,
        typeSet2,
        typeList1,
        typeList2);
    return entry;
  }
  /**
   * Creates an ldap entry containing boolean based string values.
   *
   * @return ldap entry
   */
  public static LdapEntry createLdapEntry() {
    final LdapAttribute typeArray1 = new LdapAttribute(SortBehavior.ORDERED);
    typeArray1.setName("typeArray1");
    typeArray1.addStringValue("false", "true");

    final LdapAttribute typeArray2 = new LdapAttribute(SortBehavior.ORDERED);
    typeArray2.setName("typeArray2");
    typeArray2.addStringValue("false", "true");

    final LdapAttribute typeCol1 = new LdapAttribute(SortBehavior.ORDERED);
    typeCol1.setName("typeCol1");
    typeCol1.addStringValue("true", "false");

    final LdapAttribute typeCol2 = new LdapAttribute(SortBehavior.ORDERED);
    typeCol2.setName("typeCol2");
    typeCol2.addStringValue("false", "true");

    final LdapAttribute typeSet1 = new LdapAttribute(SortBehavior.ORDERED);
    typeSet1.setName("typeSet1");
    typeSet1.addStringValue("true", "false");

    final LdapAttribute typeSet2 = new LdapAttribute(SortBehavior.ORDERED);
    typeSet2.setName("typeSet2");
    typeSet2.addStringValue("true", "false");

    final LdapAttribute typeList1 = new LdapAttribute(SortBehavior.ORDERED);
    typeList1.setName("typeList1");
    typeList1.addStringValue("false", "true");

    final LdapAttribute typeList2 = new LdapAttribute(SortBehavior.ORDERED);
    typeList2.setName("typeList2");
    typeList2.addStringValue("true", "false");

    final LdapEntry entry = new LdapEntry();
    entry.setDn("cn=Boolean Entry,ou=people,dc=ldaptive,dc=org");
    entry.addAttribute(
        new LdapAttribute("type1", "true"),
        new LdapAttribute("type2", "false"),
        new LdapAttribute("booleanthree", "true"),
        typeArray1,
        typeArray2,
        typeCol1,
        typeCol2,
        typeSet1,
        typeSet2,
        typeList1,
        typeList2);
    return entry;
  }
  /**
   * Creates an ldap entry containing binary data.
   *
   * @return ldap entry
   */
  public static LdapEntry createLdapEntry() {
    // CheckStyle:MagicNumber OFF
    final LdapAttribute typeCol1 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeCol1.setName("typeCol1");
    typeCol1.addBinaryValue(new byte[] {0x20, 0x0F, 0x1F}, new byte[] {0x21});

    final LdapAttribute typeCol2 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeCol2.setName("typeCol2");
    typeCol2.addBinaryValue(new byte[] {0x20, 0x0F, 0x1F}, new byte[] {0x21});

    final LdapAttribute typeSet1 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeSet1.setName("typeSet1");
    typeSet1.addBinaryValue(new byte[] {0x22, 0x0F, 0x1F}, new byte[] {0x23});

    final LdapAttribute typeSet2 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeSet2.setName("typeSet2");
    typeSet2.addBinaryValue(new byte[] {0x22, 0x0F, 0x1F}, new byte[] {0x23});

    final LdapAttribute typeList1 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeList1.setName("typeList1");
    typeList1.addBinaryValue(new byte[] {0x24, 0x0F, 0x1F}, new byte[] {0x25});

    final LdapAttribute typeList2 = new LdapAttribute(SortBehavior.ORDERED, true);
    typeList2.setName("typeList2");
    typeList2.addBinaryValue(new byte[] {0x24, 0x0F, 0x1F}, new byte[] {0x25});

    final LdapEntry entry = new LdapEntry();
    entry.setDn("cn=Binary Entry,ou=people,dc=ldaptive,dc=org");
    entry.addAttribute(
        new LdapAttribute("customname1", new byte[] {0x40, 0x41, 0x42, 0x43}),
        new LdapAttribute(
            "customname2",
            new byte[] {0x44, 0x45, 0x46, 0x47},
            new byte[] {0x48, 0x49, 0x50, 0x51}),
        new LdapAttribute("type1", new byte[] {0x01}),
        new LdapAttribute("type2", new byte[] {0x02, 0x0F}),
        new LdapAttribute("binarythree", new byte[] {0x03, 0x0F, 0x1F}),
        typeCol1,
        typeCol2,
        typeSet1,
        typeSet2,
        typeList1,
        typeList2);
    return entry;
    // CheckStyle:MagicNumber ON
  }
示例#6
0
 /**
  * Creates a new ldap entry.
  *
  * @param dn dn for this entry
  * @param attrs collection of attributes to add
  */
 public LdapEntry(final String dn, final Collection<LdapAttribute> attrs) {
   this();
   setDn(dn);
   addAttributes(attrs);
 }
示例#7
0
 /**
  * Creates a new ldap entry.
  *
  * @param dn dn for this entry
  */
 public LdapEntry(final String dn) {
   this();
   setDn(dn);
 }