Search in sources :

Example 6 with Credentials

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

the class RMNodeStarter method getDefaultCredentials.

private Credentials getDefaultCredentials() {
    try {
        return Credentials.getCredentials();
    } catch (KeyException fromDiskKeyException) {
        try {
            Credentials credentialsFromRMHome = Credentials.getCredentials(new File(PAResourceManagerProperties.RM_HOME.getValueAsStringOrNull(), "config/authentication/rm.cred").getAbsolutePath());
            logger.info("Using default credentials from ProActive home, authenticating as user rm");
            return credentialsFromRMHome;
        } catch (KeyException fromRMHomeKeyException) {
            try {
                Credentials credentialsFromJar = Credentials.getCredentials(RMNodeStarter.class.getResourceAsStream("/config/authentication/rm.cred"));
                logger.info("Using default credentials from ProActive jars, authenticating as user rm");
                return credentialsFromJar;
            } catch (Exception fromJarKeyException) {
                logger.error("Failed to read credentials, from location obtained using system property, RM home or ProActive jars", fromJarKeyException);
                System.exit(ExitStatus.CRED_UNREADABLE.exitCode);
            }
        }
    }
    return null;
}
Also used : File(java.io.File) KeyException(java.security.KeyException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) KeyException(java.security.KeyException) NotConfiguredException(org.objectweb.proactive.extensions.dataspaces.exceptions.NotConfiguredException) NodeException(org.objectweb.proactive.core.node.NodeException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) ProActiveRuntimeException(org.objectweb.proactive.core.ProActiveRuntimeException) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ProActiveException(org.objectweb.proactive.core.ProActiveException)

Example 7 with Credentials

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

the class RMNodeStarter method registerInRM.

/**
 * Tries to join to the Resource Manager with a specified timeout
 * at the given URL, logs with provided credentials and adds the local node to
 * the Resource Manager. Handles all errors/exceptions.
 */
protected ResourceManager registerInRM(final Credentials credentials, final String rmURL, final String nodeName, final Collection<Node> nodes) {
    RMAuthentication auth = joinResourceManager(rmURL);
    final ResourceManager rm = loginToResourceManager(credentials, auth);
    SigarExposer sigarExposer = null;
    if (!disabledMonitoring) {
        // initializing JMX server with Sigar beans
        sigarExposer = new SigarExposer(nodeName);
        final RMAuthentication rmAuth = auth;
        sigarExposer.boot(auth, false, new PermissionChecker() {

            @Override
            public boolean checkPermission(Credentials cred) {
                ResourceManager rm = null;
                try {
                    rm = rmAuth.login(cred);
                    if (NB_OF_ADD_NODE_ATTEMPTS == 0)
                        return true;
                    boolean isAdmin = rm.isNodeAdmin(nodes.iterator().next().getNodeInformation().getURL()).getBooleanValue();
                    if (!isAdmin) {
                        throw new SecurityException("Permission denied");
                    }
                    return true;
                } catch (LoginException e) {
                    throw new SecurityException(e);
                } finally {
                    if (rm != null) {
                        rm.disconnect();
                    }
                }
            }
        });
    } else {
        logger.info("JMX monitoring is disabled.");
    }
    for (final Node node : nodes) {
        nodeSetJmxUrl(sigarExposer, node);
        addNodeToResourceManager(rmURL, node, rm);
    }
    return rm;
}
Also used : SigarExposer(org.ow2.proactive.resourcemanager.node.jmx.SigarExposer) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) PermissionChecker(org.ow2.proactive.jmx.PermissionChecker) Node(org.objectweb.proactive.core.node.Node) LoginException(javax.security.auth.login.LoginException) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 8 with Credentials

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

the class SSHInfrastructure method configure.

/**
 * Configures the Infrastructure
 *
 * @param parameters
 *            parameters[4] : ssh Options, see {@link SSHClient}
 *            parameters[5] : java path on the remote machines parameters[6]
 *            : Scheduling path on remote machines parameters[7] : target
 *            OS' type (Linux, Windows or Cygwin) parameters[8] : extra java
 *            options parameters[9] : rm cred
 * @throws IllegalArgumentException
 *             configuration failed
 */
@Override
public void configure(Object... parameters) {
    super.configure(parameters);
    int index = 4;
    if (parameters != null && parameters.length >= 10) {
        this.sshOptions = parameters[index++].toString();
        this.javaPath = parameters[index++].toString();
        if (this.javaPath == null || this.javaPath.equals("")) {
            throw new IllegalArgumentException("A valid Java path must be supplied.");
        }
        this.schedulingPath = parameters[index++].toString();
        // target OS
        if (parameters[index] != null) {
            OperatingSystem configuredTargetOs = OperatingSystem.getOperatingSystem(parameters[index++].toString());
            if (configuredTargetOs == null) {
                throw new IllegalArgumentException("Only 'Linux', 'Windows' and 'Cygwin' are valid values for Target OS Property.");
            }
            persistedInfraVariables.put(TARGET_OS_OBJ_KEY, configuredTargetOs);
        } else {
            throw new IllegalArgumentException("Target OS parameter cannot be null");
        }
        this.javaOptions = parameters[index++].toString();
        // credentials
        if (parameters[index] == null) {
            throw new IllegalArgumentException("Credentials must be specified");
        }
        try {
            persistedInfraVariables.put(CREDENTIALS_KEY, Credentials.getCredentialsBase64((byte[]) parameters[index++]));
        } catch (KeyException e) {
            throw new IllegalArgumentException("Could not retrieve base64 credentials", e);
        }
    } else {
        throw new IllegalArgumentException("Invalid parameters for infrastructure creation");
    }
}
Also used : OperatingSystem(org.ow2.proactive.resourcemanager.utils.OperatingSystem) KeyException(java.security.KeyException)

Example 9 with Credentials

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

the class AuthenticationTest method loginIncorrectUserPassword.

private void loginIncorrectUserPassword(RMAuthentication auth) throws KeyException {
    log("Test 4");
    log("Trying to authorized with incorrect user name and password");
    try {
        Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, "b"), auth.getPublicKey());
        auth.login(cred);
        fail("Error: successful authentication");
    } catch (LoginException e) {
        log("Passed: expected error " + e.getMessage());
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 10 with Credentials

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

the class AuthenticationTest method loginAsAdmin.

private void loginAsAdmin(RMAuthentication auth) throws LoginException, KeyException {
    log("Test 1");
    log("Trying to authorized with correct admin name and password");
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
    ResourceManager admin = auth.login(cred);
    admin.disconnect().getBooleanValue();
    log("Passed: successful authentication");
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

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