use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class AddGetTest method action.
/**
* Test function.
* @throws Exception
*/
@org.junit.Test
public void action() throws Exception {
final ResourceManager rm = rmHelper.getResourceManager();
// The username and thr password must be the same a used to connect to the RM
final String adminLogin = TestUsers.TEST.username;
final String adminPassword = TestUsers.TEST.password;
// All accounting values are checked through JMX
final RMAuthentication auth = (RMAuthentication) rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
// Connect to the JMX RMI Connector Server
final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
// Tests on database
// (nodeprovider=demo)
// Ensure that no refreshes was done and all account values are correctly initialized
AttributeList atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
long usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
long providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
int providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
Assert.assertEquals("The accounts must not be refreshed automatically therefore the LastRefreshDurationInMilliseconds must be 0", (Long) 0l, (Long) conn.getAttribute(managementMBeanName, "LastRefreshDurationInMilliseconds"));
Assert.assertTrue("The usedNodeTime attribute must be 0", usedNodeTime == 0);
Assert.assertTrue("The providedNodeTime attribute must be 0", providedNodeTime == 0);
Assert.assertTrue("The providedNodesCount attribute must be 0", providedNodesCount == 0);
// ADD, GET
// 1) ADD
final long beforeAddTime = System.currentTimeMillis();
testNode = rmHelper.createNode("test");
Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
rm.addNode(nodeURL).getBooleanValue();
// we eat the configuring to free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
node = rm.getAtMostNodes(1, null).get(0);
// Sleep a certain amount of time that will be the minimum amount of the GET duration
Thread.sleep(GR_DURATION);
// Refresh the account manager
conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
final long currentTime = System.currentTimeMillis();
final long addRefreshMaxDuration = currentTime - beforeAddTime;
final long getRefreshMaxDuration = currentTime - beforeGetTime;
// Check account values validity
atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
Assert.assertTrue("Invalid value of the usedNodeTime attribute", (usedNodeTime >= GR_DURATION) && (usedNodeTime <= addRefreshMaxDuration));
Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= getRefreshMaxDuration));
Assert.assertTrue("Invalid value of the providedNodesCount attribute", (providedNodesCount == 1));
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsUser.
private void loginAsUser(RMAuthentication auth) throws LoginException, KeyException {
log("Test 2");
log("Trying to authorized with correct user name and password");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
ResourceManager user = auth.login(cred);
user.disconnect().getBooleanValue();
log("Passed: successful authentication");
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class AuthenticationTest method loginIncorrectAdminPassword.
private void loginIncorrectAdminPassword(RMAuthentication auth) throws KeyException {
// negative
log("Test 3");
log("Trying to authorized with incorrect user name and password");
try {
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, "b"), auth.getPublicKey());
auth.login(cred);
fail("Error: successful authentication");
} catch (LoginException e) {
log("Passed: expected error " + e.getMessage());
}
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class TestLoadJobs method testLoadJobs.
@Test
public void testLoadJobs() throws Exception {
long time = System.currentTimeMillis();
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
FileLock fileLock = new FileLock();
Path lock = fileLock.lock();
String fileLockPath = lock.toString();
logger.info("File lock location is " + fileLockPath);
JobInfo job;
List<JobInfo> jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
JobId firstJob = scheduler.submit(createJob(fileLockPath, null));
schedulerHelper.waitForEventTaskRunning(firstJob, "Test");
jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob);
job = jobs.get(0);
assertEquals(this.getClass().getSimpleName(), job.getJobId().getReadableName());
assertEquals(this.getClass().getSimpleName(), job.getProjectName());
assertEquals(1, job.getTotalNumberOfTasks());
assertEquals(0, job.getNumberOfFinishedTasks());
assertEquals(0, job.getNumberOfPendingTasks());
assertEquals(1, job.getNumberOfRunningTasks());
assertEquals(JobStatus.RUNNING, job.getStatus());
assertTrue("Unexpected submit time: " + job.getSubmittedTime(), job.getSubmittedTime() > time && job.getSubmittedTime() < System.currentTimeMillis());
assertTrue("Unexpected start time: " + job.getStartTime(), job.getStartTime() > time && job.getStartTime() < System.currentTimeMillis());
assertEquals(-1, job.getFinishedTime());
assertEquals(-1, job.getRemovedTime());
assertEquals(TestUsers.DEMO.username, job.getJobOwner());
assertEquals(JobPriority.NORMAL, job.getPriority());
JobId secondJob = scheduler.submit(createJob(fileLockPath, null));
JobId thirdJob = scheduler.submit(createJob(fileLockPath, secondJob.value()));
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(1, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob, thirdJob);
jobs = scheduler.getJobs(1, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true, false), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_DESC).getList();
checkJobs(jobs, thirdJob, secondJob, firstJob);
fileLock.unlock();
for (JobInfo jobInfo : jobs) {
schedulerHelper.waitForEventJobFinished(jobInfo.getJobId(), 30000);
}
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, false), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
scheduler.disconnect();
// connect as another user
SchedulerMonitorsHandler monitorsHandler = new SchedulerMonitorsHandler();
SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
scheduler = auth.login(cred);
eventReceiver = new MonitorEventReceiver(monitorsHandler);
eventReceiver = PAActiveObject.turnActive(eventReceiver);
SchedulerState state = scheduler.addEventListener(eventReceiver, true, true);
monitorsHandler.init(state);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
fileLockPath = fileLock.lock().toString();
JobId fourthJob = scheduler.submit(createJob(fileLockPath, null));
monitorsHandler.waitForEventTask(SchedulerEvent.TASK_PENDING_TO_RUNNING, fourthJob, "Test", 30000);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, fourthJob);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
jobs = scheduler.getJobs(2, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob, fourthJob);
fileLock.unlock();
monitorsHandler.waitForFinishedJob(fourthJob, 30000);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, fourthJob);
jobs = scheduler.getJobs(0, 10, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
jobs = scheduler.getJobs(1, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob);
jobs = scheduler.getJobs(1, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob, thirdJob);
jobs = scheduler.getJobs(2, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob);
jobs = scheduler.getJobs(2, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob, fourthJob);
scheduler.disconnect();
PAActiveObject.terminateActiveObject(eventReceiver, true);
// connect as a user who can see only its own jobs
cred = Credentials.createCredentials(new CredData("user", "pwd"), auth.getPublicKey());
scheduler = auth.login(cred);
monitorsHandler = new SchedulerMonitorsHandler();
eventReceiver = new MonitorEventReceiver(monitorsHandler);
eventReceiver = PAActiveObject.turnActive(eventReceiver);
state = scheduler.addEventListener(eventReceiver, true, true);
monitorsHandler.init(state);
JobId myjob = scheduler.submit(createJob(fileLockPath, null));
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, myjob);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, myjob);
scheduler.disconnect();
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class SchedulerStateRest method getCreateCredential.
@Override
public byte[] getCreateCredential(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);
}
}
Aggregations