use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.
the class PasswordManagerTest method testMultipleMasterPasswords.
@Test
public void testMultipleMasterPasswords() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
String masterPassword1 = UUID.randomUUID().toString();
String masterPassword2 = UUID.randomUUID().toString();
String masterPassword3 = UUID.randomUUID().toString();
File masterPasswordFile = File.createTempFile("masterPassword", null);
Files.write(masterPassword, masterPasswordFile, Charset.defaultCharset());
Files.write(masterPassword1, new File(masterPasswordFile.toString() + ".1"), Charset.defaultCharset());
Files.write(masterPassword2, new File(masterPasswordFile.toString() + ".2"), Charset.defaultCharset());
Files.write(masterPassword3, new File(masterPasswordFile.toString() + ".3"), Charset.defaultCharset());
State state = new State();
BasicTextEncryptor encryptor = new BasicTextEncryptor();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPasswordFile.toString());
state.setProp(ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS, 3);
PasswordManager passwordManager = PasswordManager.getInstance(state);
// Test current master password
encryptor.setPassword(masterPassword);
String encrypted = "ENC(" + encryptor.encrypt(password) + ")";
String decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test last master password using same passwordManager
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword1);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test second last master password using same passwordManager
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword2);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test third last master password using same passwordManager
// This one is not accepted because ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS = 3
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword3);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
try {
passwordManager.readPassword(encrypted);
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().startsWith("Failed to decrypt password"));
return;
}
Assert.fail("Password Manager decrypted too old password.");
}
use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.
the class PasswordManagerTest method testMasterPasswordNotExist.
@Test
public void testMasterPasswordNotExist() {
String password = "ENC(" + UUID.randomUUID().toString() + ")";
State state = new State();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, UUID.randomUUID());
Assert.assertEquals(PasswordManager.getInstance(state).readPassword(password), password);
}
use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.
the class PasswordManagerTest method testStrongEncryptionAndDecryption.
@Test
public void testStrongEncryptionAndDecryption() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
File masterPwdFile = getMasterPwdFile(masterPassword);
State state = new State();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPwdFile.toString());
state.setProp(ConfigurationKeys.ENCRYPT_USE_STRONG_ENCRYPTOR, true);
try {
StrongTextEncryptor encryptor = new StrongTextEncryptor();
encryptor.setPassword(masterPassword);
String encrypted = encryptor.encrypt(password);
encrypted = "ENC(" + encrypted + ")";
String decrypted = PasswordManager.getInstance(state).readPassword(encrypted);
Assert.assertEquals(decrypted, password);
} catch (EncryptionOperationNotPossibleException e) {
// no strong encryption is supported
}
}
use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.
the class PasswordManagerTest method testReadNormalPassword.
@Test
public void testReadNormalPassword() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
File masterPwdFile = getMasterPwdFile(masterPassword);
State state = new State();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPwdFile.toString());
Assert.assertEquals(PasswordManager.getInstance(state).readPassword(password), password);
masterPwdFile.delete();
}
use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.
the class MRCompactor method modifyDatasetStateToRecompact.
public static void modifyDatasetStateToRecompact(Dataset dataset) {
// Modify the dataset for recompaction
LOG.info("{} changes to recompact mode", dataset.getDatasetName());
State recompactState = new State();
recompactState.setProp(MRCompactor.COMPACTION_RECOMPACT_FROM_DEST_PATHS, Boolean.TRUE);
recompactState.setProp(MRCompactor.COMPACTION_JOB_LATE_DATA_MOVEMENT_TASK, Boolean.FALSE);
dataset.modifyDatasetForRecompact(recompactState);
dataset.setState(VERIFIED);
}
Aggregations