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);
}
}
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());
}
}
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);
}
}
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;
}
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);
}
}
Aggregations