Search in sources :

Example 11 with CredentialStoreException

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

the class CredentialStoreServerHandler method getAllCredentialSummaryForUserInGateway.

@Override
public List<CredentialSummary> getAllCredentialSummaryForUserInGateway(SummaryType type, String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    if (type.equals(SummaryType.SSH)) {
        Map<String, String> sshKeyMap = new HashMap<>();
        List<CredentialSummary> summaryList = new ArrayList<>();
        try {
            List<Credential> allCredentials = credentialReader.getAllCredentials();
            if (allCredentials != null && !allCredentials.isEmpty()) {
                for (Credential credential : allCredentials) {
                    if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) {
                        org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
                        String portalUserName = sshCredential.getPortalUserName();
                        String gateway = sshCredential.getGateway();
                        if (portalUserName != null && gateway != null) {
                            if (portalUserName.equals(userId) && gateway.equals(gatewayId) && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) {
                                org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredentialKey = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
                                CredentialSummary sshCredentialSummary = new CredentialSummary();
                                sshCredentialSummary.setType(SummaryType.SSH);
                                sshCredentialSummary.setToken(sshCredentialKey.getToken());
                                sshCredentialSummary.setUsername(sshCredentialKey.getPortalUserName());
                                sshCredentialSummary.setGatewayId(sshCredentialKey.getGateway());
                                sshCredentialSummary.setDescription(sshCredentialKey.getDescription());
                                sshCredentialSummary.setPublicKey(new String(sshCredentialKey.getPublicKey()));
                                summaryList.add(sshCredentialSummary);
                            }
                        }
                    }
                }
            }
        } catch (CredentialStoreException e) {
            log.error("Error occurred while retrieving credential Summary", e);
            throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credential Summary");
        }
        return summaryList;
    } else {
        log.info("Summay Type" + type.toString() + " not supported for user Id - " + userId + " and " + "gateway id - " + gatewayId);
        return null;
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) org.apache.airavata.model.credential.store(org.apache.airavata.model.credential.store) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 12 with CredentialStoreException

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

the class CredentialStoreServerHandler method getCredentialSummary.

@Override
public CredentialSummary getCredentialSummary(SummaryType type, String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    try {
        if (type.equals(SummaryType.SSH)) {
            Credential credential = credentialReader.getCredential(gatewayId, tokenId);
            if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) {
                org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
                CredentialSummary sshCredentialSummary = new CredentialSummary();
                sshCredentialSummary.setType(SummaryType.SSH);
                sshCredentialSummary.setUsername(credential1.getPortalUserName());
                sshCredentialSummary.setGatewayId(credential1.getGateway());
                sshCredentialSummary.setPublicKey(new String(credential1.getPublicKey()));
                sshCredentialSummary.setToken(credential1.getToken());
                sshCredentialSummary.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
                sshCredentialSummary.setDescription(credential1.getDescription());
                return sshCredentialSummary;
            } else {
                log.info("Could not find SSH credential for token - " + tokenId + " and " + "gateway id - " + gatewayId);
                return null;
            }
        } else {
            log.info("Summay Type" + type.toString() + " not supported for - " + tokenId + " and " + "gateway id - " + gatewayId);
            return null;
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving SSH credential Summary for token - " + tokenId + " and gateway id - " + gatewayId, e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving SSH credential Summary for token - " + tokenId + " and gateway id - " + gatewayId);
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) org.apache.airavata.model.credential.store(org.apache.airavata.model.credential.store) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 13 with CredentialStoreException

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

the class CommunityUserDAO method deleteCommunityUser.

public void deleteCommunityUser(CommunityUser user, Connection connection) throws CredentialStoreException {
    String sql = "DELETE FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=?";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, user.getGatewayName());
        preparedStatement.setString(2, user.getUserName());
        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 14 with CredentialStoreException

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

the class CommunityUserDAO method getCommunityUserByToken.

public CommunityUser getCommunityUserByToken(String gatewayName, String tokenId, Connection connection) throws CredentialStoreException {
    String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND TOKEN_ID=?";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, gatewayName);
        preparedStatement.setString(2, tokenId);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            String communityUserName = resultSet.getString("COMMUNITY_USER_NAME");
            // 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("token- ").append(tokenId);
        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 15 with CredentialStoreException

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

the class CommunityUserDAO method getCommunityUsers.

public List<CommunityUser> getCommunityUsers(String gatewayName, Connection connection) throws CredentialStoreException {
    List<CommunityUser> userList = new ArrayList<CommunityUser>();
    String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=?";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, gatewayName);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String userName = resultSet.getString("COMMUNITY_USER_NAME");
            // TODO fix typo
            String email = resultSet.getString("COMMUNITY_USER_EMAIL");
            userList.add(new CommunityUser(gatewayName, userName, email));
        }
    } catch (SQLException e) {
        StringBuilder stringBuilder = new StringBuilder("Error retrieving community users for ");
        stringBuilder.append("gateway - ").append(gatewayName);
        log.error(stringBuilder.toString(), e);
        throw new CredentialStoreException(stringBuilder.toString(), e);
    } finally {
        DBUtil.cleanup(preparedStatement);
    }
    return userList;
}
Also used : CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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