use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential 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.impl.ssh.SSHCredential in project airavata by apache.
the class SSHSummaryTest method testSSHSummary.
// @Test Change the properties in ServerProperties file and give the correct path to run the test
public void testSSHSummary() throws Exception {
try {
String jdbcURL = ServerSettings.getCredentialStoreDBURL();
String jdbcDriver = ServerSettings.getCredentialStoreDBDriver();
String userName = ServerSettings.getCredentialStoreDBUser();
String password = ServerSettings.getCredentialStoreDBPassword();
String gatewayId = "phasta";
String privateKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata";
String pubKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata.pub";
DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver);
SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil);
SSHCredential sshCredential = new SSHCredential();
sshCredential.setGateway(gatewayId);
String token = TokenGenerator.generateToken(gatewayId, null);
sshCredential.setToken(token);
sshCredential.setPortalUserName("phasta");
sshCredential.setDescription("dummy creds for testing");
FileInputStream privateKeyStream = new FileInputStream(privateKeyPath);
File filePri = new File(privateKeyPath);
byte[] bFilePri = new byte[(int) filePri.length()];
privateKeyStream.read(bFilePri);
FileInputStream pubKeyStream = new FileInputStream(pubKeyPath);
File filePub = new File(pubKeyPath);
byte[] bFilePub = new byte[(int) filePub.length()];
pubKeyStream.read(bFilePub);
privateKeyStream.close();
pubKeyStream.close();
sshCredential.setPrivateKey(bFilePri);
sshCredential.setPublicKey(bFilePub);
sshCredential.setPassphrase("ultrascan");
writer.writeCredentials(sshCredential);
Assert.assertEquals(token, sshCredential.getToken());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.
the class TokenizedSSHAuthInfo method getDefaultCredentials.
/**
* Gets the default proxy certificate.
*
* @return Default my proxy credentials.
* @throws GFacException If an error occurred while retrieving credentials.
* @throws org.apache.airavata.common.exception.ApplicationSettingsException
*/
public SSHCredential getDefaultCredentials() throws GFacException, ApplicationSettingsException, IOException {
Properties configurationProperties = ServerSettings.getProperties();
String sshUserName = configurationProperties.getProperty(GFacConstants.SSH_USER_NAME);
this.getRequestData().setRequestUser(sshUserName);
this.privateKeyFile = configurationProperties.getProperty(GFacConstants.SSH_PRIVATE_KEY);
this.publicKeyFile = configurationProperties.getProperty(GFacConstants.SSH_PUBLIC_KEY);
this.passPhrase = configurationProperties.getProperty(GFacConstants.SSH_PRIVATE_KEY_PASS);
this.getRequestData().setRequestUser(sshUserName);
return new SSHCredential(IOUtil.readToByteArray(new File(this.privateKeyFile)), IOUtil.readToByteArray(new File(this.publicKeyFile)), this.passPhrase, requestData.getGatewayId(), sshUserName);
}
use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.
the class TokenizedSSHAuthInfo method getCredentialsFromStore.
/**
* Reads the credentials from credential store.
*
* @return If token is found in the credential store, will return a valid credential. Else returns null.
* @throws Exception If an error occurred while retrieving credentials.
*/
public SSHCredential getCredentialsFromStore() throws Exception {
if (getCredentialReader() == null) {
credentialReader = GFacUtils.getCredentialReader();
if (credentialReader == null) {
return null;
}
}
Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
if (credential instanceof SSHCredential) {
SSHCredential credential1 = (SSHCredential) credential;
this.publicKeyFile = writeFileToDisk(credential1.getPublicKey());
this.privateKeyFile = writeFileToDisk(credential1.getPrivateKey());
this.passPhrase = credential1.getPassphrase();
System.out.println(this.publicKeyFile);
System.out.println(this.privateKeyFile);
System.out.println(this.passPhrase);
this.getRequestData().setRequestUser(credential1.getPortalUserName());
return credential1;
} else {
log.info("Could not find SSH credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
}
return null;
}
use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.
the class SSHCredentialWriter method writeCredentials.
public void writeCredentials(Credential credential) throws CredentialStoreException {
SSHCredential sshCredential = (SSHCredential) credential;
Connection connection = null;
try {
connection = dbUtil.getConnection();
// First delete existing credentials
credentialsDAO.deleteCredentials(sshCredential.getGateway(), sshCredential.getToken(), connection);
// Add the new certificate
credentialsDAO.addCredentials(sshCredential.getGateway(), credential, connection);
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException e1) {
logger.error("Unable to rollback transaction", e1);
}
}
throw new CredentialStoreException("Unable to retrieve database connection.", e);
} finally {
DBUtil.cleanup(connection);
}
}
Aggregations