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");
}
}
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);
}
}
Aggregations