use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.
the class SSHCredentialTest method main.
public static void main(String[] args) {
String jdbcURL = "jdbc:mysql://gw85.iu.xsede.org:3306/airavata_gw119";
String jdbcDriver = "com.mysql.jdbc.Driver";
String userName = "gtaDevUser";
String password = "gtaDevPWD";
String gatewayId = "phasta";
String privateKeyPath = "/Users/chathuri/Desktop/ssh_gw111/id_rsa";
String pubKeyPath = "/Users/chathuri/Desktop/ssh_gw111/id_rsa.pub";
try {
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);
System.out.println(token);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ApplicationSettingsException e) {
e.printStackTrace();
} catch (CredentialStoreException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential in project airavata by apache.
the class GatewayRegister method registerSSHKeys.
public void registerSSHKeys() throws Exception {
try {
// write tokens to file
String tokenWriteLocation = properties.getTokenFileLoc();
String fileName = tokenWriteLocation + File.separator + TestFrameworkConstants.CredentialStoreConstants.TOKEN_FILE_NAME;
PrintWriter tokenWriter = new PrintWriter(fileName, "UTF-8");
// credential store related functions are not in the current api, so need to call credential store directly
String jdbcURL = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_URL, PropertyFileType.AIRAVATA_SERVER);
String jdbcDriver = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_DRIVER, PropertyFileType.AIRAVATA_SERVER);
String userName = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_USERNAME, PropertyFileType.AIRAVATA_SERVER);
String password = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_PWD, PropertyFileType.AIRAVATA_SERVER);
String privateKeyPath = properties.getSshPrivateKeyLoc();
String pubKeyPath = properties.getSshPubKeyLoc();
String keyPassword = properties.getSshPassword();
DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver);
SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil);
Gateway gateway = airavata.getGateway(authzToken, properties.getGname());
SSHCredential sshCredential = new SSHCredential();
sshCredential.setGateway(gateway.getGatewayId());
String token = TokenGenerator.generateToken(gateway.getGatewayId(), null);
sshCredential.setToken(token);
sshCredential.setPortalUserName(testUser);
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(keyPassword);
writer.writeCredentials(sshCredential);
tokenMap.put(gateway.getGatewayId(), token);
tokenWriter.println(gateway.getGatewayId() + ":" + token);
tokenWriter.close();
} catch (ClassNotFoundException e) {
logger.error("Unable to find mysql driver", e);
throw new Exception("Unable to find mysql driver", e);
} catch (InstantiationException e) {
logger.error("Error while saving SSH credentials", e);
throw new Exception("Error while saving SSH credentials", e);
} catch (IllegalAccessException e) {
logger.error("Error while saving SSH credentials", e);
throw new Exception("Error while saving SSH credentials", e);
} catch (ApplicationSettingsException e) {
logger.error("Unable to read airavata-client properties", e);
throw new Exception("Unable to read airavata-client properties", e);
} catch (AiravataSystemException e) {
logger.error("Error occured while connecting with airavata client", e);
throw new Exception("Error occured while connecting with airavata client", e);
} catch (InvalidRequestException e) {
logger.error("Error occured while connecting with airavata client", e);
throw new Exception("Error occured while connecting with airavata client", e);
} catch (AiravataClientException e) {
logger.error("Error occured while connecting with airavata client", e);
throw new Exception("Error occured while connecting with airavata client", e);
} catch (TException e) {
logger.error("Error occured while connecting with airavata client", e);
throw new Exception("Error occured while connecting with airavata client", e);
} catch (FileNotFoundException e) {
logger.error("Could not find keys specified in the path", e);
throw new Exception("Could not find keys specified in the path", e);
} catch (CredentialStoreException e) {
logger.error("Error while saving SSH credentials", e);
throw new Exception("Error while saving SSH credentials", e);
} catch (IOException e) {
logger.error("Error while saving SSH credentials", e);
throw new Exception("Error while saving SSH credentials", e);
}
}
Aggregations