Search in sources :

Example 1 with DBUtil

use of org.apache.airavata.common.utils.DBUtil in project airavata by apache.

the class JDBCUserStore method initializeDatabaseLookup.

protected void initializeDatabaseLookup(String passwordColumn, String userTable, String userNameColumn) throws IllegalAccessException, ClassNotFoundException, InstantiationException {
    DBUtil dbUtil = new DBUtil(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver());
    DataSource dataSource = dbUtil.getDataSource();
    jdbcRealm.setDataSource(dataSource);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("SELECT ").append(passwordColumn).append(" FROM ").append(userTable).append(" WHERE ").append(userNameColumn).append(" = ?");
    jdbcRealm.setAuthenticationQuery(stringBuilder.toString());
}
Also used : DBUtil(org.apache.airavata.common.utils.DBUtil) DataSource(javax.sql.DataSource)

Example 2 with DBUtil

use of org.apache.airavata.common.utils.DBUtil 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 DBUtil

use of org.apache.airavata.common.utils.DBUtil in project airavata by apache.

the class CredentialStoreCallbackServlet method init.

public void init() throws ServletException {
    DBUtil dbUtil;
    try {
        dbUtil = DBUtil.getCredentialStoreDBUtil();
    } catch (Exception e) {
        throw new ServletException("Error initializing database operations.", e);
    }
    try {
        configurationReader = new ConfigurationReader();
        super.init();
        certificateCredentialWriter = new CertificateCredentialWriter(dbUtil);
    } catch (Exception e) {
        throw new ServletException("Error initializing configuration reader.", e);
    }
    // initialize notifier
    try {
        boolean enabled = Boolean.parseBoolean(ApplicationSettings.getCredentialStoreNotifierEnabled());
        if (enabled) {
            EmailNotifierConfiguration notifierConfiguration = EmailNotifierConfiguration.getEmailNotifierConfigurations();
            long duration = Long.parseLong(ApplicationSettings.getCredentialStoreNotifierDuration());
            notifierBootstrap = new NotifierBootstrap(duration, dbUtil, notifierConfiguration);
        }
    } catch (ApplicationSettingsException e) {
        throw new ServletException("Error initializing notifier.", e);
    }
    info("Credential store callback initialized successfully.");
}
Also used : ServletException(javax.servlet.ServletException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) DBUtil(org.apache.airavata.common.utils.DBUtil) CertificateCredentialWriter(org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter) NotifierBootstrap(org.apache.airavata.credential.store.notifier.NotifierBootstrap) EmailNotifierConfiguration(org.apache.airavata.credential.store.notifier.impl.EmailNotifierConfiguration) ServletException(javax.servlet.ServletException) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ConfigurationReader(org.apache.airavata.credential.store.util.ConfigurationReader)

Example 4 with DBUtil

use of org.apache.airavata.common.utils.DBUtil 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 5 with DBUtil

use of org.apache.airavata.common.utils.DBUtil 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

DBUtil (org.apache.airavata.common.utils.DBUtil)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)3 SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)3 SSHCredentialWriter (org.apache.airavata.credential.store.store.impl.SSHCredentialWriter)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)2 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 FileNotFoundException (java.io.FileNotFoundException)1 ServletException (javax.servlet.ServletException)1 DataSource (javax.sql.DataSource)1 NotifierBootstrap (org.apache.airavata.credential.store.notifier.NotifierBootstrap)1 EmailNotifierConfiguration (org.apache.airavata.credential.store.notifier.impl.EmailNotifierConfiguration)1 CertificateCredentialWriter (org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter)1 ConfigurationReader (org.apache.airavata.credential.store.util.ConfigurationReader)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