Search in sources :

Example 1 with CredentialReader

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

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

the class SecurityUtils method getSecurityContext.

public static UNICORESecurityContext getSecurityContext(ProcessContext processContext) throws GFacException {
    if (processContext.getJobSubmissionProtocol().equals(JobSubmissionProtocol.UNICORE)) {
        // set by the framework
        String credentialStoreToken = processContext.getTokenId();
        RequestData requestData;
        requestData = new RequestData(processContext.getProcessModel().getUserDn());
        requestData.setTokenId(credentialStoreToken);
        CredentialReader credentialReader = null;
        try {
            credentialReader = GFacUtils.getCredentialReader();
            if (credentialReader == null) {
                throw new GFacException("Credential reader returns null");
            }
        } catch (Exception e) {
            throw new GFacException("Error while initializing credential reader");
        }
        return new UNICORESecurityContext(credentialReader, requestData);
    } else {
        throw new GFacException("Only support UNICORE job submissions, invalid job submission protocol " + processContext.getJobSubmissionProtocol().name());
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) RequestData(org.apache.airavata.gfac.core.RequestData) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 3 with CredentialReader

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

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

the class GFACPassiveJobSubmitter method submit.

/**
 * Submit the job to a shared launch.queue accross multiple gfac instances
 *
 * @param experimentId
 * @param processId
 * @param tokenId
 * @return
 * @throws OrchestratorException
 */
public boolean submit(String experimentId, String processId, String tokenId) throws OrchestratorException {
    try {
        String gatewayId = null;
        CredentialReader credentialReader = GFacUtils.getCredentialReader();
        if (credentialReader != null) {
            try {
                gatewayId = credentialReader.getGatewayID(tokenId);
            } catch (Exception e) {
                logger.error(e.getLocalizedMessage());
            }
        }
        if (gatewayId == null || gatewayId.isEmpty()) {
            gatewayId = ServerSettings.getDefaultUserGateway();
        }
        ProcessSubmitEvent processSubmitEvent = new ProcessSubmitEvent(processId, gatewayId, experimentId, tokenId);
        MessageContext messageContext = new MessageContext(processSubmitEvent, MessageType.LAUNCHPROCESS, "LAUNCH" + ".PROCESS-" + UUID.randomUUID().toString(), gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
        publisher.publish(messageContext);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new OrchestratorException(e);
    }
    return true;
}
Also used : CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ProcessSubmitEvent(org.apache.airavata.model.messaging.event.ProcessSubmitEvent) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) MessageContext(org.apache.airavata.messaging.core.MessageContext) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 5 with CredentialReader

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

the class GFACPassiveJobSubmitter method terminate.

/**
 * Submit the experiment the terminate.queue job queue and remove the experiment from shared launch.queue
 * @param experimentId
 * @param processId
 * @return
 * @throws OrchestratorException
 */
public boolean terminate(String experimentId, String processId, String tokenId) throws OrchestratorException {
    String gatewayId = null;
    try {
        CredentialReader credentialReader = GFacUtils.getCredentialReader();
        if (credentialReader != null) {
            try {
                gatewayId = credentialReader.getGatewayID(tokenId);
            } catch (Exception e) {
                logger.error(e.getLocalizedMessage());
            }
        }
        if (gatewayId == null || gatewayId.isEmpty()) {
            gatewayId = ServerSettings.getDefaultUserGateway();
        }
        ProcessTerminateEvent processTerminateEvent = new ProcessTerminateEvent(processId, gatewayId, tokenId);
        MessageContext messageContext = new MessageContext(processTerminateEvent, MessageType.TERMINATEPROCESS, "LAUNCH.TERMINATE-" + UUID.randomUUID().toString(), gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
        publisher.publish(messageContext);
        return true;
    } catch (Exception e) {
        throw new OrchestratorException(e);
    }
}
Also used : CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ProcessTerminateEvent(org.apache.airavata.model.messaging.event.ProcessTerminateEvent) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) MessageContext(org.apache.airavata.messaging.core.MessageContext) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Aggregations

CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)6 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)3 IOException (java.io.IOException)2 InvalidKeyException (java.security.InvalidKeyException)2 AiravataException (org.apache.airavata.common.exception.AiravataException)2 Credential (org.apache.airavata.credential.store.credential.Credential)2 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)2 GFacException (org.apache.airavata.gfac.core.GFacException)2 RequestData (org.apache.airavata.gfac.core.RequestData)2 MessageContext (org.apache.airavata.messaging.core.MessageContext)2 OrchestratorException (org.apache.airavata.orchestrator.core.exception.OrchestratorException)2 ParseException (java.text.ParseException)1 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)1 CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)1 SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)1 EmailNotificationMessage (org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage)1 CredentialReaderImpl (org.apache.airavata.credential.store.store.impl.CredentialReaderImpl)1 UNICORESecurityContext (org.apache.airavata.gfac.bes.security.UNICORESecurityContext)1 SSHKeyAuthentication (org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)1 ProcessSubmitEvent (org.apache.airavata.model.messaging.event.ProcessSubmitEvent)1