Search in sources :

Example 41 with CredData

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

the class SchedulerAuthenticationGUIHelper method login.

/**
 * This method will log a client to the scheduler by requesting his URL, username and password from a
 * graphical interface.
 *
 * @param schedulerURL The default URL of the scheduler to connect
 * @return The connection to the scheduler as a {@link Scheduler} if logging successful.
 * 			If the username is empty or if the user cancel the authentication, this method will return null.
 * @throws LoginException If a problem occurs while logging the user.
 * @throws SchedulerException If a problem occurs at scheduler level.
 */
public static Scheduler login(String schedulerURL) throws LoginException, SchedulerException {
    AuthResultContainer auth = connect(schedulerURL);
    if (auth == null) {
        return null;
    } else {
        SchedulerAuthenticationInterface schedAuth = auth.getAuth();
        Credentials cred = null;
        try {
            cred = Credentials.createCredentials(new CredData(CredData.parseLogin(auth.getUsername()), CredData.parseDomain(auth.getUsername()), auth.getPassword()), schedAuth.getPublicKey());
        } catch (LoginException e) {
            throw new LoginException("Could not retrieve public key from Scheduler " + schedulerURL + ", contact the administrator" + e);
        } catch (KeyException e) {
            throw new LoginException("Could not encrypt credentials " + e);
        }
        return schedAuth.login(cred);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) KeyException(java.security.KeyException)

Example 42 with CredData

use of org.ow2.proactive.authentication.crypto.CredData 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 43 with CredData

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

the class ForkedTaskExecutorRunAsMeTest method createCredentials.

private Decrypter createCredentials(String username, String password) throws NoSuchAlgorithmException, KeyException {
    CredData credData = new CredData(username, password);
    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 : CredData(org.ow2.proactive.authentication.crypto.CredData) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 44 with CredData

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

the class SchedulerStateRest method getCreateCredential.

/**
 * generates a credential file from user provided credentials
 *
 * @return the credential file generated by the scheduler
 * @throws LoginException
 * @throws SchedulerRestException
 */
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("createcredential")
@Produces("*/*")
public byte[] getCreateCredential(@MultipartForm LoginForm multipart) throws LoginException, SchedulerRestException {
    String username = multipart.getUsername();
    String password = multipart.getPassword();
    byte[] privKey = multipart.getSshKey();
    try {
        String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
        SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
        PublicKey pubKey = auth.getPublicKey();
        sessionStore.create(username);
        Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privKey), pubKey);
        return cred.getBase64();
    } catch (ConnectionException | KeyException e) {
        throw new SchedulerRestException(e);
    }
}
Also used : PublicKey(java.security.PublicKey) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) KeyException(java.security.KeyException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 45 with CredData

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

the class SharedSessionStoreTestUtils method createValidSession.

public static String createValidSession(SchedulerProxyUserInterface scheduler) throws LoginException, ActiveObjectCreationException, SchedulerException, NodeException {
    SchedulerRMProxyFactory schedulerFactory = mock(SchedulerRMProxyFactory.class);
    when(schedulerFactory.connectToScheduler(Matchers.<CredData>any())).thenReturn(scheduler);
    SharedSessionStore.getInstance().setSchedulerRMProxyFactory(schedulerFactory);
    // login
    Session session = SharedSessionStore.getInstance().createUnnamedSession();
    session.connectToScheduler(new CredData());
    return session.getSessionId();
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData)

Aggregations

CredData (org.ow2.proactive.authentication.crypto.CredData)53 Credentials (org.ow2.proactive.authentication.crypto.Credentials)41 PublicKey (java.security.PublicKey)15 Test (org.junit.Test)15 LoginException (javax.security.auth.login.LoginException)13 KeyException (java.security.KeyException)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)10 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)10 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)9 HashMap (java.util.HashMap)8 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)6 JMXServiceURL (javax.management.remote.JMXServiceURL)6 JMXConnector (javax.management.remote.JMXConnector)5 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 SchedulerProxyUserInterface (org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface)5 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)5 MBeanServerConnection (javax.management.MBeanServerConnection)4 ObjectName (javax.management.ObjectName)4 POST (javax.ws.rs.POST)4