Example usage for org.apache.commons.configuration HierarchicalConfiguration getString

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getString.

Prototype

public String getString(String key, String defaultValue) 

Source Link

Usage

From source file:org.apache.james.smtpserver.netty.SMTPServer.java

@Override
public void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException {
    super.doConfigure(configuration);
    if (isEnabled()) {
        String authRequiredString = configuration.getString("authRequired", "false").trim().toLowerCase();
        if (authRequiredString.equals("true"))
            authRequired = AUTH_REQUIRED;
        else if (authRequiredString.equals("announce"))
            authRequired = AUTH_ANNOUNCE;
        else/*from www  . j  a va2 s .  c  om*/
            authRequired = AUTH_DISABLED;
        if (authRequired != AUTH_DISABLED) {
            getLogger().info("This SMTP server requires authentication.");
        } else {
            getLogger().info("This SMTP server does not require authentication.");
        }

        authorizedAddresses = configuration.getString("authorizedAddresses", null);
        if (authRequired == AUTH_DISABLED && authorizedAddresses == null) {
            /*
             * if SMTP AUTH is not required then we will use
             * authorizedAddresses to determine whether or not to relay
             * e-mail. Therefore if SMTP AUTH is not required, we will not
             * relay e-mail unless the sending IP address is authorized.
             * 
             * Since this is a change in behavior for James v2, create a
             * default authorizedAddresses network of 0.0.0.0/0, which
             * matches all possible addresses, thus preserving the current
             * behavior.
             * 
             * James v3 should require the <authorizedAddresses> element.
             */
            authorizedAddresses = "0.0.0.0/0.0.0.0";
        }

        if (authorizedNetworks != null) {
            getLogger().info("Authorized addresses: " + authorizedNetworks.toString());
        }

        // get the message size limit from the conf file and multiply
        // by 1024, to put it in bytes
        maxMessageSize = configuration.getLong("maxmessagesize", maxMessageSize) * 1024;
        if (maxMessageSize > 0) {
            getLogger().info("The maximum allowed message size is " + maxMessageSize + " bytes.");
        } else {
            getLogger().info("No maximum message size is enforced for this server.");
        }

        heloEhloEnforcement = configuration.getBoolean("heloEhloEnforcement", true);

        if (authRequiredString.equals("true"))
            authRequired = AUTH_REQUIRED;

        // get the smtpGreeting
        smtpGreeting = configuration.getString("smtpGreeting", null);

        addressBracketsEnforcement = configuration.getBoolean("addressBracketsEnforcement", true);

        verifyIdentity = configuration.getBoolean("verifyIdentity", true);

    }
}

From source file:org.apache.james.smtpserver.POP3BeforeSMTPHandler.java

public void configure(HierarchicalConfiguration config) throws ConfigurationException {
    try {//from   w w w .  j a v  a2s  .c  om
        setExpireTime(config.getString("expireTime", null));
    } catch (NumberFormatException e) {
        throw new ConfigurationException("Please configure a valid expireTime: " + e.getMessage());
    }
}

From source file:org.apache.james.user.hbase.HBaseUsersRepository.java

/**
 * @see org.apache.james.user.lib.AbstractUsersRepository#doConfigure(HierarchicalConfiguration)
 *//* w w  w .  j  a  va2s. com*/
@Override
public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
    algo = config.getString("algorithm", "MD5");
    super.doConfigure(config);
}

From source file:org.apache.james.user.jcr.JCRUsersRepository.java

public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
    this.workspace = config.getString("workspace", null);
    String username = config.getString("username", null);
    String password = config.getString("password", null);

    if (username != null && password != null) {
        this.creds = new SimpleCredentials(username, password.toCharArray());
    }//w  w  w .  j av a 2 s .c o  m
}

From source file:org.apache.james.user.jdbc.AbstractJdbcUsersRepository.java

/**
 * <p>//from   w  w w. j  a va 2 s .c  o m
 * Configures the UserRepository for JDBC access.
 * </p>
 * <p>
 * Requires a configuration element in the .conf.xml file of the form:
 * </p>
 * 
 * <pre>
 *   &lt;repository name=&quot;so even &quot;
 *       class=&quot;org.apache.james.userrepository.JamesUsersJdbcRepository&quot;&gt;
 *       &lt;!-- Name of the datasource to use --&gt;
 *       &lt;data-source&gt;MailDb&lt;/data-source&gt;
 *       &lt;!-- File to load the SQL definitions from --&gt;
 *       &lt;sqlFile&gt;dist/conf/sqlResources.xml&lt;/sqlFile&gt;
 *       &lt;!-- replacement parameters for the sql file --&gt;
 *       &lt;sqlParameters table=&quot;JamesUsers&quot;/&gt;
 *   &lt;/repository&gt;
 * </pre>
 * 
 * @see org.apache.james.user.lib.AbstractJamesUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
 */
