Repository: airavata Updated Branches: refs/heads/master ac574c942 -> e9468ca5b
adding test class to save ssh credentials Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/e9468ca5 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/e9468ca5 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/e9468ca5 Branch: refs/heads/master Commit: e9468ca5b68083527cb918c2ce195ec0d4f2a8a1 Parents: ac574c9 Author: Chathuri Wimalasena <[email protected]> Authored: Fri Mar 6 12:26:14 2015 -0500 Committer: Chathuri Wimalasena <[email protected]> Committed: Fri Mar 6 12:26:14 2015 -0500 ---------------------------------------------------------------------- .../credential-store-service/pom.xml | 6 ++ .../store/store/impl/db/SSHCredentialTest.java | 92 ++++++++++++++++++++ 2 files changed, 98 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/e9468ca5/modules/credential-store/credential-store-service/pom.xml ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/pom.xml b/modules/credential-store/credential-store-service/pom.xml index 1595ed6..7f9e329 100644 --- a/modules/credential-store/credential-store-service/pom.xml +++ b/modules/credential-store/credential-store-service/pom.xml @@ -80,6 +80,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-server-configuration</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.derby</groupId> <artifactId>derbyclient</artifactId> <version>${derby.version}</version> http://git-wip-us.apache.org/repos/asf/airavata/blob/e9468ca5/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java b/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java new file mode 100644 index 0000000..7f44125 --- /dev/null +++ b/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java @@ -0,0 +1,92 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.credential.store.store.impl.db; + + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.DBUtil; +import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential; +import org.apache.airavata.credential.store.store.CredentialStoreException; +import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; +import org.apache.airavata.credential.store.util.TokenGenerator; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class SSHCredentialTest { + + public static void main(String[] args) { + String jdbcURL = "jdbc:derby://localhost:1527/persistent_data;create=true;user=airavata;password=airavata"; + String jdbcDriver = "org.apache.derby.jdbc.ClientDriver"; + String userName = "airavata"; + String password = "airavata"; + String gatewayId = "default"; + String privateKeyPath = "/Users/chathuri/.ssh/id_dsa"; + String pubKeyPath = "/Users/chathuri/.ssh/id_dsa.pub"; + + try { + AiravataUtils.setExecutionAsServer(); + 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("admin"); + 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(bFilePub); + sshCredential.setPublicKey(bFilePub); + sshCredential.setPassphrase("test"); + 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(); + } + + + } + +}
