Search in sources :

Example 1 with SSHCredential

use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.

the class Factory method getSshKeyAuthentication.

private static SSHKeyAuthentication getSshKeyAuthentication(String gatewayId, String loginUserName, String credentialStoreToken) throws ApplicationSettingsException, IllegalAccessException, InstantiationException, CredentialStoreException, GFacException {
    SSHKeyAuthentication sshKA;
    CredentialReader credentialReader = GFacUtils.getCredentialReader();
    Credential credential = credentialReader.getCredential(gatewayId, credentialStoreToken);
    if (credential instanceof SSHCredential) {
        sshKA = new SSHKeyAuthentication();
        sshKA.setUserName(loginUserName);
        SSHCredential sshCredential = (SSHCredential) credential;
        sshKA.setPublicKey(sshCredential.getPublicKey());
        sshKA.setPrivateKey(sshCredential.getPrivateKey());
        sshKA.setPassphrase(sshCredential.getPassphrase());
        sshKA.setStrictHostKeyChecking("no");
        /*            sshKA.setStrictHostKeyChecking(ServerSettings.getSetting("ssh.strict.hostKey.checking", "no"));
            sshKA.setKnownHostsFilePath(ServerSettings.getSetting("ssh.known.hosts.file", null));
            if (sshKA.getStrictHostKeyChecking().equals("yes") && sshKA.getKnownHostsFilePath() == null) {
                throw new ApplicationSettingsException("If ssh strict hostkey checking property is set to yes, you must " +
                        "provide known host file path");
            }*/
        return sshKA;
    } else {
        String msg = "Provided credential store token is not valid. Please provide the correct credential store token";
        log.error(msg);
        throw new CredentialStoreException("Invalid credential store token:" + credentialStoreToken);
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) SSHKeyAuthentication(org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)

Example 2 with SSHCredential

use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.

the class SSHSummaryTest method testSSHSummary.

// @Test Change the properties in ServerProperties file and give the correct path to run the test
public void testSSHSummary() throws Exception {
    try {
        String jdbcURL = ServerSettings.getCredentialStoreDBURL();
        String jdbcDriver = ServerSettings.getCredentialStoreDBDriver();
        String userName = ServerSettings.getCredentialStoreDBUser();
        String password = ServerSettings.getCredentialStoreDBPassword();
        String gatewayId = "phasta";
        String privateKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata";
        String pubKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata.pub";
        DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver);
        SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil);
        SSHCredential sshCredential = new SSHCredential();
        sshCredential.setGateway(gatewayId);
        String token = TokenGenerator.generateToken(gatewayId, null);
        sshCredential.setToken(token);
        sshCredential.setPortalUserName("phasta");
        sshCredential.setDescription("dummy creds for testing");
        FileInputStream privateKeyStream = new FileInputStream(privateKeyPath);
        File filePri = new File(privateKeyPath);
        byte[] bFilePri = new byte[(int) filePri.length()];
        privateKeyStream.read(bFilePri);
        FileInputStream pubKeyStream = new FileInputStream(pubKeyPath);
        File filePub = new File(pubKeyPath);
        byte[] bFilePub = new byte[(int) filePub.length()];
        pubKeyStream.read(bFilePub);
        privateKeyStream.close();
        pubKeyStream.close();
        sshCredential.setPrivateKey(bFilePri);
        sshCredential.setPublicKey(bFilePub);
        sshCredential.setPassphrase("ultrascan");
        writer.writeCredentials(sshCredential);
        Assert.assertEquals(token, sshCredential.getToken());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : DBUtil(org.apache.airavata.common.utils.DBUtil) SSHCredentialWriter(org.apache.airavata.credential.store.store.impl.SSHCredentialWriter) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with SSHCredential

use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.

the class TokenizedSSHAuthInfo method getDefaultCredentials.

/**
 * Gets the default proxy certificate.
 *
 * @return Default my proxy credentials.
 * @throws GFacException                            If an error occurred while retrieving credentials.
 * @throws org.apache.airavata.common.exception.ApplicationSettingsException
 */
public SSHCredential getDefaultCredentials() throws GFacException, ApplicationSettingsException, IOException {
    Properties configurationProperties = ServerSettings.getProperties();
    String sshUserName = configurationProperties.getProperty(GFacConstants.SSH_USER_NAME);
    this.getRequestData().setRequestUser(sshUserName);
    this.privateKeyFile = configurationProperties.getProperty(GFacConstants.SSH_PRIVATE_KEY);
    this.publicKeyFile = configurationProperties.getProperty(GFacConstants.SSH_PUBLIC_KEY);
    this.passPhrase = configurationProperties.getProperty(GFacConstants.SSH_PRIVATE_KEY_PASS);
    this.getRequestData().setRequestUser(sshUserName);
    return new SSHCredential(IOUtil.readToByteArray(new File(this.privateKeyFile)), IOUtil.readToByteArray(new File(this.publicKeyFile)), this.passPhrase, requestData.getGatewayId(), sshUserName);
}
Also used : SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) Properties(java.util.Properties)

Example 4 with SSHCredential

use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.

the class TokenizedSSHAuthInfo method getCredentialsFromStore.

/**
 * Reads the credentials from credential store.
 *
 * @return If token is found in the credential store, will return a valid credential. Else returns null.
 * @throws Exception If an error occurred while retrieving credentials.
 */
public SSHCredential getCredentialsFromStore() throws Exception {
    if (getCredentialReader() == null) {
        credentialReader = GFacUtils.getCredentialReader();
        if (credentialReader == null) {
            return null;
        }
    }
    Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
    if (credential instanceof SSHCredential) {
        SSHCredential credential1 = (SSHCredential) credential;
        this.publicKeyFile = writeFileToDisk(credential1.getPublicKey());
        this.privateKeyFile = writeFileToDisk(credential1.getPrivateKey());
        this.passPhrase = credential1.getPassphrase();
        System.out.println(this.publicKeyFile);
        System.out.println(this.privateKeyFile);
        System.out.println(this.passPhrase);
        this.getRequestData().setRequestUser(credential1.getPortalUserName());
        return credential1;
    } else {
        log.info("Could not find SSH credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
    }
    return null;
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)

Example 5 with SSHCredential

use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.

the class SSHCredentialWriter method writeCredentials.

public void writeCredentials(Credential credential) throws CredentialStoreException {
    SSHCredential sshCredential = (SSHCredential) credential;
    Connection connection = null;
    try {
        connection = dbUtil.getConnection();
        // First delete existing credentials
        credentialsDAO.deleteCredentials(sshCredential.getGateway(), sshCredential.getToken(), connection);
        // Add the new certificate
        credentialsDAO.addCredentials(sshCredential.getGateway(), credential, connection);
        if (!connection.getAutoCommit()) {
            connection.commit();
        }
    } catch (SQLException e) {
        if (connection != null) {
            try {
                connection.rollback();
            } catch (SQLException e1) {
                logger.error("Unable to rollback transaction", e1);
            }
        }
        throw new CredentialStoreException("Unable to retrieve database connection.", e);
    } finally {
        DBUtil.cleanup(connection);
    }
}
Also used : SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Aggregations

SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)7 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)4 DBUtil (org.apache.airavata.common.utils.DBUtil)3 SSHCredentialWriter (org.apache.airavata.credential.store.store.impl.SSHCredentialWriter)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 Credential (org.apache.airavata.credential.store.credential.Credential)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)1 SSHKeyAuthentication (org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)1 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)1 AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)1 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)1 Gateway (org.apache.airavata.model.workspace.Gateway)1 TException (org.apache.thrift.TException)1