Search in sources :

Example 21 with CredentialStoreException

use of org.apache.airavata.credential.store.store.CredentialStoreException 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)

Example 22 with CredentialStoreException

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

the class CommunityUserDAO method deleteCommunityUserByToken.

public void deleteCommunityUserByToken(CommunityUser user, String token, Connection connection) throws CredentialStoreException {
    String sql = "DELETE FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=? AND TOKEN_ID=?";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, user.getGatewayName());
        preparedStatement.setString(2, user.getUserName());
        preparedStatement.setString(3, token);
        preparedStatement.executeUpdate();
        connection.commit();
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error deleting community user.");
        stringBuilder.append("gateway - ").append(user.getGatewayName());
        stringBuilder.append("community user name - ").append(user.getUserName());
        log.error(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 23 with CredentialStoreException

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

the class CommunityUserDAO method getCommunityUser.

public CommunityUser getCommunityUser(String gatewayName, String communityUserName, Connection connection) throws CredentialStoreException {
    String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=?";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, gatewayName);
        preparedStatement.setString(2, communityUserName);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            // TODO fix typo
            String email = resultSet.getString("COMMUNITY_USER_EMAIL");
            return new CommunityUser(gatewayName, communityUserName, email);
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving community user.");
        stringBuilder.append("gateway - ").append(gatewayName);
        stringBuilder.append("community user name - ").append(communityUserName);
        log.error(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement);
    }
    return null;
}
Also used : CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 24 with CredentialStoreException

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

the class CommunityUserDAO method addCommunityUser.

public void addCommunityUser(CommunityUser user, String token, Connection connection) throws CredentialStoreException {
    String sql = "INSERT INTO COMMUNITY_USER VALUES (?, ?, ?, ?)";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, user.getGatewayName());
        preparedStatement.setString(2, user.getUserName());
        preparedStatement.setString(3, token);
        preparedStatement.setString(4, user.getUserEmail());
        preparedStatement.executeUpdate();
        connection.commit();
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error persisting community user.");
        stringBuilder.append("gateway - ").append(user.getGatewayName());
        stringBuilder.append("community user name - ").append(user.getUserName());
        stringBuilder.append("community user email - ").append(user.getUserEmail());
        stringBuilder.append("token id - ").append(token);
        log.error(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 25 with CredentialStoreException

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

the class CredentialsDAO method getCredential.

/**
 * 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 Credential getCredential(String gatewayName, String tokenId, Connection connection) throws CredentialStoreException {
    String sql = "SELECT * FROM CREDENTIALS WHERE GATEWAY_ID=? AND TOKEN_ID=?";
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, gatewayName);
        preparedStatement.setString(2, tokenId);
        resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            // CertificateCredential certificateCredential = new CertificateCredential();
            Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
            byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
            Credential certificateCredential = (Credential) convertByteArrayToObject(certificate);
            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")));
            return certificateCredential;
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for user.");
        stringBuilder.append("gateway - ").append(gatewayName);
        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 : Credential(org.apache.airavata.credential.store.credential.Credential) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

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