Example usage for org.apache.commons.configuration Configuration getBoolean

List of usage examples for org.apache.commons.configuration Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getBoolean.

Prototype

Boolean getBoolean(String key, Boolean defaultValue);

Source Link

Document

Get a Boolean associated with the given configuration key.

Usage

From source file:org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java

/**
 * Configure the helloName for the given Configuration
 * //from w  w w  .ja  va  2 s  .  co  m
 * @param handlerConfiguration
 * @throws ConfigurationException
 */
protected void configureHelloName(Configuration handlerConfiguration) throws ConfigurationException {
    StringBuilder infoBuffer;
    String hostName;
    try {
        hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ue) {
        hostName = "localhost";
    }

    infoBuffer = new StringBuilder(64).append(getServiceType()).append(" is running on: ").append(hostName);
    getLogger().info(infoBuffer.toString());

    boolean autodetect = handlerConfiguration.getBoolean(HELLO_NAME + ".[@autodetect]", true);
    if (autodetect) {
        helloName = hostName;
    } else {
        helloName = handlerConfiguration.getString(HELLO_NAME);
        if (helloName == null || helloName.trim().length() < 1) {
            throw new ConfigurationException("Please configure the helloName or use autodetect");
        }
    }

    infoBuffer = new StringBuilder(64).append(getServiceType()).append(" handler hello name is: ")
            .append(helloName);
    getLogger().info(infoBuffer.toString());
}

From source file:org.apache.james.smtpserver.fastfail.SPFHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    setBlockSoftFail(config.getBoolean("blockSoftFail", false));
    setBlockPermError(config.getBoolean("blockPermError", true));
}

From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    String[] servers = config.getStringArray("uriRblServers.server");
    Collection<String> serverCollection = new ArrayList<String>();
    for (String rblServerName : servers) {
        serverCollection.add(rblServerName);
        if (serviceLog.isInfoEnabled()) {
            serviceLog.info("Adding uriRBL server: " + rblServerName);
        }//from w w w .j ava 2  s .com
    }
    if (serverCollection != null && serverCollection.size() > 0) {
        setUriRblServer(serverCollection);
    } else {
        throw new ConfigurationException("Please provide at least one server");
    }

    setGetDetail(config.getBoolean("getDetail", false));
}