protected void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException {
    StringBuffer logBuffer;
    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(64).append(this.getClass().getName()).append(".configure()");
        getLogger().debug(logBuffer.toString());
    }

    // Parse the DestinationURL for the name of the datasource,
    // the table to use, and the (optional) repository Key.
    String destUrl = configuration.getString("[@destinationURL]", null);
    // throw an exception if the attribute is missing
    if (destUrl == null)
        throw new ConfigurationException("destinationURL attribute is missing from Configuration");

    // normalise the destination, to simplify processing.
    if (!destUrl.endsWith("/")) {
        destUrl += "/";
    }
    // Split on "/", starting after "db://"
    List<String> urlParams = new ArrayList<String>();
    int start = 5;
    int end = destUrl.indexOf('/', start);
    while (end > -1) {
        urlParams.add(destUrl.substring(start, end));
        start = end + 1;
        end = destUrl.indexOf('/', start);
    }

    // Build SqlParameters and get datasource name from URL parameters
    m_sqlParameters = new HashMap<String, String>();
    switch (urlParams.size()) {
    case 3:
        m_sqlParameters.put("key", urlParams.get(2));
    case 2:
        m_sqlParameters.put("table", urlParams.get(1));
    case 1:
        urlParams.get(0);
        break;
    default:
        throw new ConfigurationException("Malformed destinationURL - "
                + "Must be of the format \"db://<data-source>[/<table>[/<key>]]\".");
    }

    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(128).append("Parsed URL: table = '").append(m_sqlParameters.get("table"))
                .append("', key = '").append(m_sqlParameters.get("key")).append("'");
        getLogger().debug(logBuffer.toString());
    }

    // Get the SQL file location
    m_sqlFileName = configuration.getString("sqlFile", null);

    // Get other sql parameters from the configuration object,
    // if any.
    Iterator<String> paramIt = configuration.getKeys("sqlParameters");
    while (paramIt.hasNext()) {
        String rawName = paramIt.next();
        String paramName = paramIt.next().substring("sqlParameters.[@".length(), rawName.length() - 1);
        String paramValue = configuration.getString(rawName);
        m_sqlParameters.put(paramName, paramValue);
    }
}

From source file:org.apache.james.user.jpa.JPAUsersRepository.java

/**
 * @see//from   w w  w.  j a va 2 s . c  o m
 * org.apache.james.user.lib.AbstractUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
 */
public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
    algo = config.getString("algorithm", "MD5");
    super.doConfigure(config);
}

From source file:org.apache.james.user.ldap.LdapRepositoryConfiguration.java

public static LdapRepositoryConfiguration from(HierarchicalConfiguration configuration)
        throws ConfigurationException {
    String ldapHost = configuration.getString("[@ldapHost]", "");
    String principal = configuration.getString("[@principal]", "");
    String credentials = configuration.getString("[@credentials]", "");
    String userBase = configuration.getString("[@userBase]");
    String userIdAttribute = configuration.getString("[@userIdAttribute]");
    String userObjectClass = configuration.getString("[@userObjectClass]");
    // Default is to use connection pooling
    boolean useConnectionPool = configuration.getBoolean("[@useConnectionPool]", USE_CONNECTION_POOL);
    int connectionTimeout = configuration.getInt("[@connectionTimeout]", NO_CONNECTION_TIMEOUT);
    int readTimeout = configuration.getInt("[@readTimeout]", NO_READ_TIME_OUT);
    // Default maximum retries is 1, which allows an alternate connection to
    // be found in a multi-homed environment
    int maxRetries = configuration.getInt("[@maxRetries]", 1);
    boolean supportsVirtualHosting = configuration.getBoolean(SUPPORTS_VIRTUAL_HOSTING,
            !ENABLE_VIRTUAL_HOSTING);/*from w w  w  . j a  v a 2s  . c o m*/
    // Default retry start interval is 0 second
    long retryStartInterval = configuration.getLong("[@retryStartInterval]", 0);
    // Default maximum retry interval is 60 seconds
    long retryMaxInterval = configuration.getLong("[@retryMaxInterval]", 60);
    int scale = configuration.getInt("[@retryIntervalScale]", 1000); // seconds

    HierarchicalConfiguration restrictionConfig = null;
    // Check if we have a restriction we can use
    // See JAMES-1204
    if (configuration.containsKey("restriction[@memberAttribute]")) {
        restrictionConfig = configuration.configurationAt("restriction");
    }
    ReadOnlyLDAPGroupRestriction restriction = new ReadOnlyLDAPGroupRestriction(restrictionConfig);

    //see if there is a filter argument
    String filter = configuration.getString("[@filter]");

    Optional<String> administratorId = Optional.ofNullable(configuration.getString("[@administratorId]"));

    return new LdapRepositoryConfiguration(ldapHost, principal, credentials, userBase, userIdAttribute,
            userObjectClass, useConnectionPool, connectionTimeout, readTimeout, maxRetries,
            supportsVirtualHosting, retryStartInterval, retryMaxInterval, scale, restriction, filter,
            administratorId);
}

