Search in sources :

Example 6 with CredentialStoreException

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

the class NotifierBootstrap method run.

@Override
public void run() {
    if (!enabled)
        return;
    // retrieve OA4MP credentials
    try {
        CredentialReader credentialReader = new CredentialReaderImpl(this.dbUtil);
        List<Credential> credentials = credentialReader.getAllCredentials();
        for (Credential credential : credentials) {
            if (credential instanceof CertificateCredential) {
                CertificateCredential certificateCredential = (CertificateCredential) credential;
                Date date = Utility.convertStringToDate(certificateCredential.getNotAfter());
                // gap is 1 days
                date.setDate(date.getDate() + 1);
                Date currentDate = new Date();
                if (currentDate.after(date)) {
                    // Send an email
                    CommunityUser communityUser = certificateCredential.getCommunityUser();
                    String body = String.format(MESSAGE, communityUser.getUserName(), certificateCredential.getNotAfter());
                    String subject = String.format(SUBJECT, communityUser.getUserName());
                    NotificationMessage notificationMessage = new EmailNotificationMessage(subject, communityUser.getUserEmail(), body);
                    this.credentialStoreNotifier.notifyMessage(notificationMessage);
                }
            }
        }
    } catch (ApplicationSettingsException e) {
        log.error("Error configuring email senders.", e);
    } catch (CredentialStoreException e) {
        log.error("Error sending emails about credential expiring.", e);
    } catch (ParseException e) {
        log.error("Error parsing date time when sending emails", e);
    }
}
Also used : EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ParseException(java.text.ParseException)

Example 7 with CredentialStoreException

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

the class CredentialStoreServerHandler method getAllSSHKeysForGateway.

@Override
public Map<String, String> getAllSSHKeysForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    Map<String, String> sshKeyMap = 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.ssh.SSHCredential) {
                    org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
                    byte[] publicKey = sshCredential.getPublicKey();
                    if (publicKey != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) {
                        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 8 with CredentialStoreException

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

the class CredentialStoreServerHandler method getSSHCredential.

@Override
public SSHCredential getSSHCredential(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.ssh.SSHCredential) {
            org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
            SSHCredential sshCredential = new SSHCredential();
            sshCredential.setUsername(credential1.getPortalUserName());
            sshCredential.setGatewayId(credential1.getGateway());
            sshCredential.setPublicKey(new String(credential1.getPublicKey()));
            sshCredential.setPrivateKey(new String(credential1.getPrivateKey()));
            sshCredential.setPassphrase(credential1.getPassphrase());
            sshCredential.setToken(credential1.getToken());
            sshCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
            sshCredential.setDescription(credential1.getDescription());
            sshCredential.setCredentialOwnerType(credential1.getCredentialOwnerType().getDatamodelType());
            return sshCredential;
        } else {
            log.info("Could not find SSH credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
            return null;
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving SSH 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 9 with CredentialStoreException

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

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

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