Esempio n. 1
0
 static String getLDAPPropertyName(AnnotatedConfigurableProperty property)
     throws ConfigurationException {
   LDAP ldapAnno = property.getAnnotation(LDAP.class);
   if (ldapAnno != null) {
     if (!ldapAnno.overriddenName().equals("")) {
       return ldapAnno.overriddenName();
     } else {
       return property.getAnnotatedName();
     }
   } else {
     return property.getAnnotatedName();
   }
 }
Esempio n. 2
0
  static String getDistinguishingField(AnnotatedConfigurableProperty property) {
    LDAP propLdapAnno = property.getAnnotation(LDAP.class);

    String distinguishingField;
    if (propLdapAnno != null) distinguishingField = propLdapAnno.distinguishingField();
    else distinguishingField = LDAP.DEFAULT_DISTINGUISHING_FIELD;

    if (distinguishingField.equals(LDAP.DEFAULT_DISTINGUISHING_FIELD)) {
      Annotation classLdapAnno = property.getRawClass().getAnnotation(LDAP.class);
      if (classLdapAnno != null) distinguishingField = ((LDAP) classLdapAnno).distinguishingField();
    }

    return distinguishingField;
  }
Esempio n. 3
0
  static boolean isNoContainerNode(AnnotatedConfigurableProperty property) {
    LDAP propLdapAnno = property.getAnnotation(LDAP.class);

    LDAP classLdapAnno = null;
    if (property.isConfObject()) classLdapAnno = propLdapAnno;
    else {
      AnnotatedConfigurableProperty pseudoProperty =
          property.getPseudoPropertyForConfigClassCollectionElement();
      if (pseudoProperty != null)
        classLdapAnno = (LDAP) pseudoProperty.getRawClass().getAnnotation(LDAP.class);
    }

    if (propLdapAnno == null || classLdapAnno == null) return false;

    return propLdapAnno.noContainerNode() || classLdapAnno.noContainerNode();
  }
Esempio n. 4
0
  /**
   * Resolve map/collection key field for a property
   *
   * @param property
   * @return
   */
  static String getDistinguishingFieldForCollectionElement(AnnotatedConfigurableProperty property) {

    // by default use what annotated on the property
    LDAP annotation = property.getAnnotation(LDAP.class);
    String elementDistinguishingField =
        annotation == null ? LDAP.DEFAULT_DISTINGUISHING_FIELD : annotation.distinguishingField();

    // if property is default, check the annotation on the element class if its a confclass
    if (elementDistinguishingField.equals(LDAP.DEFAULT_DISTINGUISHING_FIELD))
      if (property.isArrayOfConfObjects()
          || property.isCollectionOfConfObjects()
          || property.isMapOfConfObjects())
        elementDistinguishingField =
            ((LDAP)
                    property
                        .getPseudoPropertyForConfigClassCollectionElement()
                        .getRawClass()
                        .getAnnotation(LDAP.class))
                .distinguishingField();

    return elementDistinguishingField;
  }
Esempio n. 5
0
  protected static NamingEnumeration<SearchResult> searchForCollectionElements(
      LdapConfigurationStorage ldapConfigurationStorage,
      String dn,
      AnnotatedConfigurableProperty property)
      throws NamingException, ConfigurationException {
    NamingEnumeration<SearchResult> enumeration;
    AnnotatedConfigurableProperty elemProperty =
        property.getPseudoPropertyForConfigClassCollectionElement();

    // figure out the objectClass
    String childObjClass;
    if (elemProperty == null)
      childObjClass = property.getAnnotation(LDAP.class).mapEntryObjectClass();
    else childObjClass = extractObjectClasses(elemProperty.getRawClass()).get(0);

    try {
      enumeration = searchSubcontextWithClass(ldapConfigurationStorage, childObjClass, dn);
    } catch (IndexOutOfBoundsException e) {
      throw new ConfigurationException(
          "No object class defined for class " + elemProperty.getRawClass(), e);
    }
    return enumeration;
  }