From source file:org.apache.james.user.ldap.ReadOnlyUsersLDAPRepository.java

/**
 * Extracts the parameters required by the repository instance from the
 * James server configuration data. The fields extracted include
 * {@link #ldapHost}, {@link #userIdAttribute}, {@link #userBase},
 * {@link #principal}, {@link #credentials} and {@link #restriction}.
 *
 * @param configuration//from   w  ww .ja v a  2  s  .  co  m
 *            An encapsulation of the James server configuration data.
 */
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {
    ldapHost = configuration.getString("[@ldapHost]", "");
    principal = configuration.getString("[@principal]", "");
    credentials = configuration.getString("[@credentials]", "");
    userBase = configuration.getString("[@userBase]");
    userIdAttribute = configuration.getString("[@userIdAttribute]");
    userObjectClass = configuration.getString("[@userObjectClass]");
    // Default is to use connection pooling
    useConnectionPool = configuration.getBoolean("[@useConnectionPool]", true);
    connectionTimeout = configuration.getInt("[@connectionTimeout]", -1);
    readTimeout = configuration.getInt("[@readTimeout]", -1);
    // Default maximum retries is 1, which allows an alternate connection to
    // be found in a multi-homed environment
    maxRetries = configuration.getInt("[@maxRetries]", 1);
    // Default retry start interval is 0 second
    long retryStartInterval = configuration.getLong("[@retryStartInterval]", 0);
    // Default maximum retry interval is 60 seconds
    long retryMaxInterval = configuration.getLong("[@retryMaxInterval]", 60);
    int scale = configuration.getInt("[@retryIntervalScale]", 1000); // seconds
    schedule = new DoublingRetrySchedule(retryStartInterval, retryMaxInterval, scale);

    HierarchicalConfiguration restrictionConfig = null;
    // Check if we have a restriction we can use
    // See JAMES-1204
    if (configuration.containsKey("restriction[@memberAttribute]")) {
        restrictionConfig = configuration.configurationAt("restriction");
    }
    restriction = new ReadOnlyLDAPGroupRestriction(restrictionConfig);

    //see if there is a filter argument
    filter = configuration.getString("[@filter]");

}

From source file:org.apache.james.user.memory.MemoryUsersRepository.java

@Override
public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
    algo = config.getString("algorithm", "MD5");
    super.doConfigure(config);
}

From source file:org.onosproject.drivers.odtn.openconfig.TerminalDeviceDiscovery.java

/**
 * Checks if a given component has a subcomponent of a given type.
 *
 * @param component subtree to parse looking for subcomponents.
 * @param components the full components tree, to cross-ref in
 *  case we need to check (sub)components' types.
 *
 * @return true or false// w w  w .j  av  a  2s  . c o  m
 */
private boolean hasSubComponentOfType(HierarchicalConfiguration component, HierarchicalConfiguration components,
        String type) {
    long count = component.configurationsAt("subcomponents/subcomponent").stream().filter(subcomponent -> {
        String scName = subcomponent.getString("name");
        StringBuilder sb = new StringBuilder("component[name='");
        sb.append(scName);
        sb.append("']/state/type");
        String scType = components.getString(sb.toString(), "unknown");
        return scType.equals(type);
    }).count();
    return (count > 0);
}