Search in sources :

Example 6 with Credential

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

the class CredentialStoreServerHandler method getCertificateCredential.

@Override
public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    try {
        Credential credential = credentialReader.getCredential(gatewayId, tokenId);
        if (credential instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) {
            org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential1 = (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) credential;
            CertificateCredential certificateCredential = new CertificateCredential();
            org.apache.airavata.model.credential.store.CommunityUser communityUser = new org.apache.airavata.model.credential.store.CommunityUser();
            communityUser.setGatewayName(credential1.getCommunityUser().getGatewayName());
            communityUser.setUsername(credential1.getCommunityUser().getUserName());
            communityUser.setUserEmail(credential1.getCommunityUser().getUserEmail());
            certificateCredential.setCommunityUser(communityUser);
            certificateCredential.setToken(credential1.getToken());
            certificateCredential.setLifeTime(credential1.getLifeTime());
            certificateCredential.setNotAfter(credential1.getNotAfter());
            certificateCredential.setNotBefore(credential1.getNotBefore());
            certificateCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
            if (credential1.getPrivateKey() != null) {
                certificateCredential.setPrivateKey(credential1.getPrivateKey().toString());
            }
            certificateCredential.setX509Cert(credential1.getCertificates()[0].toString());
            return certificateCredential;
        } else {
            log.info("Could not find Certificate credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
            return null;
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId, e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId);
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) org.apache.airavata.model.credential.store(org.apache.airavata.model.credential.store) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 7 with Credential

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

the class CredentialStoreServerHandler method getPasswordCredential.

@Override
public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    try {
        Credential credential = credentialReader.getCredential(gatewayId, tokenId);
        if (credential instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) {
            org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential1 = (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential;
            PasswordCredential pwdCredential = new PasswordCredential();
            pwdCredential.setGatewayId(credential1.getGateway());
            pwdCredential.setPortalUserName(credential1.getPortalUserName());
            pwdCredential.setLoginUserName(credential1.getUserName());
            pwdCredential.setPassword(credential1.getPassword());
            pwdCredential.setDescription(credential1.getDescription());
            pwdCredential.setToken(credential1.getToken());
            pwdCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
            return pwdCredential;
        } else {
            log.info("Could not find PWD credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
            return null;
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving PWD credential 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 8 with Credential

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

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

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

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