Search in sources :

Example 1 with AlreadyConnectedException

use of org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException in project scheduling by ow2-proactive.

the class AuthenticationTest method loginAsAdmin.

private void loginAsAdmin(SchedulerAuthenticationInterface auth, PublicKey pubKey) throws KeyException, LoginException, AlreadyConnectedException, NotConnectedException, PermissionException {
    log("Test 1");
    log("Trying to authorized as an admin with correct user name and password");
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), pubKey);
    Scheduler admin = auth.login(cred);
    String userName = admin.getCurrentUser();
    Assert.assertEquals(TestUsers.DEMO.username, userName);
    UserData userData = admin.getCurrentUserData();
    Assert.assertNotNull(userData);
    Assert.assertNotNull(userData.getUserName());
    Assert.assertNotNull(userData.getGroups());
    Assert.assertTrue(userData.getGroups().contains("admin"));
    admin.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 2 with AlreadyConnectedException

use of org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException in project scheduling by ow2-proactive.

the class SchedulerAuthentication method login.

/**
 * {@inheritDoc}
 */
public Scheduler login(Credentials cred) throws LoginException, AlreadyConnectedException {
    Subject subject = authenticate(cred);
    UserNamePrincipal unPrincipal = subject.getPrincipals(UserNamePrincipal.class).iterator().next();
    String user = unPrincipal.getName();
    logger.info("user : " + user);
    // add this user to the scheduler front-end
    UserIdentificationImpl ident = new UserIdentificationImpl(user, subject);
    ident.setHostName(getSenderHostName());
    this.frontend.connect(PAActiveObject.getContext().getCurrentRequest().getSourceBodyID(), ident, cred);
    try {
        // return the stub on Scheduler interface to keep avoid using server class on client side
        return PAActiveObject.lookupActive(Scheduler.class, PAActiveObject.getUrl(frontend));
    } catch (ActiveObjectCreationException e) {
        rethrowSchedulerStubException(e);
    } catch (IOException e) {
        rethrowSchedulerStubException(e);
    }
    return null;
}
Also used : UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) IOException(java.io.IOException) Subject(javax.security.auth.Subject) UserIdentificationImpl(org.ow2.proactive.scheduler.job.UserIdentificationImpl) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException)

Example 3 with AlreadyConnectedException

use of org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException in project scheduling by ow2-proactive.

the class SchedulerFrontendTest method testConnection.

/**
 * Related to issue #1849.
 * <p>
 * https://github.com/ow2-proactive/scheduling/issues/1849
 */
@Test
public void testConnection() throws KeyException, AlreadyConnectedException {
    schedulerFrontend.connect(new UniqueID(), new UserIdentificationImpl("admin"), null);
    Mockito.verify(spacesSupport, times(1)).registerUserSpace("admin");
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) UserIdentificationImpl(org.ow2.proactive.scheduler.job.UserIdentificationImpl) Test(org.junit.Test)

Example 4 with AlreadyConnectedException

use of org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException 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)

Aggregations

UserData (org.ow2.proactive.authentication.UserData)2 CredData (org.ow2.proactive.authentication.crypto.CredData)2 Credentials (org.ow2.proactive.authentication.crypto.Credentials)2 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)2 UserIdentificationImpl (org.ow2.proactive.scheduler.job.UserIdentificationImpl)2 IOException (java.io.IOException)1 Subject (javax.security.auth.Subject)1 Test (org.junit.Test)1 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 UserNamePrincipal (org.ow2.proactive.authentication.principals.UserNamePrincipal)1