Beispiel #1
0
  public static String connectionLdapDnToRef(String dn, LdapConfigurationStorage ldapStorage) {
    try {

      String baseDN = ldapStorage.getBaseDN();
      List<Rdn> rdns = LdapConfigUtils.getNonBaseRdns(dn, baseDN);

      if (!rdns.get(0).toString().equals("cn=DICOM Configuration")
          || !rdns.get(1).toString().equals("cn=Devices")
          || !rdns.get(2).getType().equals("dicomDeviceName"))
        throw new IllegalArgumentException("Invalid dn " + dn);

      String deviceName = (String) rdns.get(2).getValue();

      Attributes attributes = rdns.get(3).toAttributes();
      ArrayList<String> predicates = new ArrayList<String>();

      if (attributes.get("cn") != null)
        predicates.add("cn='" + escapeApos(attributes.get("cn").get().toString()) + "'");

      if (attributes.get("dicomHostname") != null)
        predicates.add("dicomHostname='" + attributes.get("dicomHostname").get().toString() + "'");

      if (attributes.get("dicomPort") != null)
        predicates.add("dicomPort='" + attributes.get("dicomPort").get().toString() + "'");

      return "/dicomConfigurationRoot/dicomDevicesRoot/*[dicomDeviceName='"
          + escapeStringFromLdap(deviceName)
          + "']/dicomConnection["
          + StringUtils.join(predicates, ",")
          + "]";

    } catch (javax.naming.NamingException e) {
      throw new IllegalArgumentException(e);
    }
  }
Beispiel #2
0
 static NamingEnumeration<SearchResult> searchSubcontextWithClass(
     LdapConfigurationStorage ldapConfigurationStorage, String childObjClass, String dn)
     throws NamingException {
   SearchControls ctls = new SearchControls();
   ctls.setSearchScope(1);
   ctls.setReturningObjFlag(false);
   return ldapConfigurationStorage
       .getLdapCtx()
       .search(dn, "(objectclass=" + childObjClass + ")", ctls);
 }
Beispiel #3
0
  static Class<?> getExtensionClassBySimpleName(
      LdapConfigurationStorage configurationStorage, String extensionSimpleName)
      throws ClassNotFoundException {

    List<Class<?>> extensionClasses = configurationStorage.getAllExtensionClasses();

    for (Class<?> aClass : extensionClasses) {
      if (aClass.getSimpleName().equals(extensionSimpleName)) return aClass;
    }

    throw new ClassNotFoundException();
  }
Beispiel #4
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);
    }
  }