Search in sources :

Example 16 with CredentialStoreException

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

the class CredentialsDAO method getCredentials.

/**
 * Gets all credentials.
 * @param connection The database connection
 * @return All credentials as a list
 * @throws CredentialStoreException If an error occurred while rerieving credentials.
 */
public List<Credential> getCredentials(Connection connection) throws CredentialStoreException {
    List<Credential> credentialList = new ArrayList<Credential>();
    String sql = "SELECT * FROM CREDENTIALS";
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        resultSet = preparedStatement.executeQuery();
        Credential certificateCredential;
        while (resultSet.next()) {
            Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
            byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
            certificateCredential = (Credential) convertByteArrayToObject(certificate);
            certificateCredential.setToken(resultSet.getString("TOKEN_ID"));
            certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
            certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
            certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
            certificateCredential.setCredentialOwnerType(CredentialOwnerType.valueOf(resultSet.getString("CREDENTIAL_OWNER_TYPE")));
            credentialList.add(certificateCredential);
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving all credentials");
        log.debug(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement, resultSet);
    }
    return credentialList;
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) ArrayList(java.util.ArrayList) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 17 with CredentialStoreException

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

the class CredentialsDAO method getCredentials.

/**
 * String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + "        GATEWAY_ID VARCHAR(256) NOT NULL,\n" +
 * "        TOKEN_ID VARCHAR(256) NOT NULL,\n" + // Actual token used to identify the credential
 * "        CREDENTIAL BLOB NOT NULL,\n" + "        PORTAL_USER_ID VARCHAR(256) NOT NULL,\n" +
 * "        TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n" + "        PRIMARY KEY (GATEWAY_ID, TOKEN_ID)\n"
 * + ")";
 */
public List<Credential> getCredentials(String gatewayName, Connection connection) throws CredentialStoreException {
    List<Credential> credentialList = new ArrayList<Credential>();
    String sql = "SELECT * FROM CREDENTIALS WHERE GATEWAY_ID=?";
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, gatewayName);
        resultSet = preparedStatement.executeQuery();
        Credential certificateCredential;
        while (resultSet.next()) {
            Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
            byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
            certificateCredential = (Credential) convertByteArrayToObject(certificate);
            certificateCredential.setToken(resultSet.getString("TOKEN_ID"));
            certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
            certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
            certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
            certificateCredential.setCredentialOwnerType(CredentialOwnerType.valueOf(resultSet.getString("CREDENTIAL_OWNER_TYPE")));
            credentialList.add(certificateCredential);
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving credential list for ");
        stringBuilder.append("gateway - ").append(gatewayName);
        log.debug(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement, resultSet);
    }
    return credentialList;
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) ArrayList(java.util.ArrayList) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 18 with CredentialStoreException

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

the class CredentialsDAO method getGatewayID.

/**
 */
public String getGatewayID(String tokenId, Connection connection) throws CredentialStoreException {
    String sql = "SELECT GATEWAY_ID FROM CREDENTIALS WHERE TOKEN_ID=?";
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, tokenId);
        resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            return resultSet.getString("GATEWAY_ID");
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for user.");
        stringBuilder.append("token id - ").append(tokenId);
        log.debug(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement, resultSet);
    }
    return null;
}
Also used : CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 19 with CredentialStoreException

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

the class CertificateCredentialWriter method writeCredentials.

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

Example 20 with CredentialStoreException

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

the class GfacServerHandler method submitProcess.

/**
 * * After creating the experiment Data and Task Data in the orchestrator
 * * Orchestrator has to invoke this operation for each Task per experiment to run
 * * the actual Job related actions.
 * *
 * * @param experimentID
 * * @param taskID
 * * @param gatewayId:
 * *  The GatewayId is inferred from security context and passed onto gfac.
 * * @return sucess/failure
 * *
 * *
 *
 * @param processId - processModel id in registry
 * @param gatewayId - gateway Identification
 */
public boolean submitProcess(String processId, String gatewayId, String tokenId) throws TException {
    MDC.put(MDCConstants.PROCESS_ID, processId);
    MDC.put(MDCConstants.GATEWAY_ID, gatewayId);
    MDC.put(MDCConstants.TOKEN_ID, tokenId);
    try {
        executorService.execute(MDCUtil.wrapWithMDC(new GFacWorker(processId, gatewayId, tokenId)));
    } catch (GFacException e) {
        log.error("Failed to submit process", e);
        throw new TException("Failed to submit process", e);
    } catch (CredentialStoreException e) {
        log.error("Failed to submit process due to credential issue, " + "make sure you are passing a valid credentials");
        throw new TException("Failed to submit process due to credential issue, " + "make sure you are passing a valid credential token", e);
    } catch (Exception e) {
        log.error("Error creating zookeeper nodes", e);
        throw new TException("Error creating zookeeper nodes", e);
    }
    return true;
}
Also used : TException(org.apache.thrift.TException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacWorker(org.apache.airavata.gfac.impl.GFacWorker) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataStartupException(org.apache.airavata.common.exception.AiravataStartupException) GFacException(org.apache.airavata.gfac.core.GFacException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

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