use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface in project scheduling by ow2-proactive.
the class SchedulerStateRest method getCreateCredential.
/**
* generates a credential file from user provided credentials
*
* @return the credential file generated by the scheduler
* @throws LoginException
* @throws SchedulerRestException
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("createcredential")
@Produces("*/*")
public byte[] getCreateCredential(@MultipartForm LoginForm multipart) throws LoginException, SchedulerRestException {
String username = multipart.getUsername();
String password = multipart.getPassword();
byte[] privKey = multipart.getSshKey();
try {
String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
PublicKey pubKey = auth.getPublicKey();
sessionStore.create(username);
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privKey), pubKey);
return cred.getBase64();
} catch (ConnectionException | KeyException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface in project scheduling by ow2-proactive.
the class SchedulerAwarePolicy method waitAndConnectToScheduler.
private void waitAndConnectToScheduler() throws Exception {
SchedulerAuthenticationInterface authentication;
boolean firstException = true;
int trialsNumber = 0;
while (scheduler == null && trialsNumber <= schedulerAwarePolicyNodeSourceRecoveryTrialsNumber) {
trialsNumber++;
try {
authentication = SchedulerConnection.join(schedulerUrl);
Credentials creds = Credentials.getCredentialsBase64(credentials);
scheduler = authentication.login(creds);
Thread.sleep(schedulerAwarePolicyNodeSourceRecoveryDelay);
} catch (Throwable t) {
if (firstException) {
logger.warn("Could not contact scheduler at url " + schedulerUrl + " this is normal if the scheduler has just been restarted", t);
firstException = false;
} else {
logger.debug("Could not contact scheduler", t);
}
}
if (trialsNumber > schedulerAwarePolicyNodeSourceRecoveryTrialsNumber)
throw new ConnectionException("Number of trials exceeded and could not contact scheduler");
}
}
use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface in project scheduling by ow2-proactive.
the class AbstractSchedulerUser method connectToScheduler.
public void connectToScheduler() throws SchedulerException, LoginException {
SchedulerAuthenticationInterface auth = SchedulerConnection.join(this.schedulerURL);
this.scheduler = auth.login(this.userCreds);
this.defaultParameter = this.scheduler;
}
use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsAdminIncorrectPassword.
private void loginAsAdminIncorrectPassword(SchedulerAuthenticationInterface auth, PublicKey pubKey) {
// negative
log("Test 3");
log("Trying to authorized as an admin with incorrect user name and password");
try {
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, "b"), pubKey);
auth.login(cred);
fail("Error: successful authentication");
} catch (Exception e) {
log("Passed: expected error " + e.getMessage());
}
}
use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsUser.
private void loginAsUser(SchedulerAuthenticationInterface auth, PublicKey pubKey) throws KeyException, LoginException, AlreadyConnectedException, NotConnectedException, PermissionException {
log("Test 2");
log("Trying to authorized as a user with correct user name and password");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), pubKey);
Scheduler user = auth.login(cred);
String userName = user.getCurrentUser();
Assert.assertEquals(TestUsers.USER.username, userName);
UserData userData = user.getCurrentUserData();
Assert.assertNotNull(userData);
Assert.assertNotNull(userData.getUserName());
Assert.assertNotNull(userData.getGroups());
Assert.assertTrue(userData.getGroups().contains("user"));
user.disconnect();
log("Passed: successful authentication");
}
Aggregations