Search in sources :

Example 81 with Credentials

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

the class RMStateCaching method init_.

private static void init_() {
    while (rm == null) {
        String url = PortalConfiguration.RM_URL.getValueAsString();
        String cred_path = PortalConfiguration.RM_CACHE_CREDENTIALS.getValueAsStringOrNull();
        try {
            if (rm == null) {
                rm = PAActiveObject.newActive(RMProxyUserInterface.class, new Object[] {});
                if (cred_path != null && !(new File(cred_path)).exists()) {
                    logger.error("Credentials path set in " + PortalConfiguration.RM_CACHE_CREDENTIALS.getKey() + " but file " + cred_path + " does not exist");
                }
                if (cred_path != null && new File(cred_path).exists()) {
                    Credentials cred = Credentials.getCredentials(cred_path);
                    rm.init(url, cred);
                } else {
                    String login = PortalConfiguration.RM_CACHE_LOGIN.getValueAsString();
                    String password = PortalConfiguration.RM_CACHE_PASSWORD.getValueAsString();
                    rm.init(url, new CredData(login, password));
                }
            }
        } catch (Exception e) {
            logger.warn("Could not connect to resource manager at " + url + " retrying in 8 seconds", e);
            if (rm != null) {
                PAActiveObject.terminateActiveObject(rm, true);
                rm = null;
            }
            new Sleeper(8 * 1000, logger).sleep();
            continue;
        }
    }
}
Also used : RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) CredData(org.ow2.proactive.authentication.crypto.CredData) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) Sleeper(org.objectweb.proactive.utils.Sleeper) File(java.io.File) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 82 with Credentials

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

the class SchedulerStateListener method connect.

private void connect() throws InterruptedException {
    String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
    String cred_path = PortalConfiguration.SCHEDULER_CACHE_CREDENTIALS.getValueAsStringOrNull();
    while (scheduler == null && !killed) {
        try {
            scheduler = PAActiveObject.newActive(SchedulerProxyUserInterface.class, new Object[] {});
            if (cred_path != null && !(new File(cred_path)).exists()) {
                logger.error("Credentials path set in " + PortalConfiguration.SCHEDULER_CACHE_CREDENTIALS.getKey() + " but file " + cred_path + " does not exist");
            }
            // check is we use a credential file
            if (cred_path != null && (new File(cred_path)).exists()) {
                Credentials credential = Credentials.getCredentials(cred_path);
                scheduler.init(url, credential);
            } else {
                String login = PortalConfiguration.SCHEDULER_CACHE_LOGIN.getValueAsString();
                String password = PortalConfiguration.SCHEDULER_CACHE_PASSWORD.getValueAsString();
                scheduler.init(url, login, password);
            }
            eventListener = new EventListener(state);
            // for PROACTIVE-1027 PROACTIVE-1233
            synchronized (MOPClassLoader.getMOPClassLoader()) {
                eventListener = PAActiveObject.turnActive(eventListener);
            }
            scheduler.addEventListener(eventListener, false, false);
        } catch (Exception e) {
            logger.warn("no scheduler found on " + url + " retrying in 8 seconds", e);
            if (scheduler != null) {
                PAActiveObject.terminateActiveObject(scheduler, true);
                scheduler = null;
            }
            Thread.sleep(8000);
            continue;
        }
    }
}
Also used : SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) File(java.io.File) Credentials(org.ow2.proactive.authentication.crypto.Credentials) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException)

Example 83 with Credentials

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

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

the class TestScheduler method startLocalNodes.

private static void startLocalNodes(SchedulerTestConfiguration configuration) throws KeyException, LoginException, InterruptedException {
    if (configuration.hasLocalNodes()) {
        // Waiting while all the nodes will be registered in the RM.
        // Without waiting test can finish earlier than nodes are added.
        // It leads to test execution hang up on windows due to running processes.
        Credentials creds = Credentials.createCredentials(new CredData(CredData.parseLogin(TestUsers.DEMO.username), CredData.parseDomain(TestUsers.DEMO.username), TestUsers.DEMO.password), rmAuth.getPublicKey());
        ResourceManager rm = rmAuth.login(creds);
        while (rm.getState().getTotalAliveNodesNumber() < SchedulerStartForFunctionalTest.RM_NODE_NUMBER) {
            Thread.sleep(50);
        }
        PAFuture.waitFor(rm.disconnect());
        System.out.println("Nodes are deployed");
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 85 with Credentials

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

the class SchedulerStartForFunctionalTest method createRMAndScheduler.

private static void createRMAndScheduler(String[] args) throws Exception {
    final boolean deployLocalNodes = Boolean.valueOf(args[0]);
    String schedPropPath = args[1];
    String rmPropPath = args[2];
    PAResourceManagerProperties.updateProperties(rmPropPath);
    PASchedulerProperties.updateProperties(schedPropPath);
    RMFactory.setOsJavaProperty();
    new SchedulerHsqldbStarter().startIfNeeded();
    new Thread() {

        public void run() {
            try {
                RMFactory.startLocal();
                // waiting the initialization
                RMAuthentication rmAuth = RMConnection.waitAndJoin(schedulerUrl);
                if (deployLocalNodes) {
                    Credentials credentials = Credentials.getCredentials(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString()));
                    ResourceManager rmAdmin = rmAuth.login(credentials);
                    rmAdmin.createNodeSource(RM_NODE_NAME, LocalInfrastructure.class.getName(), new Object[] { credentials.getBase64(), RM_NODE_NUMBER, RM_NODE_DEPLOYMENT_TIMEOUT, getJavaPropertiesLine() }, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE);
                    rmAdmin.disconnect();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    schedulerUrl = "pnp://localhost:" + PNPConfig.PA_PNP_PORT.getValue() + "/";
    SchedulerFactory.createScheduler(new URI(schedulerUrl), PASchedulerProperties.SCHEDULER_DEFAULT_POLICY.getValueAsString(), SchedulerStatus.STARTED);
    SchedulerConnection.waitAndJoin(schedulerUrl);
}
Also used : RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) URI(java.net.URI) Credentials(org.ow2.proactive.authentication.crypto.Credentials) SchedulerHsqldbStarter(org.ow2.proactive.scheduler.util.SchedulerHsqldbStarter)

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