Search in sources :

Example 11 with CredData

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));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) NodeSet(org.ow2.proactive.utils.NodeSet) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) Node(org.objectweb.proactive.core.node.Node) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) ObjectName(javax.management.ObjectName) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) JMXConnector(javax.management.remote.JMXConnector) Credentials(org.ow2.proactive.authentication.crypto.Credentials) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 12 with CredData

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;
}
Also used : PublicKey(java.security.PublicKey) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 13 with CredData

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();
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 14 with CredData

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();
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 15 with CredData

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));
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) ConnectionInfo(org.ow2.proactive.authentication.ConnectionInfo)

Aggregations

CredData (org.ow2.proactive.authentication.crypto.CredData)53 Credentials (org.ow2.proactive.authentication.crypto.Credentials)41 PublicKey (java.security.PublicKey)15 Test (org.junit.Test)15 LoginException (javax.security.auth.login.LoginException)13 KeyException (java.security.KeyException)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)10 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)10 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)9 HashMap (java.util.HashMap)8 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)6 JMXServiceURL (javax.management.remote.JMXServiceURL)6 JMXConnector (javax.management.remote.JMXConnector)5 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 SchedulerProxyUserInterface (org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface)5 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)5 MBeanServerConnection (javax.management.MBeanServerConnection)4 ObjectName (javax.management.ObjectName)4 POST (javax.ws.rs.POST)4