Search in sources :

Example 31 with CredentialStoreException

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

the class EmailNotifier method notifyMessage.

public void notifyMessage(NotificationMessage message) throws CredentialStoreException {
    try {
        Email email = new SimpleEmail();
        email.setHostName(this.emailNotifierConfiguration.getEmailServer());
        email.setSmtpPort(this.emailNotifierConfiguration.getEmailServerPort());
        email.setAuthenticator(new DefaultAuthenticator(this.emailNotifierConfiguration.getEmailUserName(), this.emailNotifierConfiguration.getEmailPassword()));
        email.setSSLOnConnect(this.emailNotifierConfiguration.isSslConnect());
        email.setFrom(this.emailNotifierConfiguration.getFromAddress());
        EmailNotificationMessage emailMessage = (EmailNotificationMessage) message;
        email.setSubject(emailMessage.getSubject());
        email.setMsg(emailMessage.getMessage());
        email.addTo(emailMessage.getSenderEmail());
        email.send();
    } catch (EmailException e) {
        log.error("[CredentialStore]Error sending email notification message.");
        throw new CredentialStoreException("Error sending email notification message", e);
    }
}
Also used : CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 32 with CredentialStoreException

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

the class CredentialStoreServerHandler method addCertificateCredential.

@Override
public String addCertificateCredential(CertificateCredential certificateCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    try {
        org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential();
        credential.setPortalUserName(certificateCredential.getCommunityUser().getUsername());
        credential.setCommunityUser(new CommunityUser(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential.getCommunityUser().getUsername(), certificateCredential.getCommunityUser().getUserEmail()));
        String token = TokenGenerator.generateToken(certificateCredential.getCommunityUser().getGatewayName(), null);
        credential.setToken(token);
        Base64 encoder = new Base64(64);
        byte[] decoded = encoder.decode(certificateCredential.getX509Cert().replaceAll(X509Factory.BEGIN_CERT, "").replaceAll(X509Factory.END_CERT, ""));
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate certificate = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(decoded));
        X509Certificate[] certificates = new X509Certificate[1];
        certificates[0] = certificate;
        credential.setCertificates(certificates);
        certificateCredentialWriter.writeCredentials(credential);
        return token;
    } catch (CredentialStoreException e) {
        log.error("Error occurred while saving Certificate Credentials.", e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while saving Certificate Credentials.");
    } catch (Exception e) {
        log.error("Error occurred while converting to X509 certificate.", e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while converting to X509 certificate..");
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) 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) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) SQLException(java.sql.SQLException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 33 with CredentialStoreException

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

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

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

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