Search in sources :

Example 61 with CredData

use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.

the class SchedulingService method addThirdPartyCredentials.

/**
 * Create a new Credential object containing users' 3rd Party Credentials.
 *
 * @param creds credentials for specific user
 * @return in case of success new object containing the 3rd party credentials used to create bindings
 * at clean script
 */
Credentials addThirdPartyCredentials(Credentials creds) throws KeyException, IllegalAccessException {
    // retrieve scheduler key pair
    String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
    String publicKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PUBKEY_PATH.getValueAsString());
    // get keys from task
    PrivateKey privateKey = Credentials.getPrivateKey(privateKeyPath);
    PublicKey publicKey = Credentials.getPublicKey(publicKeyPath);
    // retrieve the current creData from task
    CredData credData = creds.decrypt(privateKey);
    // retrive database to get third party credentials from
    SchedulerDBManager dbManager = getInfrastructure().getDBManager();
    if (dbManager != null) {
        Map<String, HybridEncryptedData> thirdPartyCredentials = dbManager.thirdPartyCredentialsMap(credData.getLogin());
        if (thirdPartyCredentials == null) {
            logger.error("Failed to retrieve Third Party Credentials!");
            throw new KeyException("Failed to retrieve thirdPartyCredentials!");
        } else {
            // cycle third party credentials, add one-by-one to the decrypter
            for (Map.Entry<String, HybridEncryptedData> thirdPartyCredential : thirdPartyCredentials.entrySet()) {
                String decryptedValue = HybridEncryptionUtil.decryptString(thirdPartyCredential.getValue(), privateKey);
                credData.addThirdPartyCredential(thirdPartyCredential.getKey(), decryptedValue);
            }
        }
    }
    return Credentials.createCredentials(credData, publicKey);
}
Also used : PrivateKey(java.security.PrivateKey) HybridEncryptedData(org.ow2.proactive.authentication.crypto.HybridEncryptionUtil.HybridEncryptedData) PublicKey(java.security.PublicKey) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) CredData(org.ow2.proactive.authentication.crypto.CredData) Map(java.util.Map) KeyException(java.security.KeyException)

Example 62 with CredData

use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.

the class TestRMProxyRebind method testRebind.

private void testRebind(URI rmUri1, URI rmUri2, ResourceManager rm1, ResourceManager rm2, RMMonitorsHandler monitorsHandler1, RMMonitorsHandler monitorsHandler2, boolean singleConnection) throws Exception {
    RMProxiesManager proxiesManager;
    if (singleConnection) {
        proxiesManager = new SingleConnectionRMProxiesManager(rmUri1, schedulerProxyCredentials);
    } else {
        proxiesManager = new PerUserConnectionRMProxiesManager(rmUri1, schedulerProxyCredentials);
    }
    Credentials user1Credentials = Credentials.createCredentials(new CredData("admin", "admin"), helper1.getAuth().getPublicKey());
    RMProxy proxy1 = proxiesManager.getUserRMProxy("admin", user1Credentials);
    log("Get one node with RM1");
    NodeSet rm1NodeSet1 = proxy1.getNodes(new Criteria(1));
    waitWhenNodeSetAcquired(rm1NodeSet1, 1, monitorsHandler1);
    checkFreeNodes(rm1, NODES_NUMBER - 1);
    checkFreeNodes(rm2, NODES_NUMBER);
    assertEquals(NODES_NUMBER - 1, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    log("Get one node with RM1");
    NodeSet rm1NodeSet2 = proxy1.getNodes(new Criteria(1));
    waitWhenNodeSetAcquired(rm1NodeSet2, 1, monitorsHandler1);
    checkFreeNodes(rm1, NODES_NUMBER - 2);
    checkFreeNodes(rm2, NODES_NUMBER);
    assertEquals(NODES_NUMBER - 2, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    assertTrue(proxiesManager.getRmProxy().isActive().getBooleanValue());
    log("Rebinding to " + rmUri2);
    proxiesManager.rebindRMProxiesManager(rmUri2);
    assertEquals(NODES_NUMBER, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    assertTrue(proxiesManager.getRmProxy().isActive().getBooleanValue());
    waitWhenNodeSetReleased(2, monitorsHandler1);
    log("Get one node with RM2");
    NodeSet rm2NodeSet1 = proxy1.getNodes(new Criteria(1));
    waitWhenNodeSetAcquired(rm2NodeSet1, 1, monitorsHandler2);
    checkFreeNodes(rm1, NODES_NUMBER);
    checkFreeNodes(rm2, NODES_NUMBER - 1);
    assertEquals(NODES_NUMBER - 1, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    log("Get two nodes with RM2");
    NodeSet rm2NodeSet2 = proxy1.getNodes(new Criteria(2));
    waitWhenNodeSetAcquired(rm2NodeSet2, 2, monitorsHandler2);
    checkFreeNodes(rm1, NODES_NUMBER);
    checkFreeNodes(rm2, NODES_NUMBER - 3);
    assertEquals(NODES_NUMBER - 3, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    log("Release one node with RM2");
    proxy1.releaseNodes(rm2NodeSet1);
    waitWhenNodeSetReleased(1, monitorsHandler2);
    checkFreeNodes(rm1, NODES_NUMBER);
    checkFreeNodes(rm2, NODES_NUMBER - 2);
    assertEquals(NODES_NUMBER - 2, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    log("Kill RM1");
    PAFuture.waitFor(rm1.shutdown(true));
    helper1.kill();
    rm1 = null;
    assertEquals(NODES_NUMBER - 2, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    assertTrue(proxiesManager.getRmProxy().isActive().getBooleanValue());
    log("Release two nodes with RM2");
    proxy1.releaseNodes(rm2NodeSet2);
    waitWhenNodeSetReleased(2, monitorsHandler2);
    checkFreeNodes(rm2, NODES_NUMBER);
    assertEquals(NODES_NUMBER, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    assertTrue(proxiesManager.getRmProxy().isActive().getBooleanValue());
    log("Try to release node with terminated RM1");
    proxy1.releaseNodes(rm1NodeSet2);
    log("Try to release node with terminated RM1 one more time");
    proxy1.releaseNodes(rm1NodeSet2);
    assertEquals(NODES_NUMBER, proxiesManager.getRmProxy().getState().getFreeNodesNumber());
    assertTrue(proxiesManager.getRmProxy().isActive().getBooleanValue());
    log("Terminate all proxies");
    proxiesManager.terminateAllProxies();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) RMProxy(org.ow2.proactive.scheduler.core.rmproxies.RMProxy) PerUserConnectionRMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.PerUserConnectionRMProxiesManager) CredData(org.ow2.proactive.authentication.crypto.CredData) Criteria(org.ow2.proactive.utils.Criteria) SingleConnectionRMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.SingleConnectionRMProxiesManager) PerUserConnectionRMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.PerUserConnectionRMProxiesManager) SingleConnectionRMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.SingleConnectionRMProxiesManager) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

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