You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/05/01 20:28:53 UTC

[10/10] airavata git commit: adding capability to store and retreive PWD credentials in the Airavata API

adding capability to store and retreive PWD credentials in the Airavata API


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/3bb7f493
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/3bb7f493
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/3bb7f493

Branch: refs/heads/develop
Commit: 3bb7f493dc9ab3b71177c1e1ac9b14c25e406519
Parents: 63825ce
Author: scnakandala <su...@gmail.com>
Authored: Sun May 1 14:28:36 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Sun May 1 14:28:36 2016 -0400

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |    70 +
 .../java/org/apache/airavata/api/Airavata.java  | 14469 +++++++++++------
 .../main/resources/lib/airavata/Airavata.cpp    |  4505 +++--
 .../src/main/resources/lib/airavata/Airavata.h  |   492 +
 .../lib/airavata/Airavata_server.skeleton.cpp   |    38 +
 .../resources/lib/Airavata/API/Airavata.php     |  7181 ++++----
 .../lib/apache/airavata/api/Airavata-remote     |    21 +
 .../lib/apache/airavata/api/Airavata.py         |  1447 +-
 .../impl/password/PasswordCredential.java       |    11 +-
 .../server/CredentialStoreServerHandler.java    |    72 +-
 .../store/cpi/CredentialStoreService.java       |  2249 ++-
 .../store/datamodel/CertificateCredential.java  |     2 +-
 .../store/datamodel/CommunityUser.java          |     2 +-
 .../store/datamodel/PasswordCredential.java     |   254 +-
 .../store/datamodel/SSHCredential.java          |     2 +-
 .../exception/CredentialStoreException.java     |     2 +-
 .../apache/airavata/gfac/cpi/GfacService.java   |     2 +-
 .../orchestrator/cpi/OrchestratorService.java   |     2 +-
 .../airavata-apis/airavata_api.thrift           |    41 +
 .../component-cpis/credential-store-cpi.thrift  |     3 +
 .../credential_store_data_models.thrift         |    17 +-
 21 files changed, 20911 insertions(+), 9971 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/3bb7f493/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index a8b3375..4b6d2f3 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -31,6 +31,7 @@ import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.credential.store.client.CredentialStoreClientFactory;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
 import org.apache.airavata.credential.store.datamodel.SSHCredential;
+import org.apache.airavata.credential.store.datamodel.PasswordCredential;
 import org.apache.airavata.credential.store.exception.CredentialStoreException;
 import org.apache.airavata.messaging.core.MessageContext;
 import org.apache.airavata.messaging.core.Publisher;
@@ -405,6 +406,40 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Generate and Register Username PWD Pair with Airavata Credential Store.
+     *
+     * @param authzToken
+     * @param gatewayId  The identifier for the requested Gateway.
+     * @param userName   The User for which the credential should be registered. For community accounts, this user is the name of the
+     *                   community user name. For computational resources, this user name need not be the same user name on resoruces.
+     * @param password
+     * @return airavataCredStoreToken
+     * An SSH Key pair is generated and stored in the credential store and associated with users or community account
+     * belonging to a Gateway.
+     */
+    @Override
+    public String registerPwdCredential(AuthzToken authzToken, String gatewayId, String userName, String password) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        try {
+            if (csClient == null){
+                csClient = getCredentialStoreServiceClient();
+            }
+            PasswordCredential pwdCredential = new PasswordCredential();
+            pwdCredential.setUsername(userName);
+            pwdCredential.setPassword(password);
+            pwdCredential.setGatewayId(gatewayId);
+            String key = csClient.addPasswordCredential(pwdCredential);
+            logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + userName);
+            return key;
+        }catch (Exception e){
+            logger.error("Error occurred while registering PWD Credential", e);
+            AiravataSystemException exception = new AiravataSystemException();
+            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+            exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
     @Override
     @SecurityCheck
     public String getSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
@@ -461,6 +496,24 @@ public class AiravataServerHandler implements Airavata.Iface {
     }
 
     @Override
+    public Map<String, String> getAllGatewayPWDCredentials(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        try {
+            if (csClient == null){
+                csClient = getCredentialStoreServiceClient();
+            }
+            Map<String, String> allPwdCredentials = csClient.getAllPWDCredentialsForGateway(gatewayId);
+            logger.debug("Airavata retrieved all PWD Credentials for gateway Id : " + gatewayId);
+            return allPwdCredentials;
+        }catch (Exception e){
+            logger.error("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId , e);
+            AiravataSystemException exception = new AiravataSystemException();
+            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+            exception.setMessage("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId + ". More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
     public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         try {
             if (csClient == null){
@@ -477,6 +530,23 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    @Override
+    public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        try {
+            if (csClient == null){
+                csClient = getCredentialStoreServiceClient();
+            }
+            logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken);
+            return csClient.deletePWDCredential(airavataCredStoreToken, gatewayId);
+        }catch (Exception e){
+            logger.error("Error occurred while deleting PWD credential", e);
+            AiravataSystemException exception = new AiravataSystemException();
+            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+            exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
     /**
      * Create a Project
      *