Search in sources :

Example 36 with CredentialStoreException

use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.

the class SSHCredentialTest method main.

public static void main(String[] args) {
    String jdbcURL = "jdbc:mysql://gw85.iu.xsede.org:3306/airavata_gw119";
    String jdbcDriver = "com.mysql.jdbc.Driver";
    String userName = "gtaDevUser";
    String password = "gtaDevPWD";
    String gatewayId = "phasta";
    String privateKeyPath = "/Users/chathuri/Desktop/ssh_gw111/id_rsa";
    String pubKeyPath = "/Users/chathuri/Desktop/ssh_gw111/id_rsa.pub";
    try {
        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);
        System.out.println(token);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ApplicationSettingsException e) {
        e.printStackTrace();
    } catch (CredentialStoreException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SSHCredentialWriter(org.apache.airavata.credential.store.store.impl.SSHCredentialWriter) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) FileNotFoundException(java.io.FileNotFoundException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DBUtil(org.apache.airavata.common.utils.DBUtil) File(java.io.File)

Example 37 with CredentialStoreException

use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.

the class BESJobSubmissionTask method copyOutputFilesToStorage.

private void copyOutputFilesToStorage(TaskContext taskContext, List<OutputDataObjectType> copyOutput) throws GFacException {
    ProcessContext pc = taskContext.getParentProcessContext();
    String remoteFilePath = null, fileName = null, localFilePath = null;
    try {
        authenticationInfo = Factory.getStorageSSHKeyAuthentication(pc);
        ServerInfo serverInfo = pc.getComputeResourceServerInfo();
        Session sshSession = Factory.getSSHSession(authenticationInfo, serverInfo);
        for (OutputDataObjectType output : copyOutput) {
            switch(output.getType()) {
                case STDERR:
                case STDOUT:
                case STRING:
                case URI:
                    localFilePath = output.getValue();
                    if (localFilePath.contains("://")) {
                        localFilePath = localFilePath.substring(localFilePath.indexOf("://") + 2, localFilePath.length());
                    }
                    fileName = localFilePath.substring(localFilePath.lastIndexOf("/") + 1);
                    URI destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, fileName);
                    remoteFilePath = destinationURI.getPath();
                    log.info("SCP local file :{} -> from remote :{}", localFilePath, remoteFilePath);
                    SSHUtils.scpTo(localFilePath, remoteFilePath, sshSession);
                    output.setValue(destinationURI.toString());
                    break;
                default:
                    break;
            }
        }
    } catch (IOException | JSchException | SSHApiException | URISyntaxException | CredentialStoreException e) {
        log.error("Error while coping local file " + localFilePath + " to remote " + remoteFilePath, e);
        throw new GFacException("Error while scp output files to remote storage file location", e);
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) URI(java.net.URI) SSHApiException(org.apache.airavata.gfac.core.SSHApiException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) GFacException(org.apache.airavata.gfac.core.GFacException) Session(com.jcraft.jsch.Session)

Example 38 with CredentialStoreException

use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.

the class GatewayRegister method registerSSHKeys.

public void registerSSHKeys() throws Exception {
    try {
        // write tokens to file
        String tokenWriteLocation = properties.getTokenFileLoc();
        String fileName = tokenWriteLocation + File.separator + TestFrameworkConstants.CredentialStoreConstants.TOKEN_FILE_NAME;
        PrintWriter tokenWriter = new PrintWriter(fileName, "UTF-8");
        // credential store related functions are not in the current api, so need to call credential store directly
        String jdbcURL = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_URL, PropertyFileType.AIRAVATA_SERVER);
        String jdbcDriver = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_DRIVER, PropertyFileType.AIRAVATA_SERVER);
        String userName = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_USERNAME, PropertyFileType.AIRAVATA_SERVER);
        String password = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_PWD, PropertyFileType.AIRAVATA_SERVER);
        String privateKeyPath = properties.getSshPrivateKeyLoc();
        String pubKeyPath = properties.getSshPubKeyLoc();
        String keyPassword = properties.getSshPassword();
        DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver);
        SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil);
        Gateway gateway = airavata.getGateway(authzToken, properties.getGname());
        SSHCredential sshCredential = new SSHCredential();
        sshCredential.setGateway(gateway.getGatewayId());
        String token = TokenGenerator.generateToken(gateway.getGatewayId(), null);
        sshCredential.setToken(token);
        sshCredential.setPortalUserName(testUser);
        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(keyPassword);
        writer.writeCredentials(sshCredential);
        tokenMap.put(gateway.getGatewayId(), token);
        tokenWriter.println(gateway.getGatewayId() + ":" + token);
        tokenWriter.close();
    } catch (ClassNotFoundException e) {
        logger.error("Unable to find mysql driver", e);
        throw new Exception("Unable to find mysql driver", e);
    } catch (InstantiationException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (IllegalAccessException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (ApplicationSettingsException e) {
        logger.error("Unable to read airavata-client properties", e);
        throw new Exception("Unable to read airavata-client properties", e);
    } catch (AiravataSystemException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (InvalidRequestException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (AiravataClientException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (TException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (FileNotFoundException e) {
        logger.error("Could not find keys specified in the path", e);
        throw new Exception("Could not find keys specified in the path", e);
    } catch (CredentialStoreException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (IOException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    }
}
Also used : TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SSHCredentialWriter(org.apache.airavata.credential.store.store.impl.SSHCredentialWriter) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TException(org.apache.thrift.TException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) DBUtil(org.apache.airavata.common.utils.DBUtil) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) Gateway(org.apache.airavata.model.workspace.Gateway) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException)

Aggregations

CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)38 Credential (org.apache.airavata.credential.store.credential.Credential)14 org.apache.airavata.model.credential.store (org.apache.airavata.model.credential.store)10 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)6 PreparedStatement (java.sql.PreparedStatement)6 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)6 GFacException (org.apache.airavata.gfac.core.GFacException)5 TException (org.apache.thrift.TException)5 JSchException (com.jcraft.jsch.JSchException)4 Session (com.jcraft.jsch.Session)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)4 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)4 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)3 StorageResourceDescription (org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription)3