/**
   * Retrieve the value of the named environment property.
   *
   * @param key The name of the requested property.
   * @return The value of the requested property, or <code>null</code> if the property is undefined.
   */
  public String getProperty(String key) {
    SecurityManager sm = System.getSecurityManager();

    if (sm != null) {
      sm.checkPropertyAccess(key);
    }

    return (framework.getProperty(key));
  }
예제 #2
0
 /**
  * Return specific nodes resources file path for the project, based on the
  * framework.nodes.file.name property
  *
  * @return
  */
 public String getNodesResourceFilePath() {
   if (hasProperty(PROJECT_RESOURCES_FILE_PROPERTY)) {
     return new File(getProperty(PROJECT_RESOURCES_FILE_PROPERTY)).getAbsolutePath();
   }
   final Framework framework = projectResourceMgr.getFramework();
   final String s;
   if (framework.hasProperty(Framework.NODES_RESOURCES_FILE_PROP)) {
     return new File(getEtcDir(), framework.getProperty(Framework.NODES_RESOURCES_FILE_PROP))
         .getAbsolutePath();
   } else {
     return new File(getEtcDir(), NODES_XML).getAbsolutePath();
   }
 }
예제 #3
0
 /**
  * @return specific nodes resources file path for the project, based on the
  *     framework.nodes.file.name property
  */
 public static String getNodesResourceFilePath(IRundeckProject project, Framework framework) {
   if (project.hasProperty(ProjectNodeSupport.PROJECT_RESOURCES_FILE_PROPERTY)) {
     return new File(project.getProperty(ProjectNodeSupport.PROJECT_RESOURCES_FILE_PROPERTY))
         .getAbsolutePath();
   }
   if (null != framework) {
     File etcDir = new File(framework.getFrameworkProjectsBaseDir(), project.getName() + "/etc/");
     if (framework.hasProperty(Framework.NODES_RESOURCES_FILE_PROP)) {
       return new File(etcDir, framework.getProperty(Framework.NODES_RESOURCES_FILE_PROP))
           .getAbsolutePath();
     } else {
       return new File(etcDir, ProjectNodeSupport.NODES_XML).getAbsolutePath();
     }
   } else {
     return null;
   }
 }
예제 #4
0
  /**
   * Return true in these cases: 1. project.properties allows URL and framework.properties allows
   * URL. 2. project.properties allows URL and no regexes are set in framework.properties 3.
   * project.properties no regexes are set, and framework.properites allows URL.
   */
  boolean isAllowedProviderURL(final String providerURL) {

    // whitelist the configured providerURL
    if (hasProperty(PROJECT_RESOURCES_URL_PROPERTY)
        && getProperty(PROJECT_RESOURCES_URL_PROPERTY).equals(providerURL)) {
      return true;
    }
    // check regex properties for project props
    int i = 0;
    boolean projpass = false;
    boolean setproj = false;
    while (hasProperty(PROJECT_RESOURCES_ALLOWED_URL_PREFIX + i)) {
      setproj = true;
      final String regex = getProperty(PROJECT_RESOURCES_ALLOWED_URL_PREFIX + i);
      final Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
      final Matcher matcher = pat.matcher(providerURL);
      if (matcher.matches()) {
        logger.debug(
            "ProviderURL allowed by project property \"project.resources.allowedURL."
                + i
                + "\": "
                + regex);
        projpass = true;
        break;
      }
      i++;
    }
    if (!projpass && setproj) {
      // was checked but failed match
      return false;
    }
    assert projpass ^ !setproj;
    // check framework props
    i = 0;

    final Framework framework = getFrameworkProjectMgr().getFramework();
    final boolean setframework = framework.hasProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i);
    if (!setframework && projpass) {
      // unset in framework.props, allowed by project.props
      return true;
    }
    if (!setframework && !setproj) {
      // unset in both
      return false;
    }
    while (framework.hasProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i)) {
      final String regex = framework.getProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i);
      final Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
      final Matcher matcher = pat.matcher(providerURL);
      if (matcher.matches()) {
        logger.debug(
            "ProviderURL allowed by framework property \"framework.resources.allowedURL."
                + i
                + "\": "
                + regex);
        // allowed by framework.props, and unset or allowed by project.props,
        return true;
      }
      i++;
    }
    if (projpass) {
      logger.warn(
          "providerURL was allowed by project.properties, but is not allowed by framework.properties: "
              + providerURL);
    }
    return false;
  }