use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class AddGetRemoveTest method action.
@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 = 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();
// ADD, GET, RELEASE
// 1) ADD
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.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
long originalUsedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn);
NodeSet nodes = rm.getNodes(new Criteria(1));
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
Thread.sleep(GR_DURATION);
rm.releaseNodes(nodes);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Check account values validity
long usedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn) - originalUsedNodeTime;
// 3) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
final long getRemoveMaxDuration = System.currentTimeMillis() - beforeGetTime;
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, greaterThan(GR_DURATION));
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, lessThan(getRemoveMaxDuration));
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class CredentialsCreator method createCredentials.
private byte[] createCredentials(String username, String password) throws ConnectionException, LoginException, KeyException {
String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
PublicKey pubKey = auth.getPublicKey();
byte[] privateKey = auth.getPrivateKey();
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privateKey), pubKey);
byte[] credentialBytes = cred.getBase64();
return credentialBytes;
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class RMRest method rmConnect.
/**
* Log into the resource manager using an form containing 2 fields
* @return the sessionid of the user if succeed
* @throws RMException
* @throws LoginException
* @throws KeyException
* @throws NodeException
* @throws ActiveObjectCreationException
*/
@Override
@POST
@Path("login")
@Produces("application/json")
public String rmConnect(@FormParam("username") String username, @FormParam("password") String password) throws KeyException, LoginException, RMException, ActiveObjectCreationException, NodeException {
Session session = sessionStore.create(username);
session.connectToRM(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password));
return session.getSessionId();
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class RMRest method loginWithCredential.
/*
* (non-Javadoc)
*
* @see org.ow2.proactive_grid_cloud_portal.SchedulerRestInterface#loginWithCredential(org.ow2.
* proactive_grid_cloud_portal.LoginForm)
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws ActiveObjectCreationException, NodeException, KeyException, IOException, LoginException, RMException {
Session session;
if (multipart.getCredential() != null) {
session = sessionStore.createUnnamedSession();
Credentials credentials = Credentials.getCredentials(multipart.getCredential());
session.connectToRM(credentials);
} else {
session = sessionStore.create(multipart.getUsername());
CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
session.connectToRM(credData);
}
return session.getSessionId();
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SchedulerNodeClient method connect.
/**
* Connects to the scheduler at the specified schedulerRestUrl, using the current user credentials
* @param url schedulerRestUrl of the scheduler
* @throws Exception
*/
public void connect(String url) throws Exception {
CredData userCreds = decrypter.decrypt();
client = SchedulerClient.createInstance();
client.init(new ConnectionInfo(url, userCreds.getLogin(), userCreds.getPassword(), null, true));
}
Aggregations