use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class TaskLauncherTest method thirdPartyCredentials.
@Test
public void thirdPartyCredentials() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(credentials.get('password'))", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory());
CredData credData = new CredData("john", "pwd");
credData.addThirdPartyCredential("password", "r00t");
final KeyPairProducer keyPairProducer = new KeyPairProducer();
final TaskLauncher spy = spy(taskLauncher);
doReturn(keyPairProducer.getKeyPair()).when(spy).getKeyPair();
Credentials thirdPartyCredentials = Credentials.createCredentials(credData, spy.generatePublicKey());
executableContainer.setCredentials(thirdPartyCredentials);
TaskResult taskResult = runTaskLauncher(spy, executableContainer);
final String allLogs = taskResult.getOutput().getAllLogs(false);
assertThat(allLogs.contains(String.format("r00t%n")), is(true));
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class ForkedTaskVariablesManagerTest method testScriptCredentialsAreReplaced.
@Test
public void testScriptCredentialsAreReplaced() throws InvalidScriptException {
ForkedTaskVariablesManager forkedTaskVariablesManager = new ForkedTaskVariablesManager();
// Add $credential_[something] variable to new python script
Serializable[] parameters = new Serializable[] { "$" + ForkedTaskVariablesManager.CREDENTIALS_KEY_PREFIX + testVariable1Key };
Script script = new SimpleScript("print 'hello'", "python", parameters);
// Create credentials
Map<String, String> credentials = new HashMap<>();
credentials.put(testVariable1Key, testVariable1Value);
// Replace the credentials inside the script parameters
forkedTaskVariablesManager.replaceScriptParameters(script, credentials, new VariablesMap(), System.out);
assertThat((String) parameters[0], is(testVariable1Value));
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method createCredentials.
private Decrypter createCredentials(String username) throws NoSuchAlgorithmException, KeyException {
CredData credData = new CredData(username, "pwd");
KeyPairGenerator keyGen;
keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(512, new SecureRandom());
KeyPair keyPair = keyGen.generateKeyPair();
Decrypter decrypter = new Decrypter(keyPair.getPrivate());
Credentials credentials = Credentials.createCredentials(credData, keyPair.getPublic());
decrypter.setCredentials(credentials);
return decrypter;
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method createCredentials.
private Decrypter createCredentials(String username) throws NoSuchAlgorithmException, KeyException {
CredData credData = new CredData(username, "pwd");
credData.addThirdPartyCredential("PASSWORD", "p4ssw0rd");
KeyPairGenerator keyGen;
keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(512, new SecureRandom());
KeyPair keyPair = keyGen.generateKeyPair();
Decrypter decrypter = new Decrypter(keyPair.getPrivate());
Credentials credentials = Credentials.createCredentials(credData, keyPair.getPublic());
decrypter.setCredentials(credentials);
return decrypter;
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class CommandFactory method getCommandList.
/**
* Returns an ordered {@link Command} list for specified user arguments.
*
* @param cli the command-line arguments
* @return an ordered {@link Command} list.
*/
protected List<Command> getCommandList(CommandLine cli, Map<String, Command> map, ApplicationContext currentContext) {
LinkedList<Command> list = new LinkedList<>();
if (map.containsKey(opt(COMMON_HELP))) {
list.add(map.remove(opt(COMMON_HELP)));
return list;
}
if (map.containsKey(opt(RM_HELP))) {
list.add(map.remove(opt(RM_HELP)));
return list;
}
if (map.containsKey(opt(SCHEDULER_HELP))) {
list.add(map.remove(opt(SCHEDULER_HELP)));
return list;
}
if (map.containsKey(opt(SILENT))) {
list.add(map.remove(opt(SILENT)));
}
if (map.containsKey(opt(DEBUG))) {
list.add(map.remove(opt(DEBUG)));
}
if (map.containsKey(opt(URL))) {
list.addFirst(map.remove(opt(URL)));
}
if (map.containsKey(opt(INSECURE))) {
list.add(map.remove(opt(INSECURE)));
} else if (map.containsKey(opt(CA_CERTS))) {
list.add(map.remove(opt(CA_CERTS)));
if (map.containsKey(opt(CA_CERTS_PASSWORD))) {
list.add(map.remove(opt(CA_CERTS_PASSWORD)));
}
}
if (map.containsKey(opt(SESSION_ID))) {
list.add(map.remove(opt(SESSION_ID)));
} else if (map.containsKey(opt(SESSION_ID_FILE))) {
list.add(map.remove(opt(SESSION_ID_FILE)));
}
if (map.containsKey(opt(PASSWORD))) {
list.add(map.remove(opt(PASSWORD)));
}
if (map.containsKey(opt(LOGIN))) {
list.add(map.remove(opt(LOGIN)));
} else if (map.containsKey(opt(CREDENTIALS))) {
list.add(map.remove(opt(CREDENTIALS)));
} else {
// auto login
String resourceType = currentContext.getResourceType();
String filename = resourceType + ".cc";
File credFile = new File(DFLT_SESSION_DIR, filename);
if (credFile.exists()) {
list.add(new LoginWithCredentialsCommand(credFile.getAbsolutePath(), true));
} else {
String schedulerHome = ClasspathUtils.findSchedulerHome();
File defaultCredentials = new File(schedulerHome, DEFAULT_CREDENTIALS_PATH);
if (defaultCredentials.exists()) {
list.add(new LoginWithCredentialsCommand(defaultCredentials.getAbsolutePath(), true));
}
}
}
if (map.containsKey(opt(INFRASTRUCTURE))) {
list.add(map.remove(opt(INFRASTRUCTURE)));
}
if (map.containsKey(opt(POLICY))) {
list.add(map.remove(opt(POLICY)));
}
if (map.isEmpty()) {
list.add(new ImodeCommand());
} else {
Command output = map.remove(opt(OUTPUT));
list.addAll(map.values());
if (output != null) {
list.add(output);
}
}
return list;
}
Aggregations