Search in sources :

Example 11 with BasicTextEncryptor

use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.

the class ConfigUtilsTest method testConfigResolveEncrypted.

@Test
public void testConfigResolveEncrypted() throws IOException {
    Map<String, String> vals = Maps.newHashMap();
    vals.put("test.key1", "test_val1");
    vals.put("test.key2", "test_val2");
    State state = new State();
    for (Map.Entry<String, String> entry : vals.entrySet()) {
        state.setProp(entry.getKey(), entry.getValue());
    }
    String key = UUID.randomUUID().toString();
    File keyFile = newKeyFile(key);
    state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, keyFile.getAbsolutePath());
    Map<String, String> encryptedVals = Maps.newHashMap();
    encryptedVals.put("my.nested.key1", "val1");
    encryptedVals.put("my.nested.key2", "val2");
    String encPrefix = "testenc";
    for (Map.Entry<String, String> entry : encryptedVals.entrySet()) {
        BasicTextEncryptor encryptor = new BasicTextEncryptor();
        encryptor.setPassword(key);
        String encrypted = "ENC(" + encryptor.encrypt(entry.getValue()) + ")";
        state.setProp(encPrefix + "." + entry.getKey(), encrypted);
    }
    Config config = ConfigUtils.resolveEncrypted(ConfigUtils.propertiesToConfig(state.getProperties()), Optional.of(encPrefix));
    Map<String, String> expected = ImmutableMap.<String, String>builder().putAll(vals).putAll(encryptedVals).build();
    for (Map.Entry<String, String> entry : expected.entrySet()) {
        String val = config.getString(entry.getKey());
        Assert.assertEquals(val, entry.getValue());
    }
    keyFile.delete();
}
Also used : State(org.apache.gobblin.configuration.State) Config(com.typesafe.config.Config) BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) File(java.io.File) Test(org.testng.annotations.Test)

Example 12 with BasicTextEncryptor

use of org.jasypt.util.text.BasicTextEncryptor in project omegat by omegat-org.

the class CredentialsManager method clearMasterPassword.

/**
 * Clear the stored master password (if present) and the canary value.
 * Afterwards, any encrypted values will be considered to be not set
 * ({@link #isStored(String)} returns false; {@link #retrieve(String)}
 * returns {@link Optional#empty()}).
 */
public void clearMasterPassword() {
    clear(CREDENTIALS_MANAGER_CANARY);
    clear(CREDENTIALS_MASTER_PASSWORD);
    synchronized (this) {
        textEncryptor = new BasicTextEncryptor();
    }
}
Also used : BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor)

Example 13 with BasicTextEncryptor

use of org.jasypt.util.text.BasicTextEncryptor in project service-authorization by reportportal.

the class Encryptor method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    textEncryptor = new BasicTextEncryptor();
    textEncryptor.setPassword(password);
}
Also used : BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor)

Aggregations

BasicTextEncryptor (org.jasypt.util.text.BasicTextEncryptor)13 File (java.io.File)4 State (org.apache.gobblin.configuration.State)4 Test (org.testng.annotations.Test)4 StrongTextEncryptor (org.jasypt.util.text.StrongTextEncryptor)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Closer (com.google.common.io.Closer)1 LineReader (com.google.common.io.LineReader)1 Config (com.typesafe.config.Config)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Path (org.apache.hadoop.fs.Path)1 TextEncryptor (org.jasypt.util.text.TextEncryptor)1 Test (org.junit.Test)1