Search in sources :

Example 1 with Credential

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

the class Factory method getSshKeyAuthentication.

private static SSHKeyAuthentication getSshKeyAuthentication(String gatewayId, String loginUserName, String credentialStoreToken) throws ApplicationSettingsException, IllegalAccessException, InstantiationException, CredentialStoreException, GFacException {
    SSHKeyAuthentication sshKA;
    CredentialReader credentialReader = GFacUtils.getCredentialReader();
    Credential credential = credentialReader.getCredential(gatewayId, credentialStoreToken);
    if (credential instanceof SSHCredential) {
        sshKA = new SSHKeyAuthentication();
        sshKA.setUserName(loginUserName);
        SSHCredential sshCredential = (SSHCredential) credential;
        sshKA.setPublicKey(sshCredential.getPublicKey());
        sshKA.setPrivateKey(sshCredential.getPrivateKey());
        sshKA.setPassphrase(sshCredential.getPassphrase());
        sshKA.setStrictHostKeyChecking("no");
        /*            sshKA.setStrictHostKeyChecking(ServerSettings.getSetting("ssh.strict.hostKey.checking", "no"));
            sshKA.setKnownHostsFilePath(ServerSettings.getSetting("ssh.known.hosts.file", null));
            if (sshKA.getStrictHostKeyChecking().equals("yes") && sshKA.getKnownHostsFilePath() == null) {
                throw new ApplicationSettingsException("If ssh strict hostkey checking property is set to yes, you must " +
                        "provide known host file path");
            }*/
        return sshKA;
    } else {
        String msg = "Provided credential store token is not valid. Please provide the correct credential store token";
        log.error(msg);
        throw new CredentialStoreException("Invalid credential store token:" + credentialStoreToken);
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) SSHKeyAuthentication(org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)

Example 2 with Credential

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

the class CredentialsDAOTest method testGetGatewayCredentials.

@Test
public void testGetGatewayCredentials() throws Exception {
    addTestCredentials();
    Connection connection = getConnection();
    try {
        List<Credential> list = credentialsDAO.getCredentials("gw1", connection);
        Assert.assertEquals(1, list.size());
    } finally {
        connection.close();
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) Connection(java.sql.Connection) Test(org.junit.Test)

Example 3 with Credential

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

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

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

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