Search in sources :

Example 21 with Credentials

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));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) CredData(org.ow2.proactive.authentication.crypto.CredData) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) KeyPairProducer(org.ow2.proactive.resourcemanager.utils.KeyPairProducer) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 22 with Credentials

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));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) Script(org.ow2.proactive.scripting.Script) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Serializable(java.io.Serializable) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) Test(org.junit.Test)

Example 23 with Credentials

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;
}
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 24 with Credentials

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;
}
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 25 with Credentials

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;
}
Also used : Command(org.ow2.proactive_grid_cloud_portal.cli.cmd.Command) LoginWithCredentialsCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand) ImodeCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.ImodeCommand) File(java.io.File) LinkedList(java.util.LinkedList) LoginWithCredentialsCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand) ImodeCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.ImodeCommand)

Aggregations

Credentials (org.ow2.proactive.authentication.crypto.Credentials)50 CredData (org.ow2.proactive.authentication.crypto.CredData)42 KeyException (java.security.KeyException)17 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)17 PublicKey (java.security.PublicKey)15 LoginException (javax.security.auth.login.LoginException)15 Test (org.junit.Test)14 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)13 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 File (java.io.File)9 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)6 JMXServiceURL (javax.management.remote.JMXServiceURL)6 JMXConnector (javax.management.remote.JMXConnector)5 Node (org.objectweb.proactive.core.node.Node)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 MBeanServerConnection (javax.management.MBeanServerConnection)4 ObjectName (javax.management.ObjectName)4 POST (javax.ws.rs.POST)4