Search in sources :

Example 91 with Credentials

use of org.ow2.proactive.authentication.crypto.Credentials 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 92 with Credentials

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

the class InternalJob method getUserCredentials.

private UserCredentials getUserCredentials() {
    UserCredentials userCredentials = null;
    try {
        CredData decryptedUserCredentials = credentials.decrypt(corePrivateKey);
        if (PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.isSet() && decryptedUserCredentials.getDomain() == null) {
            decryptedUserCredentials.setDomain(PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.getValueAsString());
        }
        userCredentials = new UserCredentials(decryptedUserCredentials.getLogin(), decryptedUserCredentials.getPassword(), decryptedUserCredentials.getDomain(), decryptedUserCredentials.getKey());
    } catch (Exception e) {
        LOGGER.error("Could not decrypt user credentials", e);
    }
    return userCredentials;
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials) KeyException(java.security.KeyException) ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException)

Example 93 with Credentials

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

the class RMProxyActiveObject method cleanCallBack.

/**
 * Called when a script has returned (call is made as an active object call)
 * <p>
 * Check the nodes to release and release the one that have to (clean script has returned)
 * Take care when renaming this method, method name is linked to
 * {@link #handleCleaningScript(NodeSet, Script, VariablesMap, Map, TaskId, Credentials, Synchronization, SignalApi)}
 */
@ImmediateService
public synchronized void cleanCallBack(Future<ScriptResult<?>> future, NodeSet nodes) {
    String nodeUrl = nodes.get(0).getNodeInformation().getURL();
    ScriptResult<?> sResult = null;
    TaskId taskId = nodesTaskId.get(nodes);
    try {
        sResult = future.get();
    } catch (Exception e) {
        logger.error("Exception occurred while executing cleaning script on node " + nodeUrl + ":", e);
    }
    printCleaningScriptInformations(nodes, sResult, taskId);
    closeTaskLogger(taskId);
    releaseNodes(nodes);
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) LoginException(javax.security.auth.login.LoginException) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Example 94 with Credentials

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

the class ForkedTaskVariablesManagerTest method createCredentials.

private Decrypter createCredentials(String username, String password) throws NoSuchAlgorithmException, KeyException {
    Map<String, String> thirdPartyCreds = new HashMap<>();
    thirdPartyCreds.put(thirdPartyCred1Key, thirdPartyCred1Value);
    CredData credData = new CredData(username, password, thirdPartyCreds);
    KeyPairGenerator keyGen;
    keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512, new SecureRandom());
    KeyPair keyPair = keyGen.generateKeyPair();
    Decrypter decrypter = new Decrypter(keyPair.getPrivate());
    Credentials credentials = Credentials.createCredentials(credData, keyPair.getPublic());
    decrypter.setCredentials(credentials);
    return decrypter;
}
Also used : KeyPair(java.security.KeyPair) HashMap(java.util.HashMap) CredData(org.ow2.proactive.authentication.crypto.CredData) SecureRandom(java.security.SecureRandom) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) KeyPairGenerator(java.security.KeyPairGenerator) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 95 with Credentials

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

the class ForkedTaskExecutorRunAsMeTest method createCredentials.

private Decrypter createCredentials(String username, String password) throws NoSuchAlgorithmException, KeyException {
    CredData credData = new CredData(username, password);
    KeyPairGenerator keyGen;
    keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512, new SecureRandom());
    KeyPair keyPair = keyGen.generateKeyPair();
    Decrypter decrypter = new Decrypter(keyPair.getPrivate());
    Credentials credentials = Credentials.createCredentials(credData, keyPair.getPublic());
    decrypter.setCredentials(credentials);
    return decrypter;
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Aggregations

Credentials (org.ow2.proactive.authentication.crypto.Credentials)52 CredData (org.ow2.proactive.authentication.crypto.CredData)45 KeyException (java.security.KeyException)20 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)18 LoginException (javax.security.auth.login.LoginException)17 PublicKey (java.security.PublicKey)15 Test (org.junit.Test)15 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)14 HashMap (java.util.HashMap)13 IOException (java.io.IOException)12 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)12 File (java.io.File)9 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)6 JMXServiceURL (javax.management.remote.JMXServiceURL)6 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)6 Node (org.objectweb.proactive.core.node.Node)6 RMException (org.ow2.proactive.resourcemanager.exception.RMException)6 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)6 JMXConnector (javax.management.remote.JMXConnector)5