Search in sources :

Example 61 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.

the class TestGetUsage method testGetMyAccountUsage.

@Test
public void testGetMyAccountUsage() throws Exception {
    Date beforeJobExecution = new Date();
    // put some data in the database
    Scheduler firstUser = schedulerHelper.getSchedulerInterface();
    JobId jobId = firstUser.submit(createJob());
    schedulerHelper.waitForEventJobFinished(jobId, 30000);
    Date afterJobExecution = new Date();
    // We try to retrieve usage on the job I just ran
    List<JobUsage> adminUsages = firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertFalse(adminUsages.isEmpty());
    // Do we properly check for user connection ?
    firstUser.disconnect();
    try {
        firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
        fail("Should throw a not connected exception because i just disconnected");
    } catch (NotConnectedException e) {
    // Ok that is expected
    }
    // another user
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
    Scheduler otherUser = auth.login(cred);
    // This user has not ran any job
    List<JobUsage> userUsages = otherUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertTrue(userUsages.isEmpty());
    otherUser.disconnect();
}
Also used : NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date) JobId(org.ow2.proactive.scheduler.common.job.JobId) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 62 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.

the class TestMultipleUsersMakingMassivGetResultRequest method testMultipleUsersMakingMassivGetResultRequest.

@Test
public void testMultipleUsersMakingMassivGetResultRequest() throws Throwable {
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    // create a job
    final TaskFlowJob job = new TaskFlowJob();
    for (int i = 0; i < taskPerJob; i++) {
        JavaTask task = new JavaTask();
        task.setName("jt" + i);
        task.setExecutableClassName(EmptyTask.class.getName());
        job.addTask(task);
    }
    // start threads
    for (int i = 0; i < ThreadNumber; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    // connect the scheduler
                    log(Thread.currentThread().getName() + " -> Connecting the scheduler");
                    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
                    Scheduler user = auth.login(cred);
                    log(Thread.currentThread().getName() + " -> Connected");
                    long start = System.currentTimeMillis();
                    int submitted = 1;
                    while (true) {
                        log(Thread.currentThread().getName() + " -> Submit (" + submitted + ")");
                        JobId id = user.submit(job);
                        JobResult jr = null;
                        while (jr == null) {
                            Thread.sleep(getResultDelay);
                            jr = user.getJobResult(id);
                        }
                        if (System.currentTimeMillis() - start > jobSubmissionDuration) {
                            log(Thread.currentThread().getName() + " -> Terminate");
                            nbFinished++;
                            break;
                        }
                        submitted++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    while (nbFinished < ThreadNumber) {
        Thread.sleep(100);
    }
    log("All threads terminated.");
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) EmptyTask(org.ow2.proactive.scheduler.examples.EmptyTask) Credentials(org.ow2.proactive.authentication.crypto.Credentials) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 63 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.

the class AuthenticationTest method loginAsUser.

private void loginAsUser(SchedulerAuthenticationInterface auth, PublicKey pubKey) throws KeyException, LoginException, AlreadyConnectedException, NotConnectedException, PermissionException {
    log("Test 2");
    log("Trying to authorized as a user with correct user name and password");
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), pubKey);
    Scheduler user = auth.login(cred);
    String userName = user.getCurrentUser();
    Assert.assertEquals(TestUsers.USER.username, userName);
    UserData userData = user.getCurrentUserData();
    Assert.assertNotNull(userData);
    Assert.assertNotNull(userData.getUserName());
    Assert.assertNotNull(userData.getGroups());
    Assert.assertTrue(userData.getGroups().contains("user"));
    user.disconnect();
    log("Passed: successful authentication");
}
Also used : UserData(org.ow2.proactive.authentication.UserData) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 64 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.

the class AuthenticationTest method loginAsAdminIncorrectPassword.

private void loginAsAdminIncorrectPassword(SchedulerAuthenticationInterface auth, PublicKey pubKey) {
    // negative
    log("Test 3");
    log("Trying to authorized as an admin with incorrect user name and password");
    try {
        Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, "b"), pubKey);
        auth.login(cred);
        fail("Error: successful authentication");
    } catch (Exception e) {
        log("Passed: expected error " + e.getMessage());
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Credentials(org.ow2.proactive.authentication.crypto.Credentials) LoginException(javax.security.auth.login.LoginException) KeyException(java.security.KeyException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException)

Example 65 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.

the class SchedulerStarter method addLocalNodes.

private static void addLocalNodes(RMAuthentication rmAuth, int numberLocalNodes, int nodeTimeoutValue) throws LoginException, KeyException, IOException {
    // creating default node source
    ResourceManager rman = rmAuth.login(Credentials.getCredentials(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
    // first im parameter is default rm url
    byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
    rman.createNodeSource(RMConstants.DEFAULT_LOCAL_NODES_NODE_SOURCE_NAME, LocalInfrastructure.class.getName(), new Object[] { creds, numberLocalNodes, nodeTimeoutValue, "" }, RestartDownNodesPolicy.class.getName(), new Object[] { "ALL", "ALL", "10000" }, NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_RECOVERABLE);
    credentials = creds;
}
Also used : RestartDownNodesPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.RestartDownNodesPolicy) LocalInfrastructure(org.ow2.proactive.resourcemanager.nodesource.infrastructure.LocalInfrastructure) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) File(java.io.File)

Aggregations

Credentials (org.ow2.proactive.authentication.crypto.Credentials)52 CredData (org.ow2.proactive.authentication.crypto.CredData)45 KeyException (java.security.KeyException)20 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)18 LoginException (javax.security.auth.login.LoginException)17 PublicKey (java.security.PublicKey)15 Test (org.junit.Test)15 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)14 HashMap (java.util.HashMap)13 IOException (java.io.IOException)12 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)12 File (java.io.File)9 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)6 JMXServiceURL (javax.management.remote.JMXServiceURL)6 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)6 Node (org.objectweb.proactive.core.node.Node)6 RMException (org.ow2.proactive.resourcemanager.exception.RMException)6 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)6 JMXConnector (javax.management.remote.JMXConnector)5