Esempio n. 6
0
  static String refToLdapDN(
      String ref, LdapConfigurationStorage ldapStorage, BooleanContainer dnIsKillableWrapper) {

    boolean dnIsKillable = true;
    try {
      Iterator<Map<String, Object>> pathItemIter = ConfigNodeUtil.parseReference(ref).iterator();

      // first pathitem is always dicomconfigroot
      if (!pathItemIter.next().get("$name").equals("dicomConfigurationRoot"))
        throw new IllegalArgumentException("No dicom config root");

      String dn = "cn=DICOM Configuration," + ldapStorage.getBaseDN();

      Class currentClass = CommonDicomConfiguration.DicomConfigurationRootNode.class;
      while (pathItemIter.hasNext()) {

        List<AnnotatedConfigurableProperty> properties =
            ConfigIterators.getAllConfigurableFieldsAndSetterParameters(currentClass);

        Map<String, Object> pathItem = pathItemIter.next();

        Object name = pathItem.get("$name");

        for (AnnotatedConfigurableProperty property : properties) {
          if (name.equals(property.getAnnotatedName())) {

            // in any case
            if (!isNoContainerNode(property)) {
              dn = dnOf(dn, "cn", getLDAPPropertyName(property));
              dnIsKillable = true;
            } else dnIsKillable = false;

            // for collections/maps, analyze predicates
            if (property.isCollectionOfConfObjects()
                || property.isMapOfConfObjects()
                || property.isArrayOfConfObjects()) {

              // remove $name, because it is the collection name in this pathitem
              pathItem.remove("$name");

              // add rdn
              List<String> rdnItems = new ArrayList<String>();
              while (true) {
                // collect rdn pieces
                for (Map.Entry<String, Object> entry : pathItem.entrySet()) {

                  // skip wildcard - expect predicates
                  if (entry.getKey().equals("$name") && entry.getValue().equals("*")) {
                    if (pathItem.size() == 1)
                      throw new IllegalArgumentException(
                          "Wildcard without predicates is not allowed in references");
                    continue;
                  }

                  // add the rest of predicates to rdn
                  String df = null;
                  if (entry.getKey().equals("@name") || entry.getKey().equals("$name"))
                    df = getDistinguishingFieldForCollectionElement(property);
                  else df = entry.getKey();
                  rdnItems.add(df + "=" + escapeStringToLdap(entry.getValue()));
                }

                if (!rdnItems.isEmpty()) {
                  // if rdn found, proceed
                  dn = StringUtils.join(rdnItems, "+") + "," + dn;
                  dnIsKillable = true;
                  break;
                } else if (!pathItemIter.hasNext()) {
                  // rdn not found, path is over,.. nothing to look for
                  break;
                } else {
                  // get next path item and collect the rdn there
                  pathItem = pathItemIter.next();
                }
              }

              currentClass =
                  property.getPseudoPropertyForConfigClassCollectionElement().getRawClass();
            }

            // ConfObject
            if (property.isConfObject()) currentClass = property.getRawClass();
          }
        }

        // handle extensions
        if (currentClass.equals(Device.class)) {
          if (name.equals("deviceExtensions")
              || name.equals("aeExtensions")
              || name.equals("hl7AppExtensions")) {

            dnIsKillable = false;

            String extName;
            if (pathItem.containsKey("@name")) {
              extName = pathItem.get("@name").toString();
            } else {
              pathItem = pathItemIter.next();
              extName = pathItem.get("$name").toString();
            }

            currentClass = getExtensionClassBySimpleName(ldapStorage, extName);

            LDAP ldapanno = (LDAP) currentClass.getAnnotation(LDAP.class);
            if (ldapanno == null || !ldapanno.noContainerNode()) {
              dn = dnOf(dn, "cn", currentClass.getSimpleName());
              dnIsKillable = true;
            }
          }
        }
      }

      dnIsKillableWrapper.setKillable(dnIsKillable);
      return dn;
    } catch (Exception e) {
      throw new RuntimeException("Cannot transform reference " + ref + " to LDAP dn", e);
    }
  }
Esempio n. 7
0
 static ArrayList<String> extractObjectClasses(AnnotatedConfigurableProperty property) {
   return new ArrayList<String>(Arrays.asList(property.getAnnotation(LDAP.class).objectClasses()));
 }