Search in sources :

Example 1 with OSUser

use of org.objectweb.proactive.extensions.processbuilder.OSUser 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)

Aggregations

OSUser (org.objectweb.proactive.extensions.processbuilder.OSUser)1 CredData (org.ow2.proactive.authentication.crypto.CredData)1