From source file:org.apache.james.smtpserver.fastfail.ValidRcptHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    setRecipientRewriteTableSupport(config.getBoolean("enableRecipientRewriteTable", true));

}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_InMemory() {
    System.out.println("testDecryptFromConfigXML_InMemory");
    try {/*w  w  w  .  ja v  a2  s.  co  m*/
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new AES128Cryptor();
        String encrypt = auth.encrypt("test");
        Assert.assertNotNull(encrypt);
        Assert.assertNotSame(encrypt, "test");

        //add to the config
        config.addProperty("testDecryptFromConfigXML", encrypt);
        config.addProperty("testDecryptFromConfigXML" + Property.ENCRYPTED_ATTRIBUTE, "true");

        //retrieve it
        String pwd = config.getString("testDecryptFromConfigXML");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("testDecryptFromConfigXML" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "test");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_Disk_Default() {
    System.out.println("testDecryptFromConfigXML_Disk_Default");
    try {//w ww .  j  av  a2  s  .  c om
        File f = new File(".");
        System.out.println("Current working dir is " + f.getAbsolutePath());
        System.setProperty(AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY,
                f.getAbsolutePath() + "/src/test/resources/juddiv3-enc-default.xml");
        AppConfig.reloadConfig();
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new DefaultCryptor();

        //retrieve it
        String pwd = config.getString("juddi.mail.smtp.password");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("juddi.mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "password");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_Disk_3DES() {
    System.out.println("testDecryptFromConfigXML_Disk_3DES");
    try {// w  w  w . ja v  a 2 s  .  c om
        File f = new File(".");
        System.out.println("Current working dir is " + f.getAbsolutePath());
        System.setProperty(AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY,
                f.getAbsolutePath() + "/src/test/resources/juddiv3-enc-3des.xml");
        AppConfig.reloadConfig();
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new TripleDESCrytor();

        //retrieve it
        String pwd = config.getString("juddi.mail.smtp.password");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("juddi.mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "password");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_Disk_AES128() {
    System.out.println("testDecryptFromConfigXML_Disk_AES128");
    try {//from ww  w  .java 2  s  . c om
        File f = new File(".");
        System.out.println("Current working dir is " + f.getAbsolutePath());

        System.setProperty(AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY,
                f.getAbsolutePath() + "/src/test/resources/juddiv3-enc-aes128.xml");
        AppConfig.reloadConfig();
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new AES128Cryptor();

        //retrieve it
        String pwd = config.getString("juddi.mail.smtp.password");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("juddi.mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "password");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_Disk_AES256() {
    System.out.println("testDecryptFromConfigXML_Disk_AES256");
    try {/*from w  w w  .  j  av a2s .c o  m*/
        File f = new File(".");
        System.out.println("Current working dir is " + f.getAbsolutePath());
        System.setProperty(AppConfig.JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY,
                f.getAbsolutePath() + "/src/test/resources/juddiv3-enc-aes256.xml");
        AppConfig.reloadConfig();
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new AES256Cryptor();

        //retrieve it
        String pwd = config.getString("juddi.mail.smtp.password");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("juddi.mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "password");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (InvalidKeyException e) {
        logger.error(
                "Hey, you're probably using the Oracle JRE without the Unlimited Strength Java Crypto Extensions installed. AES256 won't work until you download and install it",
                e);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}

From source file:org.apache.juddi.config.AppConfig.java

private Properties getPersistentConfiguration(Configuration config) throws ConfigurationException {
    Properties result = new Properties();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//  ww w  . java 2s  . c  o  m
        boolean seedAlways = config.getBoolean("juddi.seed.always", false);
        if (seedAlways || !Install.alreadyInstalled(config)) {
            if (seedAlways) {
                log.info("Installing UDDI seed data, loading...");
            } else {
                log.info("The 'root' publisher was not found, loading...");
            }
            try {
                Install.install(config);
            } catch (Exception e) {
                throw new ConfigurationException(e);
            } catch (Throwable t) {
                throw new ConfigurationException(t);
            }
        }

        tx.begin();

        String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
        UddiEntityPublisher rootPublisher = new UddiEntityPublisher(rootPublisherStr);
        rootPublisher.populateKeyGeneratorKeys(em);
        List<String> rootKeyGenList = rootPublisher.getKeyGeneratorKeys();
        if (rootKeyGenList == null || rootKeyGenList.size() == 0)
            throw new ConfigurationException(
                    "The 'root' publisher key generator was not found.  Please make sure that the application is properly installed.");

        String rootKeyGen = rootKeyGenList.iterator().next();
        //rootKeyGen = rootKeyGen.substring((KeyGenerator.UDDI_SCHEME + KeyGenerator.PARTITION_SEPARATOR).length());
        rootKeyGen = rootKeyGen.substring(0, rootKeyGen.length()
                - (KeyGenerator.PARTITION_SEPARATOR + KeyGenerator.KEYGENERATOR_SUFFIX).length());
        log.debug("root partition:  " + rootKeyGen);

        result.setProperty(Property.JUDDI_ROOT_PARTITION, rootKeyGen);

        // The node Id is defined as the business key of the business entity categorized as a node.  This entity is saved as part of the install.
        // Only one business entity should be categorized as a node.
        String nodeId = "";
        CategoryBag categoryBag = new CategoryBag();
        KeyedReference keyedRef = new KeyedReference();
        keyedRef.setTModelKey(Constants.NODE_CATEGORY_TMODEL);
        keyedRef.setKeyValue(Constants.NODE_KEYVALUE);
        categoryBag.getKeyedReference().add(keyedRef);
        List<?> keyList = FindBusinessByCategoryQuery.select(em, new FindQualifiers(), categoryBag, null);
        if (keyList != null && keyList.size() > 1)
            throw new ConfigurationException("Only one business entity can be categorized as the node.");

        if (keyList != null && keyList.size() > 0) {
            nodeId = (String) keyList.get(0);
        } else
            throw new ConfigurationException(
                    "A node business entity was not found.  Please make sure that the application is properly installed.");
        result.setProperty(Property.JUDDI_NODE_ID, nodeId);

        //result.setProperty(Property.JUDDI_NODE_ROOT_BUSINESS, nodeId);

        tx.commit();
        return result;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}