Search in sources :

Example 1 with EnvironmentStringPBEConfig

use of org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig in project karaf by apache.

the class EncryptableConfigAdminPropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    // Configure Jasypt
    enc = new StandardPBEStringEncryptor();
    env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    System.setProperty("org.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt2.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test2.jar", bundle().add("OSGI-INF/blueprint/configadmin-test.xml", getClass().getResource("configadmin-test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "configtest").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Example 2 with EnvironmentStringPBEConfig

use of org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig in project tesb-rt-se by Talend.

the class TextEncryptor method execute.

@Override
public Object execute() throws Exception {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
    env.setProvider(new BouncyCastleProvider());
    env.setProviderName(PROVIDER_NAME);
    env.setAlgorithm(ALGORITHM);
    if (encryptionPassword != null) {
        env.setPassword(encryptionPassword);
        System.out.println("Specified password for decryption should be set to " + PASSWORD_ENV_NAME + " env variable");
    } else {
        if (System.getenv(PASSWORD_ENV_NAME) != null) {
            env.setPasswordEnvName(PASSWORD_ENV_NAME);
        } else {
            System.out.println(PASSWORD_ENV_NAME + " system variable is not specified. ");
            System.out.println("Second parameter should be used to specify password.");
            return null;
        }
    }
    enc.setConfig(env);
    System.out.println(PropertyValueEncryptionUtils.encrypt(textToEncrypt, enc));
    return null;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 3 with EnvironmentStringPBEConfig

use of org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig in project karaf by apache.

the class EncryptablePropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    String val = enc.encrypt("bar");
    System.setProperty("foo", val);
    System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test.jar", bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "test").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) HashMap(java.util.HashMap) Map(java.util.Map) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Example 4 with EnvironmentStringPBEConfig

use of org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig in project tesb-rt-se by Talend.

the class WSPasswordCallbackHandlerTest method getEncryptor.

private StandardPBEStringEncryptor getEncryptor() throws Exception {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
    env.setProvider(new BouncyCastleProvider());
    env.setProviderName(PROVIDER_NAME);
    env.setAlgorithm(ALGORITHM);
    env.setPassword("pwd");
    enc.setConfig(env);
    return enc;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 5 with EnvironmentStringPBEConfig

use of org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig in project tesb-rt-se by Talend.

the class Configuration method setProperties.

/**
 * Back this <code>Configuration</code>  by the given properties from ConfigurationAdmin.
 *
 * @param properties the properties from ConfigurationAdmin, may be <code>null</code>.
 * @throws ConfigurationException thrown if the property values are not of type String
 */
public void setProperties(Dictionary<?, ?> properties) throws ConfigurationException {
    List<String> newArgumentList = new ArrayList<String>();
    if (properties != null) {
        for (Enumeration<?> keysEnum = properties.keys(); keysEnum.hasMoreElements(); ) {
            String key = (String) keysEnum.nextElement();
            Object val = properties.get(key);
            if (val instanceof String) {
                String value = (String) val;
                if (PropertyValueEncryptionUtils.isEncryptedValue(value)) {
                    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
                    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
                    env.setProvider(new BouncyCastleProvider());
                    env.setProviderName(PROVIDER_NAME);
                    env.setAlgorithm(ALGORITHM);
                    env.setPasswordEnvName(PASSWORD_ENV_NAME);
                    enc.setConfig(env);
                    val = PropertyValueEncryptionUtils.decrypt(value, enc);
                }
                String strval = convertArgument(key, (String) val);
                if (strval != null) {
                    newArgumentList.add(strval);
                }
            } else {
                throw new ConfigurationException(key, "Value is not of type String.");
            }
        }
    }
    argumentList = newArgumentList;
    configAvailable.countDown();
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) ConfigurationException(org.osgi.service.cm.ConfigurationException) ArrayList(java.util.ArrayList) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)5 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)5 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)3 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)2 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1