You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by am...@apache.org on 2013/12/13 18:43:24 UTC
svn commit: r1550781 - in /airavata/trunk/modules:
airavata-client/src/main/java/org/apache/airavata/client/
airavata-client/src/main/java/org/apache/airavata/client/api/
airavata-client/src/main/java/org/apache/airavata/client/impl/
credential-store/ ...
Author: amilaj
Date: Fri Dec 13 17:43:23 2013
New Revision: 1550781
URL: http://svn.apache.org/r1550781
Log:
Fixing AIRAVATA-952. Thank you Viknes for the contribution
Added:
airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/CredentialStoreManagerImpl.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredential.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredentialGenerator.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/CredentialRegistry.java
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/CredentialStoreResourceClient.java
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/CredentialRegistryResource.java
Modified:
airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java
airavata/trunk/modules/credential-store/pom.xml
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java Fri Dec 13 17:43:23 2013
@@ -33,6 +33,7 @@ import javax.jcr.RepositoryException;
import org.apache.airavata.client.api.AiravataAPI;
import org.apache.airavata.client.api.AiravataManager;
import org.apache.airavata.client.api.ApplicationManager;
+import org.apache.airavata.client.api.CredentialStoreManager;
import org.apache.airavata.client.api.ExecutionManager;
import org.apache.airavata.client.api.ExperimentAdvanceOptions;
import org.apache.airavata.client.api.ProvenanceManager;
@@ -89,6 +90,8 @@ public class AiravataClient extends Obse
private UserManagerImpl userManagerImpl;
// private ExecutionManagerThriftImpl executionManagerImpl;
private ExecutionManager executionManager;
+
+ private CredentialStoreManagerImpl credentialStoreManagerImpl;
private String gateway;
private boolean configCreated = false;
@@ -353,6 +356,13 @@ public class AiravataClient extends Obse
}
return executionManager;
}
+
+ @Override
+ public CredentialStoreManager getCredentialStoreManager() {
+ if(credentialStoreManagerImpl == null)
+ credentialStoreManagerImpl = new CredentialStoreManagerImpl(this);
+ return credentialStoreManagerImpl;
+ }
private ExecutionManager getExecutionManagerObj(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Class<?> cls = Class.forName(className);
@@ -418,4 +428,5 @@ public class AiravataClient extends Obse
List<WorkflowInput> inputs = api.getWorkflowManager().getWorkflowInputs(workflow);
System.out.println(api.getExecutionManager().runExperiment(workflow, inputs,options));
}
+
}
Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java Fri Dec 13 17:43:23 2013
@@ -69,6 +69,12 @@ public interface AiravataAPI {
* @return
*/
public ExecutionManager getExecutionManager();
+
+ /**
+ * Returns the CredentialStoreManager
+ * @return
+ */
+ public CredentialStoreManager getCredentialStoreManager();
/**
* Returns the Current User
Added: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java (added)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.client.api;
+
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+import org.apache.airavata.registry.api.exception.RegistryException;
+
+public interface CredentialStoreManager {
+
+ /**
+ * Checks whether a credential exists in the credential store for given gateway and token
+ * @param String gatewayId
+ * @param String tokenId
+ * @return a boolean (true is credential exists, false if not)
+ * @throws RegistryException
+ */
+ public boolean isCredentialExist(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
+
+ /**
+ * Get the public key for a credential in the credential store for given gateway and token
+ * @param String gatewayId
+ * @param String tokenId
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String getCredentialPublicKey(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
+
+ /**
+ * Creates a new SSH credential for given gateway and token, encrypts it with the given password
+ * and stores it in the credential store
+ * @param String gatewayId
+ * @param String tokenId
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String createCredential(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
+
+ /**
+ * Creates a new SSH credential for given gateway and token, encrypts it with the given password
+ * and stores it in the credential store
+ * @param String gatewayId
+ * @param String tokenId
+ * @param String username
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String createCredential(String gatewayId, String tokenId, String username) throws AiravataAPIInvocationException;
+}
Added: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/CredentialStoreManagerImpl.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/CredentialStoreManagerImpl.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/CredentialStoreManagerImpl.java (added)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/CredentialStoreManagerImpl.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.client.impl;
+
+import org.apache.airavata.client.AiravataClient;
+import org.apache.airavata.client.api.CredentialStoreManager;
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+
+public class CredentialStoreManagerImpl implements CredentialStoreManager{
+
+ private AiravataClient client;
+
+ public CredentialStoreManagerImpl(AiravataClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public boolean isCredentialExist(String gatewayId, String tokenId) throws AiravataAPIInvocationException {
+ if(gatewayId==null || gatewayId.isEmpty() || tokenId == null || tokenId.isEmpty()) {
+ return false;
+ }
+ try {
+ return client.getRegistryClient().isCredentialExist(gatewayId, tokenId);
+ } catch (Exception e) {
+ throw new AiravataAPIInvocationException(e);
+ }
+ }
+
+ @Override
+ public String getCredentialPublicKey(String gatewayId, String tokenId) throws AiravataAPIInvocationException {
+ try {
+ return client.getRegistryClient().getCredentialPublicKey(gatewayId, tokenId);
+ } catch (Exception e) {
+ throw new AiravataAPIInvocationException(e);
+ }
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId) throws AiravataAPIInvocationException {
+ try {
+ return client.getRegistryClient().createCredential(gatewayId, tokenId);
+ } catch (Exception e) {
+ throw new AiravataAPIInvocationException(e);
+ }
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId, String username) throws AiravataAPIInvocationException {
+ try {
+ return client.getRegistryClient().createCredential(gatewayId, tokenId, username);
+ } catch (Exception e) {
+ throw new AiravataAPIInvocationException(e);
+ }
+ }
+
+}
Modified: airavata/trunk/modules/credential-store/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/pom.xml?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/credential-store/pom.xml (original)
+++ airavata/trunk/modules/credential-store/pom.xml Fri Dec 13 17:43:23 2013
@@ -100,6 +100,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.50</version>
+ </dependency>
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredential.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredential.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredential.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredential.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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.credential.impl.ssh;
+
+import org.apache.airavata.credential.store.credential.Credential;
+import java.io.Serializable;
+
+/**
+ * An SSH Credential class which is an extension of Airavata Credential
+ */
+public class SSHCredential extends Credential implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1277154647420198981L;
+
+ private byte[] privatekey;
+ private byte[] publicKey;
+ private String passphrase;
+ private String gateway;
+
+ public byte[] getPrivateKey() {
+ return privatekey;
+ }
+
+ public void setPrivateKey(byte[] privatekey) {
+ this.privatekey = privatekey;
+ }
+
+ public byte[] getPublicKey() {
+ return publicKey;
+ }
+
+ public void setPublicKey(byte[] pubKey) {
+ this.publicKey = pubKey;
+ }
+
+ public String getPassphrase() {
+ return passphrase;
+ }
+
+ public void setPassphrase(String passphrase) {
+ this.passphrase = passphrase;
+ }
+
+ public String getGateway() {
+ return gateway;
+ }
+
+ public void setGateway(String gateway) {
+ this.gateway = gateway;
+ }
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredentialGenerator.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredentialGenerator.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredentialGenerator.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ssh/SSHCredentialGenerator.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,91 @@
+/*
+ *
+ * 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.credential.impl.ssh;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.airavata.credential.store.store.CredentialStoreException;
+import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.KeyPair;
+
+/**
+ * A class which generates an SSH credential
+ */
+public class SSHCredentialGenerator {
+
+ private static Logger logger = LoggerFactory.getLogger(SSHCredentialWriter.class);
+
+ /**
+ *
+ * @return a SSH Credential generated and encrypted using a randomly generated password
+ * @throws CredentialStoreException
+ */
+ public SSHCredential generateCredential(String tokenId) throws CredentialStoreException {
+ JSch jsch=new JSch();
+ try {
+ KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA);
+ File file;
+
+ file = File.createTempFile("id_rsa", "");
+
+ String fileName = file.getAbsolutePath();
+
+ String password = generateRandomString();
+ // We are encrypting the private key with the hash of (tokenId+password).
+ // Any client which wants to use this private key will also generate a hash and then use it to decrypt the key.
+ kpair.writePrivateKey(fileName,generateHash(tokenId,password).getBytes());
+ kpair.writePublicKey(fileName + ".pub" , "");
+ kpair.dispose();
+ byte[] priKey = FileUtils.readFileToByteArray(new File(fileName));
+ byte[] pubKey = FileUtils.readFileToByteArray(new File(fileName + ".pub"));
+ SSHCredential sshCredential = new SSHCredential();
+ sshCredential.setPrivateKey(priKey);
+ sshCredential.setPublicKey(pubKey);
+ sshCredential.setPassphrase(password);
+ return sshCredential;
+ } catch (IOException e) {
+ logger.error("IO Exception when creating SSH credential ",e);
+ throw new CredentialStoreException("Unable to generate SSH Credential", e);
+ } catch (JSchException e) {
+ logger.error("JSch SSH credential creation exception ",e);
+ throw new CredentialStoreException("Unable to generate SSH Credential. JSch exception ", e);
+ }
+ }
+
+ private String generateHash(String tokenId, String password) {
+ // TODO: Hash the password generated and return it
+ return null;
+ }
+
+ // Generate a random alphanumberic string of 16 characters length
+ private String generateRandomString() {
+ return RandomStringUtils.randomAlphanumeric(16);
+ }
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.airavata.common.utils.DBUtil;
+import org.apache.airavata.credential.store.credential.Credential;
+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.CredentialWriter;
+import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Writes SSH credentials to database.
+ */
+public class SSHCredentialWriter implements CredentialWriter {
+
+ private CredentialsDAO credentialsDAO;
+ private DBUtil dbUtil;
+
+ protected static Logger logger = LoggerFactory.getLogger(SSHCredentialWriter.class);
+
+ public SSHCredentialWriter(DBUtil dbUtil) {
+ this.dbUtil = dbUtil;
+ credentialsDAO = new CredentialsDAO();
+ }
+
+ 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);
+ }
+
+ }
+
+}
Modified: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java (original)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java Fri Dec 13 17:43:23 2013
@@ -111,7 +111,7 @@ public class CredentialsDAO extends Pare
preparedStatement.executeUpdate();
} catch (SQLException e) {
- StringBuilder stringBuilder = new StringBuilder("Error persisting community credentials.");
+ StringBuilder stringBuilder = new StringBuilder("Error persisting credentials.");
stringBuilder.append(" gateway - ").append(gatewayId);
stringBuilder.append(" token id - ").append(credential.getToken());
@@ -233,7 +233,7 @@ public class CredentialsDAO extends Pare
}
} catch (SQLException e) {
- StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for community user.");
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for user.");
stringBuilder.append("gateway - ").append(gatewayName);
stringBuilder.append("token id - ").append(tokenId);
Modified: airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml (original)
+++ airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml Fri Dec 13 17:43:23 2013
@@ -64,6 +64,11 @@
<artifactId>airavata-registry-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-credential-store</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!--dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Modified: airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java (original)
+++ airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java Fri Dec 13 17:43:23 2013
@@ -33,10 +33,18 @@ import java.util.Map;
import java.util.regex.Pattern;
import org.apache.airavata.common.exception.AiravataConfigurationException;
+import org.apache.airavata.common.utils.DBUtil;
import org.apache.airavata.common.utils.Version;
import org.apache.airavata.commons.gfac.type.ApplicationDescription;
import org.apache.airavata.commons.gfac.type.HostDescription;
import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential;
+import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredentialGenerator;
+import org.apache.airavata.credential.store.store.CredentialReader;
+import org.apache.airavata.credential.store.store.CredentialStoreException;
+import org.apache.airavata.credential.store.store.CredentialWriter;
+import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl;
+import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter;
import org.apache.airavata.persistance.registry.jpa.JPAResourceAccessor;
import org.apache.airavata.persistance.registry.jpa.Resource;
import org.apache.airavata.persistance.registry.jpa.ResourceType;
@@ -85,6 +93,7 @@ import org.apache.airavata.registry.api.
import org.apache.airavata.registry.api.exception.RegistryAccessorNotFoundException;
import org.apache.airavata.registry.api.exception.RegistryAccessorUndefinedException;
import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegistrySettingsException;
import org.apache.airavata.registry.api.exception.UnimplementedRegistryOperationException;
import org.apache.airavata.registry.api.exception.gateway.DescriptorAlreadyExistsException;
import org.apache.airavata.registry.api.exception.gateway.DescriptorDoesNotExistsException;
@@ -151,6 +160,9 @@ public class AiravataJPARegistry extends
private PublishedWorkflowRegistry publishedWorkflowRegistry;
private UserRegistry userRegistry;
private PasswordCallback callback;
+ private CredentialReader credentialReader;
+ private CredentialWriter credentialWriter;
+ private SSHCredentialGenerator credentialGenerator;
@Override
protected void initialize() throws RegistryException {
@@ -197,6 +209,7 @@ public class AiravataJPARegistry extends
if (!ResourceUtils.isGatewayExist(getGateway().getGatewayName())){
throw new GatewayNotRegisteredException(getGateway().getGatewayName());
}
+
}
static {
@@ -2493,4 +2506,83 @@ public class AiravataJPARegistry extends
}
}
+ @Override
+ public boolean isCredentialExist(String gatewayId, String tokenId)
+ throws RegistryException {
+ credentialReader = new CredentialReaderImpl(getDBConnector());
+ try {
+ SSHCredential credential = (SSHCredential) credentialReader.getCredential(gatewayId, tokenId);
+ if (credential!=null) {
+ return true;
+ }
+ } catch(CredentialStoreException e) {
+ return false;
+ }
+ return false;
+ }
+
+ @Override
+ public String getCredentialPublicKey(String gatewayId, String tokenId)
+ throws RegistryException {
+
+ credentialReader = new CredentialReaderImpl(getDBConnector());
+ try {
+ SSHCredential credential = (SSHCredential) credentialReader.getCredential(gatewayId, tokenId);
+ if (credential!=null) {
+ return new String(credential.getPublicKey());
+ }
+ } catch(CredentialStoreException e) {
+ return null;
+ }
+ return null;
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId)
+ throws RegistryException {
+ return createCredential(gatewayId, tokenId, null);
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId,
+ String username) throws RegistryException {
+ credentialWriter = new SSHCredentialWriter(getDBConnector());
+ credentialGenerator = new SSHCredentialGenerator();
+ try {
+ SSHCredential credential = credentialGenerator.generateCredential(tokenId);
+ if (credential!=null) {
+ credential.setGateway(gatewayId);
+ credential.setToken(tokenId);
+ credential.setPortalUserName(username);
+ credentialWriter.writeCredentials(credential);
+ return new String(credential.getPublicKey());
+ }
+ } catch (CredentialStoreException e) {
+ return null;
+ }
+ return null;
+ }
+
+ private static DBUtil getDBConnector() throws RegistryException{
+ try {
+ String url = RegistrySettings.getSetting("registry.jdbc.url");
+ String driver = RegistrySettings.getSetting("registry.jdbc.driver");
+ String username = RegistrySettings.getSetting("registry.jdbc.user");
+ String password = RegistrySettings.getSetting("registry.jdbc.password");
+ DBUtil dbConnector = new DBUtil(url,username,password,driver);
+ return dbConnector;
+ } catch (InstantiationException e) {
+ logger.error("Error while accesing registrty settings ", e);
+ throw new RegistryException("Error while accesing registrty settings ", e);
+ } catch (IllegalAccessException e) {
+ logger.error("Error while reading registrty settings ", e);
+ throw new RegistryException("Error while accesing registrty settings ", e);
+ } catch (ClassNotFoundException e) {
+ logger.error("Error while reading registrty settings ", e);
+ throw new RegistryException("Error while accesing registrty settings ", e);
+ } catch (RegistrySettingsException e) {
+ logger.error("Error while reading registrty settings ", e);
+ throw new RegistryException("Error while accesing registrty settings ", e);
+ }
+ }
}
Modified: airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java (original)
+++ airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java Fri Dec 13 17:43:23 2013
@@ -27,7 +27,7 @@ import java.net.URI;
import java.util.Observable;
-public abstract class AiravataRegistry2 extends Observable implements DescriptorRegistry, ProjectsRegistry, PublishedWorkflowRegistry, UserWorkflowRegistry, ConfigurationRegistry, ProvenanceRegistry, UserRegistry{
+public abstract class AiravataRegistry2 extends Observable implements DescriptorRegistry, ProjectsRegistry, PublishedWorkflowRegistry, UserWorkflowRegistry, ConfigurationRegistry, ProvenanceRegistry, UserRegistry, CredentialRegistry{
private Gateway gateway;
private AiravataUser user;
Added: airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/CredentialRegistry.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/CredentialRegistry.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/CredentialRegistry.java (added)
+++ airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/CredentialRegistry.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,69 @@
+/*
+ *
+ * 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.registry.api;
+
+import org.apache.airavata.registry.api.exception.RegistryException;
+
+public interface CredentialRegistry extends AiravataSubRegistry{
+
+
+ /**
+ * Checks whether a credential exists in the credential store for given gateway and token
+ * @param String gatewayId
+ * @param String tokenId
+ * @return a boolean (true is credential exists, false if not)
+ * @throws RegistryException
+ */
+
+ public boolean isCredentialExist(String gatewayId, String tokenId) throws RegistryException;
+
+ /**
+ * Get the public key for a credential in the credential store for given gateway and token
+ * @param String gatewayId
+ * @param String tokenId
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String getCredentialPublicKey(String gatewayId, String tokenId) throws RegistryException;
+
+ /**
+ * Creates a new SSH credential for given gateway and token, encrypts it with a randomly
+ * generated password and stores it in the credential store
+ * @param String gatewayId
+ * @param String tokenId
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String createCredential(String gatewayId, String tokenId) throws RegistryException;
+
+ /**
+ * Creates a new SSH credential for given gateway and token, encrypts it with the given password
+ * and stores it in the credential store
+ * @param String gatewayId
+ * @param String tokenId
+ * @param String username
+ * @return String The public key of the credential
+ * @throws RegistryException
+ */
+ public String createCredential(String gatewayId, String tokenId, String username) throws RegistryException;
+
+}
\ No newline at end of file
Added: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/CredentialStoreResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/CredentialStoreResourceClient.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/CredentialStoreResourceClient.java (added)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/CredentialStoreResourceClient.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,226 @@
+/*
+ *
+ * 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.rest.client;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.airavata.registry.api.PasswordCallback;
+import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.rest.utils.BasicAuthHeaderUtil;
+import org.apache.airavata.rest.utils.ClientConstant;
+import org.apache.airavata.rest.utils.CookieManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+public class CredentialStoreResourceClient {
+ private WebResource webResource;
+ private final static Logger logger = LoggerFactory.getLogger(CredentialStoreResourceClient.class);
+ private String userName;
+ private PasswordCallback callback;
+ private String baseURI;
+ private Cookie cookie;
+ private WebResource.Builder builder;
+ private String gateway;
+
+ public CredentialStoreResourceClient(String userName,
+ String gateway,
+ String serviceURL,
+ PasswordCallback callback,
+ Cookie cookie) {
+ this.userName = userName;
+ this.callback = callback;
+ this.baseURI = serviceURL;
+ this.gateway = gateway;
+ this.cookie = cookie;
+ }
+
+ private URI getBaseURI() {
+ logger.debug("Creating Base URI");
+ return UriBuilder.fromUri(baseURI).build();
+ }
+
+ private WebResource getCredentialStoreRegistryBaseResource() {
+ ClientConfig config = new DefaultClientConfig();
+ config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
+ Boolean.TRUE);
+ Client client = Client.create(config);
+ WebResource baseWebResource = client.resource(getBaseURI());
+ webResource = baseWebResource.path(
+ ResourcePathConstants.CredentialResourceConstants.REGISTRY_API_CREDENTIALREGISTRY);
+ return webResource;
+ }
+
+ public boolean isCredentialExist(String gatewayId, String tokenId) {
+ webResource = getCredentialStoreRegistryBaseResource().path(
+ ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL_EXIST);
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("gatewayId", gatewayId);
+ queryParams.add("tokenId", tokenId);
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, queryParams, userName, null, cookie, gateway);
+ ClientResponse response = builder.accept(
+ MediaType.TEXT_PLAIN).get(ClientResponse.class);
+ int status = response.getStatus();
+
+ if (status == ClientConstant.HTTP_OK) {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ String exists = response.getEntity(String.class);
+ if (exists.equalsIgnoreCase("true")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else if (status == ClientConstant.HTTP_UNAUTHORIZED) {
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, queryParams, userName, callback.getPassword(userName), null, gateway);
+ response = builder.accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+ status = response.getStatus();
+ if (status == ClientConstant.HTTP_OK) {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ }
+ String exists = response.getEntity(String.class);
+ if (exists.equalsIgnoreCase("true")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ logger.error(response.getEntity(String.class));
+ throw new RuntimeException("Failed : HTTP error code : "
+ + status);
+ }
+ }
+
+ public String getCredentialPublicKey(String gatewayId, String tokenId) {
+ webResource = getCredentialStoreRegistryBaseResource().path(
+ ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL);
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("gatewayId", gatewayId);
+ queryParams.add("tokenId", tokenId);
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, queryParams, userName, null, cookie, gateway);
+ ClientResponse response = builder.accept(
+ MediaType.TEXT_PLAIN).get(ClientResponse.class);
+ int status = response.getStatus();
+
+ if (status == ClientConstant.HTTP_OK) {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ } else if (status == ClientConstant.HTTP_UNAUTHORIZED) {
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, queryParams, userName, callback.getPassword(userName), null, gateway);
+ response = builder.accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+ status = response.getStatus();
+ if (status == ClientConstant.HTTP_NO_CONTENT) {
+ return null;
+ }
+ if (status != ClientConstant.HTTP_OK) {
+ logger.error(response.getEntity(String.class));
+ throw new RuntimeException("Failed : HTTP error code : "
+ + status);
+ } else {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ }
+ } else if (status == ClientConstant.HTTP_NO_CONTENT) {
+ return null;
+ } else {
+ logger.error(response.getEntity(String.class));
+ throw new RuntimeException("Failed : HTTP error code : "
+ + status);
+ }
+
+ String publicKey = response.getEntity(String.class);
+ return publicKey;
+ }
+
+ public String createCredential(String gatewayId, String tokenId) {
+ return this.createCredential(gatewayId, tokenId, null);
+ }
+
+ public String createCredential(String gatewayId, String tokenId, String username) {
+ webResource = getCredentialStoreRegistryBaseResource().path(
+ ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL);
+ MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
+ formParams.add("gatewayId", gatewayId);
+ formParams.add("tokenId", tokenId);
+ if(username!=null)
+ formParams.add("username", username);
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, null, userName, null, cookie, gateway);
+ ClientResponse response = builder.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+ int status = response.getStatus();
+
+ if (status == ClientConstant.HTTP_OK) {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ } else if (status == ClientConstant.HTTP_UNAUTHORIZED) {
+ builder = BasicAuthHeaderUtil.getBuilder(
+ webResource, null, userName, callback.getPassword(userName), null, gateway);
+ response = builder.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+ status = response.getStatus();
+ if (status != ClientConstant.HTTP_OK) {
+ logger.error(response.getEntity(String.class));
+ throw new RuntimeException("Failed : HTTP error code : "
+ + status);
+ } else {
+ if (response.getCookies().size() > 0) {
+ cookie = response.getCookies().get(0).toCookie();
+ CookieManager.setCookie(cookie);
+ }
+ }
+ } else {
+ logger.error(response.getEntity(String.class));
+ throw new RuntimeException("Failed : HTTP error code : "
+ + status);
+ }
+
+ String publicKey = response.getEntity(String.class);
+ return publicKey;
+ }
+
+}
Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java Fri Dec 13 17:43:23 2013
@@ -61,6 +61,7 @@ public class RegistryClient extends Aira
private ProvenanceResourceClient provenanceResourceClient;
private PublishedWorkflowResourceClient publishedWorkflowResourceClient;
private UserWorkflowResourceClient userWorkflowResourceClient;
+ private CredentialStoreResourceClient credentialStoreResourceClient;
// private CookieManager cookieManager = new CookieManager();
@@ -99,6 +100,10 @@ public class RegistryClient extends Aira
public UserWorkflowResourceClient getUserWorkflowResourceClient() {
return userWorkflowResourceClient;
}
+
+ public CredentialStoreResourceClient getCredentialStoreResourceClient() {
+ return credentialStoreResourceClient;
+ }
@Override
@@ -131,6 +136,9 @@ public class RegistryClient extends Aira
userWorkflowResourceClient =
new UserWorkflowResourceClient(
userName,getGateway().getGatewayName(),serviceURI,callback, CookieManager.getCookie());
+ credentialStoreResourceClient =
+ new CredentialStoreResourceClient(
+ userName,getGateway().getGatewayName(),serviceURI,callback, CookieManager.getCookie());
}
public Object getConfiguration(String key) {
@@ -991,4 +999,29 @@ public class RegistryClient extends Aira
public List<AiravataUser> getUsers() throws RegistryException {
throw new UnimplementedRegistryOperationException();
}
+
+ @Override
+ public boolean isCredentialExist(String gatewayId, String tokenId)
+ throws RegistryException {
+ return getCredentialStoreResourceClient().isCredentialExist(gatewayId,tokenId);
+ }
+
+ @Override
+ public String getCredentialPublicKey(String gatewayId, String tokenId)
+ throws RegistryException {
+ return getCredentialStoreResourceClient().getCredentialPublicKey(gatewayId, tokenId);
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId)
+ throws RegistryException {
+ return getCredentialStoreResourceClient().createCredential(gatewayId, tokenId);
+ }
+
+ @Override
+ public String createCredential(String gatewayId, String tokenId, String username)
+ throws RegistryException {
+ return getCredentialStoreResourceClient().createCredential(gatewayId, tokenId, username);
+ }
+
}
Modified: airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java (original)
+++ airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java Fri Dec 13 17:43:23 2013
@@ -23,7 +23,7 @@ package org.apache.airavata.rest.mapping
public class ResourcePathConstants {
- public static final String BASE_URL = "http://localhost:8080/airavata-registry/api";
+ public static final String BASE_URL = "http://localhost:8080/airavata/services/registry";
public final class ConfigResourcePathConstants {
public static final String CONFIGURATION_REGISTRY_RESOURCE = "/congfigregistry/";
@@ -191,7 +191,14 @@ public class ResourcePathConstants {
public static final String REMOVE_WORKFLOW = "remove/workflow";
}
- public final class UserRegistryConstants {
+ public final class CredentialResourceConstants {
+
+ public static final String REGISTRY_API_CREDENTIALREGISTRY = "/credentialregistry/";
+ public static final String SSH_CREDENTIAL = "ssh/credential";
+ public static final String SSH_CREDENTIAL_EXIST = "ssh/credential/exist";
+ }
+
+ public final class UserResourceConstants {
public static final String REGISTRY_API_USERREGISTRY = "/userregistry/";
public static final String GET_ALL_USERS = "get/user/all";
Added: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/CredentialRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/CredentialRegistryResource.java?rev=1550781&view=auto
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/CredentialRegistryResource.java (added)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/CredentialRegistryResource.java Fri Dec 13 17:43:23 2013
@@ -0,0 +1,152 @@
+/*
+ *
+ * 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.services.registry.rest.resources;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.rest.mappings.utils.RegPoolUtils;
+import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.services.registry.rest.utils.WebAppUtil;
+
+/**
+ * This class provides a REST interface to all the operations related to credential store
+ */
+@Path(ResourcePathConstants.CredentialResourceConstants.REGISTRY_API_CREDENTIALREGISTRY)
+public class CredentialRegistryResource {
+
+ @Context
+ ServletContext context;
+
+ /**
+ * This method will check whether a credential exists for a given tokenId and gateway
+ *
+ * @param String gatewayId
+ * @param String tokenId
+ * @return HTTP response boolean
+ */
+ @GET
+ @Path(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL_EXIST)
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response isCredentialExist(@QueryParam("gatewayId") String gatewayId, @QueryParam("tokenId") String tokenId) {
+ if(gatewayId==null || gatewayId.isEmpty() || tokenId == null || tokenId.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
+ builder.entity("gatewayId or username can't be null");
+ return builder.build();
+ }
+
+ AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
+ try {
+ String publicKey = airavataRegistry.getCredentialPublicKey(gatewayId,tokenId);
+ if (publicKey!=null && publicKey.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ builder.entity("true");
+ return builder.build();
+ } else {
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ builder.entity("false");
+ return builder.build();
+ }
+ } catch (Throwable e) {
+ return WebAppUtil.reportInternalServerError(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL, e);
+ }
+ }
+
+
+ /**
+ * This method will get the public key of the ssh credential exists for a given user and gateway
+ *
+ * @param String gatewayId
+ * @param String tokenId
+ * @return HTTP response - The public key of the credential
+ */
+ @GET
+ @Path(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL)
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response getCredentialPublicKey(@QueryParam("gatewayId") String gatewayId, @QueryParam("tokenId") String tokenId) {
+ if(gatewayId==null || gatewayId.isEmpty() || tokenId == null || tokenId.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
+ builder.entity("gatewayId or username can't be null");
+ return builder.build();
+ }
+
+ AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
+ try {
+ String publicKey = airavataRegistry.getCredentialPublicKey(gatewayId,tokenId);
+ if (publicKey!=null && publicKey.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ builder.entity(publicKey);
+ return builder.build();
+ } else {
+ Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
+ return builder.build();
+ }
+ } catch (Throwable e) {
+ return WebAppUtil.reportInternalServerError(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL, e);
+ }
+ }
+
+
+ /**
+ * This method will create a new ssh credential for a given user, gateway and return the public key of the keypair
+ *
+ * @param String gatewayId
+ * @param String tokenId
+ * @return HTTP response - The public key of the credential
+ */
+ @POST
+ @Path(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL)
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response createCredential(@QueryParam("gatewayId") String gatewayId, @QueryParam("tokenId") String tokenId) {
+ if(gatewayId==null || gatewayId.isEmpty() || tokenId == null || tokenId.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
+ builder.entity("gatewayId or username can't be null");
+ return builder.build();
+ }
+ AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
+ try {
+ String publicKey = airavataRegistry.createCredential(gatewayId, tokenId);
+ if (publicKey!=null && publicKey.isEmpty()) {
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ builder.entity(publicKey);
+ return builder.build();
+ } else {
+ Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
+ builder.entity("Error creating credential");
+ return builder.build();
+ }
+ } catch (Throwable e) {
+ return WebAppUtil.reportInternalServerError(ResourcePathConstants.CredentialResourceConstants.SSH_CREDENTIAL, e);
+ }
+ }
+
+
+
+}
Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java?rev=1550781&r1=1550780&r2=1550781&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java Fri Dec 13 17:43:23 2013
@@ -39,25 +39,21 @@ import org.apache.airavata.rest.mappings
import org.apache.airavata.services.registry.rest.utils.WebAppUtil;
/**
- * This class is a REST interface to all the operations related to user workflows that has been
- * exposed by Airavata Registry API
+ * This class provides a REST interface to all the user management related operations
*/
-@Path(ResourcePathConstants.UserRegistryConstants.REGISTRY_API_USERREGISTRY)
+@Path(ResourcePathConstants.UserResourceConstants.REGISTRY_API_USERREGISTRY)
public class UserRegistryResource {
@Context
ServletContext context;
- /**---------------------------------User Workflow Registry----------------------------------**/
-
/**
- * This method will check whether a given user workflow name already exists
+ * This method gets all users of Airavata present in the registry
*
- * @param workflowName workflow name
- * @return HTTP response
+ * @return HTTP response - List of AiravataUsers
*/
@GET
- @Path(ResourcePathConstants.UserRegistryConstants.GET_ALL_USERS)
+ @Path(ResourcePathConstants.UserResourceConstants.GET_ALL_USERS)
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getAllUsers() {
AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
@@ -74,7 +70,7 @@ public class UserRegistryResource {
return builder.build();
}
} catch (Throwable e) {
- return WebAppUtil.reportInternalServerError(ResourcePathConstants.UserRegistryConstants.GET_ALL_USERS, e);
+ return WebAppUtil.reportInternalServerError(ResourcePathConstants.UserResourceConstants.GET_ALL_USERS, e);
} finally {
if (airavataRegistry != null) {
RegPoolUtils.releaseRegistry(context, airavataRegistry);