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