@Override // ZMutableEntry
 public void setAttr(String attrName, String value) {
   if (hasAttribute(attrName)) {
     entry.removeAttribute(attrName);
   }
   entry.addAttribute(attrName, value);
 }
  @Override
  public Entry translate(Entry original, long firstLineNumber) throws LDIFException {
    Entry entry = original;
    logger.info("Processing dn {}, line number {}", entry.getDN(), firstLineNumber);

    entry = translateDN.translate(entry, firstLineNumber);

    // Test, remove cn attribute from entry
    if (entry.getAttribute("cn") != null) {
      entry.removeAttribute("cn");
    }

    // Create group modify from memberOf attribute
    if (entry.getAttribute("memberOf") != null) {
      createGroupModify(entry.getDN(), entry.getAttribute("memberOf"));
      entry.removeAttribute("memberOf");
    }

    String pwd = '"' + getStaticPassword() + '"';
    byte[] unicodePwd = null;
    try {
      unicodePwd = pwd.getBytes("UTF-16LE");
    } catch (UnsupportedEncodingException e) {
      throw new AssertionError("Should not occur", e);
    }

    entry.setAttribute("unicodePwd", unicodePwd);

    return entry;
  }
Esempio n. 3
0
  /**
   * Gets the most appropriate monitor class from the provided entry.
   *
   * @param entry The entry from which to extract the monitor class.
   * @return The most appropriate monitor class from the provided entry, or the generic monitor
   *     object class if no appropriate subclass could be identified.
   */
  private static String getMonitorClass(final Entry entry) {
    String monitorOC = null;
    final String[] ocNames = entry.getObjectClassValues();
    for (final String oc : ocNames) {
      if (oc.equalsIgnoreCase("top")
          || oc.equalsIgnoreCase("extensibleObject")
          || oc.equalsIgnoreCase(GENERIC_MONITOR_OC)) {
        // This isn't the class we're looking for.
        continue;
      } else if (oc.equalsIgnoreCase(NumericGaugeMonitorEntry.NUMERIC_GAUGE_MONITOR_OC)
          || oc.equalsIgnoreCase(IndicatorGaugeMonitorEntry.INDICATOR_GAUGE_MONITOR_OC)) {
        // These classes are subclasses of the base gauge monitor class.
        // We'll allow them even if the monitor class is already set.
        monitorOC = oc;
      } else if (oc.equalsIgnoreCase(GaugeMonitorEntry.GAUGE_MONITOR_OC)) {
        // This is a superclass for the numeric and indicator gauge classes.
        // We'll use it only if the monitor class isn't set, but we won't
        // complain if the monitor class is already set.
        if (monitorOC == null) {
          monitorOC = oc;
        }
      } else {
        if (monitorOC != null) {
          if (debugEnabled(DebugType.MONITOR)) {
            debugMonitor(
                entry, "Multiple monitor subclasses detected:  " + monitorOC + " and " + oc);
          }
        }

        monitorOC = oc;
      }
    }

    if (monitorOC == null) {
      if (entry.hasObjectClass(GENERIC_MONITOR_OC)) {
        debugMonitor(entry, "No appropriate monitor subclass");
      } else {
        debugMonitor(entry, "Missing the generic monitor class");
      }

      return GENERIC_MONITOR_OC;
    } else {
      return monitorOC;
    }
  }
  /** {@inheritDoc} */
  @Override
  public SCIMAttribute toSCIMAttribute(
      final Entry entry,
      final LDAPRequestInterface ldapInterface,
      final LDAPSearchResolver searchResolver)
      throws SCIMException {
    if (entry.hasAttribute(ATTR_MANAGER)) {
      final String dn = entry.getAttributeValue(ATTR_MANAGER);
      final String resourceID = searchResolver.getIdFromDn(ldapInterface, dn);

      final List<SCIMAttribute> attributes = new ArrayList<SCIMAttribute>(1);
      attributes.add(
          SCIMAttribute.create(
              descriptor.getSubAttribute("managerId"),
              SCIMAttributeValue.createStringValue(resourceID)));

      return SCIMAttribute.create(descriptor, SCIMAttributeValue.createComplexValue(attributes));
    }

    return null;
  }
  @Override // ZMutableEntry
  public void mapToAttrs(Map<String, Object> mapAttrs) {
    AttributeManager attrMgr = AttributeManager.getInst();

    for (Map.Entry<String, Object> me : mapAttrs.entrySet()) {

      String attrName = me.getKey();
      Object v = me.getValue();

      boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
      boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);

      if (v instanceof String) {
        ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String) v);
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
        entry.addAttribute(a);
      } else if (v instanceof String[]) {
        String[] sa = (String[]) v;
        ASN1OctetString[] values = new ASN1OctetString[sa.length];
        for (int i = 0; i < sa.length; i++) {
          values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
        }
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
        entry.addAttribute(a);
      } else if (v instanceof Collection) {
        Collection c = (Collection) v;
        ASN1OctetString[] values = new ASN1OctetString[c.size()];
        int i = 0;
        for (Object o : c) {
          values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
          i++;
        }
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
        entry.addAttribute(a);
      }
    }
  }
 @Override // ZMutableEntry
 public boolean hasAttribute(String attrName) {
   return entry.hasAttribute(attrName);
 }
 @Override // ZMutableEntry
 public String getAttrString(String attrName) throws LdapException {
   return entry.getAttributeValue(attrName);
 }
 @Override // ZMutableEntry
 public void addAttr(String attrName, String value) {
   entry.addAttribute(attrName, value);
 }
 @Override // ZMutableEntry
 public void addAttr(String attrName, Set<String> values) {
   for (String value : values) {
     entry.addAttribute(attrName, value);
   }
 }
 @Override // ZEntry
 public String getDN() {
   return entry.getDN();
 }
 @Override
 public void debug(ZLdapElementDebugListener debugListener) {
   print(debugListener, entry.toString());
 }
 @Override
 public void setDN(String dn) {
   entry.setDN(dn);
 }