Search in sources :

Example 6 with Decrypter

use of org.ow2.proactive.scheduler.task.utils.Decrypter 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;
}
Also used : KeyPair(java.security.KeyPair) CredData(org.ow2.proactive.authentication.crypto.CredData) SecureRandom(java.security.SecureRandom) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) KeyPairGenerator(java.security.KeyPairGenerator) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 7 with Decrypter

use of org.ow2.proactive.scheduler.task.utils.Decrypter in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method scriptArgumentsReplacements.

@Test
public void scriptArgumentsReplacements() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    String printArgs = "println(args[0] + args[1]);";
    initializer.setPreScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "$PA_JOB_ID" }));
    initializer.setPostScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "$PA_JOB_ID" }));
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    Decrypter decrypter = createCredentials("somebody_that_does_not_exists");
    TaskContext taskContext = new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "${PA_JOB_ID}" }))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", "", decrypter);
    new InProcessTaskExecutor().execute(taskContext, taskOutput.outputStream, taskOutput.error);
    // pre, task and post
    assertEquals(String.format("p4ssw0rd1000%np4ssw0rd1000%np4ssw0rd1000%n"), taskOutput.output());
}
Also used : Serializable(java.io.Serializable) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 8 with Decrypter

use of org.ow2.proactive.scheduler.task.utils.Decrypter 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;
}
Also used : KeyPair(java.security.KeyPair) CredData(org.ow2.proactive.authentication.crypto.CredData) SecureRandom(java.security.SecureRandom) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) KeyPairGenerator(java.security.KeyPairGenerator) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 9 with Decrypter

use of org.ow2.proactive.scheduler.task.utils.Decrypter in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method createCredentials.

private Decrypter createCredentials(String username, String password) throws NoSuchAlgorithmException, KeyException {
    Map<String, String> thirdPartyCreds = new HashMap<>();
    thirdPartyCreds.put(thirdPartyCred1Key, thirdPartyCred1Value);
    CredData credData = new CredData(username, password, thirdPartyCreds);
    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;
}
Also used : KeyPair(java.security.KeyPair) HashMap(java.util.HashMap) CredData(org.ow2.proactive.authentication.crypto.CredData) SecureRandom(java.security.SecureRandom) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) KeyPairGenerator(java.security.KeyPairGenerator) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 10 with Decrypter

use of org.ow2.proactive.scheduler.task.utils.Decrypter in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsSchedulerNodeClientVariable.

@Test
public void testAddBindingsToScriptHandlerContainsSchedulerNodeClientVariable() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException, KeyException, NoSuchAlgorithmException {
    ScriptExecutableContainer scriptContainer = createScriptContainer();
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
    taskLauncherInitializer.setSchedulerRestUrl("http://localhost:8080/rest");
    Decrypter decrypter = createCredentials(testUser, testPass);
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null, decrypter);
    // variable should belong to the expected class
    validateThatScriptHandlerBindingsInstanceOf(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, SchedulerNodeClient.class);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Aggregations

Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)12 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)7 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)7 Test (org.junit.Test)6 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)5 KeyPair (java.security.KeyPair)4 Credentials (org.ow2.proactive.authentication.crypto.Credentials)4 KeyPairGenerator (java.security.KeyPairGenerator)3 SecureRandom (java.security.SecureRandom)3 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)3 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)3 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)3 SimpleScript (org.ow2.proactive.scripting.SimpleScript)3 TaskScript (org.ow2.proactive.scripting.TaskScript)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)2