Search in sources :

Example 16 with Credential

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

Example 17 with Credential

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

the class CredentialStoreServerHandler method getAllPWDCredentialsForGateway.

@Override
public Map<String, String> getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    Map<String, String> pwdCredMap = new HashMap<>();
    try {
        List<Credential> allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId);
        if (allCredentials != null && !allCredentials.isEmpty()) {
            for (Credential credential : allCredentials) {
                if (credential instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) {
                    org.apache.airavata.credential.store.credential.impl.password.PasswordCredential pwdCredential = (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential;
                    pwdCredMap.put(pwdCredential.getToken(), pwdCredential.getDescription() == null ? "" : pwdCredential.getDescription());
                }
            }
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving credentials", e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials");
    }
    return pwdCredMap;
}
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 18 with Credential

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

the class CredentialStoreServerHandler method getAllSSHKeysForUser.

@Override
public Map<String, String> getAllSSHKeysForUser(String username) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    Map<String, String> sshKeyMap = new HashMap<>();
    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();
                    if (portalUserName != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) {
                        if (portalUserName.equals(username)) {
                            byte[] publicKey = sshCredential.getPublicKey();
                            if (publicKey != null) {
                                sshKeyMap.put(sshCredential.getToken(), new String(publicKey));
                            }
                        }
                    }
                }
            }
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving credentials", e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials");
    }
    return sshKeyMap;
}
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 19 with Credential

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

the class CredentialStoreServerHandler method getAllCredentialSummaryForGateway.

@Override
public List<CredentialSummary> getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) 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.getAllCredentialsPerGateway(gatewayId);
            if (allCredentials != null && !allCredentials.isEmpty()) {
                for (Credential credential : allCredentials) {
                    if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential && credential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) {
                        org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
                        CredentialSummary sshCredentialSummary = new CredentialSummary();
                        sshCredentialSummary.setType(SummaryType.SSH);
                        sshCredentialSummary.setToken(sshCredential.getToken());
                        sshCredentialSummary.setUsername(sshCredential.getPortalUserName());
                        sshCredentialSummary.setGatewayId(sshCredential.getGateway());
                        sshCredentialSummary.setDescription(sshCredential.getDescription());
                        sshCredentialSummary.setPublicKey(new String(sshCredential.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 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)

Aggregations

Credential (org.apache.airavata.credential.store.credential.Credential)19 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)14 org.apache.airavata.model.credential.store (org.apache.airavata.model.credential.store)9 CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)5 X509Credential (eu.emi.security.authn.x509.X509Credential)2 KeyAndCertCredential (eu.emi.security.authn.x509.impl.KeyAndCertCredential)2 X509Certificate (java.security.cert.X509Certificate)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)2 SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)2 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)2 ParseException (java.text.ParseException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 EmailNotificationMessage (org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage)1 CredentialReaderImpl (org.apache.airavata.credential.store.store.impl.CredentialReaderImpl)1 SSHKeyAuthentication (org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)1 Test (org.junit.Test)1