Search in sources :

Example 96 with Credentials

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

the class ForkerUtils method checkConfigAndGetUser.

/**
 * If the process must be run under a specific user,
 * check the configuration of '{@value #FORK_METHOD_KEY}' property and proceed as follow:
 * <ul>
 * 	<li><b>if {@value #FORK_METHOD_KEY}=none :</b> throws IllegalAccessException</li>
 * 	<li><b>if {@value #FORK_METHOD_KEY}=pwd :</b> return the user using its login and password</li>
 * 	<li><b>if {@value #FORK_METHOD_KEY}=key :</b> return the user using its ssh key</li>
 * </ul>
 *
 * @param taskContext the task context.
 * @return the OSUser to be passed to the OSPRocess if node fork method is configured.
 * @throws IllegalAccessException if the node configuration method is not compatible with incoming credentials
 * @throws KeyException decryption failure, malformed data
 * @throws IllegalArgumentException if decrypter is null
 * @throws IllegalAccessException if node fork method is not set
 */
public OSUser checkConfigAndGetUser(TaskContext taskContext) throws IllegalAccessException, KeyException {
    Decrypter decrypter = taskContext.getDecrypter();
    Map<String, String> genericInformation = taskContext.getInitializer().getGenericInformation();
    if (decrypter != null) {
        CredData data = decrypter.decrypt();
        OSUser u;
        switch(getForkMethod(genericInformation)) {
            case NONE:
                u = new OSUser(getLogin(data, genericInformation));
                u.setDomain(getDomain(data, genericInformation));
                return u;
            case PWD:
                String password = getPassword(data, genericInformation, data.getThirdPartyCredentials());
                if (password == null) {
                    throw new IllegalAccessException("Password not found in Credentials, cannot fork using password");
                }
                u = new OSUser(getLogin(data, genericInformation), password);
                u.setDomain(getDomain(data, genericInformation));
                return u;
            case KEY:
                byte[] key = getKey(data, genericInformation, data.getThirdPartyCredentials());
                if (key == null) {
                    throw new IllegalAccessException("SSH key not found in Credentials, cannot fork using ssh Key");
                }
                u = new OSUser(getLogin(data, genericInformation), key);
                u.setDomain(getDomain(data, genericInformation));
                return u;
            default:
                throw new IllegalAccessException("Cannot fork under " + data.getLogin() + ", Property " + FORK_METHOD_KEY + " is not configured.");
        }
    } else {
        throw new IllegalArgumentException("Decrypter cannot be null");
    }
}
Also used : OSUser(org.objectweb.proactive.extensions.processbuilder.OSUser) CredData(org.ow2.proactive.authentication.crypto.CredData)

Example 97 with Credentials

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

the class SmartProxyImpl method init.

@Override
public void init(ConnectionInfo connectionInfo) throws SchedulerException, LoginException {
    this.connectionInfo = connectionInfo;
    if (connectionInfo.getCredentialFile() != null) {
        try {
            Credentials credentials = Credentials.getCredentials(connectionInfo.getCredentialFile().getAbsolutePath());
            init(connectionInfo.getUrl(), credentials);
        } catch (KeyException e) {
            throw new LoginException(e.getMessage());
        }
    } else {
        CredData cred = new CredData(CredData.parseLogin(connectionInfo.getLogin()), CredData.parseDomain(connectionInfo.getLogin()), connectionInfo.getPassword());
        init(connectionInfo.getUrl(), 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)

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