airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [3/8] airavata git commit: completing the POC of securing Airavata API with a secure client sample.
Date Tue, 02 Jun 2015 12:01:22 GMT
completing the POC of securing Airavata API with a secure client sample.


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

Branch: refs/heads/master
Commit: addb4be944acedce8efb089a1e85f86672aaa1c0
Parents: 14a1621
Author: Hasini Gunasinghe <hasi7786@gmail.com>
Authored: Sat May 23 21:38:32 2015 +0530
Committer: Hasini Gunasinghe <hasi7786@gmail.com>
Committed: Sat May 23 21:38:32 2015 +0530

----------------------------------------------------------------------
 airavata-api/airavata-api-server/pom.xml        |  21 +-
 .../server/handler/AiravataServerHandler.java   |  29 ++-
 .../java/org/apache/airavata/api/Airavata.java  | 258 +++++++++++++++++--
 .../client/samples/CreateLaunchBES.java         |   2 +-
 .../client/samples/CreateLaunchExperiment.java  |   2 +-
 .../samples/CreateLaunchExperimentUS3.java      |   2 +-
 .../samples/TestCreateLaunchExperiment.java     |   3 +-
 .../tools/RegisterOGCEUS3Application.java       |   2 +-
 .../tools/RegisterSampleApplications.java       |   2 +-
 .../client/tools/RegisterUS3Application.java    |   2 +-
 .../airavataAPI.thrift                          |   6 +-
 .../airavataDataModel.thrift                    |   1 +
 .../apache/airavata/common/utils/Constants.java |   5 +
 .../airavata/common/utils/ServerSettings.java   |  15 ++
 .../main/resources/airavata-server.properties   |   8 +
 .../apache/airavata/integration/BaseCaseIT.java |   2 +-
 .../WorkflowIntegrationTestBase.java            |   2 +
 samples/java-client/secure-client/pom.xml       |  10 +
 .../sample/AiravataSecurityException.java       |  31 +++
 .../airavata/secure/sample/Constants.java       |  26 --
 .../sample/OAuthAppRegisteringClient.java       | 109 ++++++++
 .../sample/OAuthTokenRetrievalClient.java       |  87 +++++++
 .../airavata/secure/sample/Properties.java      |  42 +++
 .../airavata/secure/sample/SecureClient.java    | 122 +++++++--
 24 files changed, 706 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-api-server/pom.xml
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/pom.xml b/airavata-api/airavata-api-server/pom.xml
index df87344..b4af842 100644
--- a/airavata-api/airavata-api-server/pom.xml
+++ b/airavata-api/airavata-api-server/pom.xml
@@ -81,7 +81,26 @@
             <artifactId>slf4j-log4j12</artifactId>
             <version>${org.slf4j.version}</version>
         </dependency>
-        
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
+            <version>4.2.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.axis2.wso2</groupId>
+            <artifactId>axis2</artifactId>
+            <version>1.6.1.wso2v4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.utils</artifactId>
+            <version>4.2.0</version>
+        </dependency>
     </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/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 fff3810..275feff 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
@@ -27,6 +27,7 @@ import org.apache.aiaravata.application.catalog.data.resources.*;
 import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion;
 import org.apache.airavata.api.Airavata;
 import org.apache.airavata.api.airavataAPIConstants;
+import org.apache.airavata.api.server.security.*;
 import org.apache.airavata.common.exception.AiravataException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.logger.AiravataLogger;
@@ -48,6 +49,7 @@ import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfil
 import org.apache.airavata.model.error.*;
 import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent;
 import org.apache.airavata.model.messaging.event.MessageType;
+import org.apache.airavata.model.security.AuthzToken;
 import org.apache.airavata.model.workspace.Gateway;
 import org.apache.airavata.model.workspace.Project;
 import org.apache.airavata.model.workspace.experiment.*;
@@ -86,7 +88,9 @@ public class AiravataServerHandler implements Airavata.Iface {
      * Query Airavata to fetch the API version
      */
     @Override
-    public String getAPIVersion() throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+    public String getAPIVersion(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        //security check
+        authenticateNAuthorize(authzToken);
         return airavataAPIConstants.AIRAVATA_API_VERSION;
     }
 
@@ -1586,7 +1590,7 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
-       
+
     private OrchestratorService.Client getOrchestratorClient() throws TException{
 		final int serverPort = Integer.parseInt(ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ORCHESTRATOR_SERVER_PORT,"8940"));
         final String serverHost = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ORCHESTRATOR_SERVER_HOST, null);
@@ -2295,7 +2299,7 @@ public class AiravataServerHandler implements Airavata.Iface {
             throw exception;
         }
     }
-    
+
     /**
      * Add a Local Job Submission details to a compute resource
      * App catalog will return a jobSubmissionInterfaceId which will be added to the jobSubmissionInterfaces.
@@ -3422,4 +3426,23 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    public void authenticateNAuthorize(AuthzToken authzToken) throws AuthorizationException {
+        try {
+            boolean isAPISecured = ServerSettings.isAPISecured();
+            if (isAPISecured) {
+
+                AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager();
+                boolean isAuthz = securityManager.isUserAuthenticatedAndAuthorized(authzToken);
+                if (!isAuthz) {
+                    throw new AuthorizationException("User is not authenticated or authorized.");
+                }
+            }
+        } catch (org.apache.airavata.api.server.security.SecurityException e) {
+            throw new AuthorizationException(e.getMessage());
+        } catch (ApplicationSettingsException e) {
+            logger.error("Error in reading API security settings.");
+            throw new AuthorizationException(e.getMessage());
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/Airavata.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/Airavata.java b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/Airavata.java
index dd73b61..6e70510 100644
--- a/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/Airavata.java
+++ b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/Airavata.java
@@ -55,8 +55,10 @@ import org.slf4j.LoggerFactory;
 
     /**
      * Fetch Apache Airavata API version
+     * 
+     * @param authzToken
      */
-    public String getAPIVersion() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.thrift.TException;
+    public String getAPIVersion(org.apache.airavata.model.security.AuthzToken authzToken) throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.airavata.model.error.AuthorizationException, org.apache.thrift.TException;
 
     public String addGateway(org.apache.airavata.model.workspace.Gateway gateway) throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.thrift.TException;
 
@@ -1792,7 +1794,7 @@ import org.slf4j.LoggerFactory;
 
   public interface AsyncIface {
 
-    public void getAPIVersion(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
+    public void getAPIVersion(org.apache.airavata.model.security.AuthzToken authzToken, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
 
     public void addGateway(org.apache.airavata.model.workspace.Gateway gateway, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
 
@@ -2066,19 +2068,20 @@ import org.slf4j.LoggerFactory;
       super(iprot, oprot);
     }
 
-    public String getAPIVersion() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.thrift.TException
+    public String getAPIVersion(org.apache.airavata.model.security.AuthzToken authzToken) throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.airavata.model.error.AuthorizationException, org.apache.thrift.TException
     {
-      send_getAPIVersion();
+      send_getAPIVersion(authzToken);
       return recv_getAPIVersion();
     }
 
-    public void send_getAPIVersion() throws org.apache.thrift.TException
+    public void send_getAPIVersion(org.apache.airavata.model.security.AuthzToken authzToken) throws org.apache.thrift.TException
     {
       getAPIVersion_args args = new getAPIVersion_args();
+      args.setAuthzToken(authzToken);
       sendBase("getAPIVersion", args);
     }
 
-    public String recv_getAPIVersion() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.thrift.TException
+    public String recv_getAPIVersion() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.airavata.model.error.AuthorizationException, org.apache.thrift.TException
     {
       getAPIVersion_result result = new getAPIVersion_result();
       receiveBase(result, "getAPIVersion");
@@ -2094,6 +2097,9 @@ import org.slf4j.LoggerFactory;
       if (result.ase != null) {
         throw result.ase;
       }
+      if (result.ae != null) {
+        throw result.ae;
+      }
       throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getAPIVersion failed: unknown result");
     }
 
@@ -6232,26 +6238,29 @@ import org.slf4j.LoggerFactory;
       super(protocolFactory, clientManager, transport);
     }
 
-    public void getAPIVersion(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
+    public void getAPIVersion(org.apache.airavata.model.security.AuthzToken authzToken, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
       checkReady();
-      getAPIVersion_call method_call = new getAPIVersion_call(resultHandler, this, ___protocolFactory, ___transport);
+      getAPIVersion_call method_call = new getAPIVersion_call(authzToken, resultHandler, this, ___protocolFactory, ___transport);
       this.___currentMethod = method_call;
       ___manager.call(method_call);
     }
 
     public static class getAPIVersion_call extends org.apache.thrift.async.TAsyncMethodCall {
-      public getAPIVersion_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
+      private org.apache.airavata.model.security.AuthzToken authzToken;
+      public getAPIVersion_call(org.apache.airavata.model.security.AuthzToken authzToken, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
         super(client, protocolFactory, transport, resultHandler, false);
+        this.authzToken = authzToken;
       }
 
       public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
         prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getAPIVersion", org.apache.thrift.protocol.TMessageType.CALL, 0));
         getAPIVersion_args args = new getAPIVersion_args();
+        args.setAuthzToken(authzToken);
         args.write(prot);
         prot.writeMessageEnd();
       }
 
-      public String getResult() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.thrift.TException {
+      public String getResult() throws org.apache.airavata.model.error.InvalidRequestException, org.apache.airavata.model.error.AiravataClientException, org.apache.airavata.model.error.AiravataSystemException, org.apache.airavata.model.error.AuthorizationException, org.apache.thrift.TException {
         if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
           throw new IllegalStateException("Method call not finished!");
         }
@@ -10743,13 +10752,15 @@ import org.slf4j.LoggerFactory;
       public getAPIVersion_result getResult(I iface, getAPIVersion_args args) throws org.apache.thrift.TException {
         getAPIVersion_result result = new getAPIVersion_result();
         try {
-          result.success = iface.getAPIVersion();
+          result.success = iface.getAPIVersion(args.authzToken);
         } catch (org.apache.airavata.model.error.InvalidRequestException ire) {
           result.ire = ire;
         } catch (org.apache.airavata.model.error.AiravataClientException ace) {
           result.ace = ace;
         } catch (org.apache.airavata.model.error.AiravataSystemException ase) {
           result.ase = ase;
+        } catch (org.apache.airavata.model.error.AuthorizationException ae) {
+          result.ae = ae;
         }
         return result;
       }
@@ -14494,6 +14505,11 @@ import org.slf4j.LoggerFactory;
                         result.setAseIsSet(true);
                         msg = result;
             }
+            else             if (e instanceof org.apache.airavata.model.error.AuthorizationException) {
+                        result.ae = (org.apache.airavata.model.error.AuthorizationException) e;
+                        result.setAeIsSet(true);
+                        msg = result;
+            }
              else 
             {
               msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
@@ -14515,7 +14531,7 @@ import org.slf4j.LoggerFactory;
       }
 
       public void start(I iface, getAPIVersion_args args, org.apache.thrift.async.AsyncMethodCallback<String> resultHandler) throws TException {
-        iface.getAPIVersion(resultHandler);
+        iface.getAPIVersion(args.authzToken,resultHandler);
       }
     }
 
@@ -22983,6 +22999,7 @@ import org.slf4j.LoggerFactory;
   public static class getAPIVersion_args implements org.apache.thrift.TBase<getAPIVersion_args, getAPIVersion_args._Fields>, java.io.Serializable, Cloneable, Comparable<getAPIVersion_args>   {
     private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getAPIVersion_args");
 
+    private static final org.apache.thrift.protocol.TField AUTHZ_TOKEN_FIELD_DESC = new org.apache.thrift.protocol.TField("authzToken", org.apache.thrift.protocol.TType.STRUCT, (short)1);
 
     private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
     static {
@@ -22990,10 +23007,11 @@ import org.slf4j.LoggerFactory;
       schemes.put(TupleScheme.class, new getAPIVersion_argsTupleSchemeFactory());
     }
 
+    public org.apache.airavata.model.security.AuthzToken authzToken; // required
 
     /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
     @SuppressWarnings("all") public enum _Fields implements org.apache.thrift.TFieldIdEnum {
-;
+      AUTHZ_TOKEN((short)1, "authzToken");
 
       private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
 
@@ -23008,6 +23026,8 @@ import org.slf4j.LoggerFactory;
        */
       public static _Fields findByThriftId(int fieldId) {
         switch(fieldId) {
+          case 1: // AUTHZ_TOKEN
+            return AUTHZ_TOKEN;
           default:
             return null;
         }
@@ -23046,9 +23066,13 @@ import org.slf4j.LoggerFactory;
         return _fieldName;
       }
     }
+
+    // isset id assignments
     public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
     static {
       Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+      tmpMap.put(_Fields.AUTHZ_TOKEN, new org.apache.thrift.meta_data.FieldMetaData("authzToken", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.apache.airavata.model.security.AuthzToken.class)));
       metaDataMap = Collections.unmodifiableMap(tmpMap);
       org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getAPIVersion_args.class, metaDataMap);
     }
@@ -23056,10 +23080,20 @@ import org.slf4j.LoggerFactory;
     public getAPIVersion_args() {
     }
 
+    public getAPIVersion_args(
+      org.apache.airavata.model.security.AuthzToken authzToken)
+    {
+      this();
+      this.authzToken = authzToken;
+    }
+
     /**
      * Performs a deep copy on <i>other</i>.
      */
     public getAPIVersion_args(getAPIVersion_args other) {
+      if (other.isSetAuthzToken()) {
+        this.authzToken = new org.apache.airavata.model.security.AuthzToken(other.authzToken);
+      }
     }
 
     public getAPIVersion_args deepCopy() {
@@ -23068,15 +23102,51 @@ import org.slf4j.LoggerFactory;
 
     @Override
     public void clear() {
+      this.authzToken = null;
+    }
+
+    public org.apache.airavata.model.security.AuthzToken getAuthzToken() {
+      return this.authzToken;
+    }
+
+    public getAPIVersion_args setAuthzToken(org.apache.airavata.model.security.AuthzToken authzToken) {
+      this.authzToken = authzToken;
+      return this;
+    }
+
+    public void unsetAuthzToken() {
+      this.authzToken = null;
+    }
+
+    /** Returns true if field authzToken is set (has been assigned a value) and false otherwise */
+    public boolean isSetAuthzToken() {
+      return this.authzToken != null;
+    }
+
+    public void setAuthzTokenIsSet(boolean value) {
+      if (!value) {
+        this.authzToken = null;
+      }
     }
 
     public void setFieldValue(_Fields field, Object value) {
       switch (field) {
+      case AUTHZ_TOKEN:
+        if (value == null) {
+          unsetAuthzToken();
+        } else {
+          setAuthzToken((org.apache.airavata.model.security.AuthzToken)value);
+        }
+        break;
+
       }
     }
 
     public Object getFieldValue(_Fields field) {
       switch (field) {
+      case AUTHZ_TOKEN:
+        return getAuthzToken();
+
       }
       throw new IllegalStateException();
     }
@@ -23088,6 +23158,8 @@ import org.slf4j.LoggerFactory;
       }
 
       switch (field) {
+      case AUTHZ_TOKEN:
+        return isSetAuthzToken();
       }
       throw new IllegalStateException();
     }
@@ -23105,6 +23177,15 @@ import org.slf4j.LoggerFactory;
       if (that == null)
         return false;
 
+      boolean this_present_authzToken = true && this.isSetAuthzToken();
+      boolean that_present_authzToken = true && that.isSetAuthzToken();
+      if (this_present_authzToken || that_present_authzToken) {
+        if (!(this_present_authzToken && that_present_authzToken))
+          return false;
+        if (!this.authzToken.equals(that.authzToken))
+          return false;
+      }
+
       return true;
     }
 
@@ -23121,6 +23202,16 @@ import org.slf4j.LoggerFactory;
 
       int lastComparison = 0;
 
+      lastComparison = Boolean.valueOf(isSetAuthzToken()).compareTo(other.isSetAuthzToken());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetAuthzToken()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.authzToken, other.authzToken);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
       return 0;
     }
 
@@ -23141,13 +23232,26 @@ import org.slf4j.LoggerFactory;
       StringBuilder sb = new StringBuilder("getAPIVersion_args(");
       boolean first = true;
 
+      sb.append("authzToken:");
+      if (this.authzToken == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.authzToken);
+      }
+      first = false;
       sb.append(")");
       return sb.toString();
     }
 
     public void validate() throws org.apache.thrift.TException {
       // check for required fields
+      if (authzToken == null) {
+        throw new org.apache.thrift.protocol.TProtocolException("Required field 'authzToken' was not present! Struct: " + toString());
+      }
       // check for sub-struct validity
+      if (authzToken != null) {
+        authzToken.validate();
+      }
     }
 
     private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
@@ -23184,6 +23288,15 @@ import org.slf4j.LoggerFactory;
             break;
           }
           switch (schemeField.id) {
+            case 1: // AUTHZ_TOKEN
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.authzToken = new org.apache.airavata.model.security.AuthzToken();
+                struct.authzToken.read(iprot);
+                struct.setAuthzTokenIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
             default:
               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
           }
@@ -23199,6 +23312,11 @@ import org.slf4j.LoggerFactory;
         struct.validate();
 
         oprot.writeStructBegin(STRUCT_DESC);
+        if (struct.authzToken != null) {
+          oprot.writeFieldBegin(AUTHZ_TOKEN_FIELD_DESC);
+          struct.authzToken.write(oprot);
+          oprot.writeFieldEnd();
+        }
         oprot.writeFieldStop();
         oprot.writeStructEnd();
       }
@@ -23216,11 +23334,15 @@ import org.slf4j.LoggerFactory;
       @Override
       public void write(org.apache.thrift.protocol.TProtocol prot, getAPIVersion_args struct) throws org.apache.thrift.TException {
         TTupleProtocol oprot = (TTupleProtocol) prot;
+        struct.authzToken.write(oprot);
       }
 
       @Override
       public void read(org.apache.thrift.protocol.TProtocol prot, getAPIVersion_args struct) throws org.apache.thrift.TException {
         TTupleProtocol iprot = (TTupleProtocol) prot;
+        struct.authzToken = new org.apache.airavata.model.security.AuthzToken();
+        struct.authzToken.read(iprot);
+        struct.setAuthzTokenIsSet(true);
       }
     }
 
@@ -23233,6 +23355,7 @@ import org.slf4j.LoggerFactory;
     private static final org.apache.thrift.protocol.TField IRE_FIELD_DESC = new org.apache.thrift.protocol.TField("ire", org.apache.thrift.protocol.TType.STRUCT, (short)1);
     private static final org.apache.thrift.protocol.TField ACE_FIELD_DESC = new org.apache.thrift.protocol.TField("ace", org.apache.thrift.protocol.TType.STRUCT, (short)2);
     private static final org.apache.thrift.protocol.TField ASE_FIELD_DESC = new org.apache.thrift.protocol.TField("ase", org.apache.thrift.protocol.TType.STRUCT, (short)3);
+    private static final org.apache.thrift.protocol.TField AE_FIELD_DESC = new org.apache.thrift.protocol.TField("ae", org.apache.thrift.protocol.TType.STRUCT, (short)4);
 
     private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
     static {
@@ -23244,13 +23367,15 @@ import org.slf4j.LoggerFactory;
     public org.apache.airavata.model.error.InvalidRequestException ire; // required
     public org.apache.airavata.model.error.AiravataClientException ace; // required
     public org.apache.airavata.model.error.AiravataSystemException ase; // required
+    public org.apache.airavata.model.error.AuthorizationException ae; // required
 
     /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
     @SuppressWarnings("all") public enum _Fields implements org.apache.thrift.TFieldIdEnum {
       SUCCESS((short)0, "success"),
       IRE((short)1, "ire"),
       ACE((short)2, "ace"),
-      ASE((short)3, "ase");
+      ASE((short)3, "ase"),
+      AE((short)4, "ae");
 
       private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
 
@@ -23273,6 +23398,8 @@ import org.slf4j.LoggerFactory;
             return ACE;
           case 3: // ASE
             return ASE;
+          case 4: // AE
+            return AE;
           default:
             return null;
         }
@@ -23324,6 +23451,8 @@ import org.slf4j.LoggerFactory;
           new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
       tmpMap.put(_Fields.ASE, new org.apache.thrift.meta_data.FieldMetaData("ase", org.apache.thrift.TFieldRequirementType.DEFAULT, 
           new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
+      tmpMap.put(_Fields.AE, new org.apache.thrift.meta_data.FieldMetaData("ae", org.apache.thrift.TFieldRequirementType.DEFAULT, 
+          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
       metaDataMap = Collections.unmodifiableMap(tmpMap);
       org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getAPIVersion_result.class, metaDataMap);
     }
@@ -23335,13 +23464,15 @@ import org.slf4j.LoggerFactory;
       String success,
       org.apache.airavata.model.error.InvalidRequestException ire,
       org.apache.airavata.model.error.AiravataClientException ace,
-      org.apache.airavata.model.error.AiravataSystemException ase)
+      org.apache.airavata.model.error.AiravataSystemException ase,
+      org.apache.airavata.model.error.AuthorizationException ae)
     {
       this();
       this.success = success;
       this.ire = ire;
       this.ace = ace;
       this.ase = ase;
+      this.ae = ae;
     }
 
     /**
@@ -23360,6 +23491,9 @@ import org.slf4j.LoggerFactory;
       if (other.isSetAse()) {
         this.ase = new org.apache.airavata.model.error.AiravataSystemException(other.ase);
       }
+      if (other.isSetAe()) {
+        this.ae = new org.apache.airavata.model.error.AuthorizationException(other.ae);
+      }
     }
 
     public getAPIVersion_result deepCopy() {
@@ -23372,6 +23506,7 @@ import org.slf4j.LoggerFactory;
       this.ire = null;
       this.ace = null;
       this.ase = null;
+      this.ae = null;
     }
 
     public String getSuccess() {
@@ -23470,6 +23605,30 @@ import org.slf4j.LoggerFactory;
       }
     }
 
+    public org.apache.airavata.model.error.AuthorizationException getAe() {
+      return this.ae;
+    }
+
+    public getAPIVersion_result setAe(org.apache.airavata.model.error.AuthorizationException ae) {
+      this.ae = ae;
+      return this;
+    }
+
+    public void unsetAe() {
+      this.ae = null;
+    }
+
+    /** Returns true if field ae is set (has been assigned a value) and false otherwise */
+    public boolean isSetAe() {
+      return this.ae != null;
+    }
+
+    public void setAeIsSet(boolean value) {
+      if (!value) {
+        this.ae = null;
+      }
+    }
+
     public void setFieldValue(_Fields field, Object value) {
       switch (field) {
       case SUCCESS:
@@ -23504,6 +23663,14 @@ import org.slf4j.LoggerFactory;
         }
         break;
 
+      case AE:
+        if (value == null) {
+          unsetAe();
+        } else {
+          setAe((org.apache.airavata.model.error.AuthorizationException)value);
+        }
+        break;
+
       }
     }
 
@@ -23521,6 +23688,9 @@ import org.slf4j.LoggerFactory;
       case ASE:
         return getAse();
 
+      case AE:
+        return getAe();
+
       }
       throw new IllegalStateException();
     }
@@ -23540,6 +23710,8 @@ import org.slf4j.LoggerFactory;
         return isSetAce();
       case ASE:
         return isSetAse();
+      case AE:
+        return isSetAe();
       }
       throw new IllegalStateException();
     }
@@ -23593,6 +23765,15 @@ import org.slf4j.LoggerFactory;
           return false;
       }
 
+      boolean this_present_ae = true && this.isSetAe();
+      boolean that_present_ae = true && that.isSetAe();
+      if (this_present_ae || that_present_ae) {
+        if (!(this_present_ae && that_present_ae))
+          return false;
+        if (!this.ae.equals(that.ae))
+          return false;
+      }
+
       return true;
     }
 
@@ -23649,6 +23830,16 @@ import org.slf4j.LoggerFactory;
           return lastComparison;
         }
       }
+      lastComparison = Boolean.valueOf(isSetAe()).compareTo(other.isSetAe());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetAe()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ae, other.ae);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
       return 0;
     }
 
@@ -23700,6 +23891,14 @@ import org.slf4j.LoggerFactory;
         sb.append(this.ase);
       }
       first = false;
+      if (!first) sb.append(", ");
+      sb.append("ae:");
+      if (this.ae == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.ae);
+      }
+      first = false;
       sb.append(")");
       return sb.toString();
     }
@@ -23778,6 +23977,15 @@ import org.slf4j.LoggerFactory;
                 org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
               }
               break;
+            case 4: // AE
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.ae = new org.apache.airavata.model.error.AuthorizationException();
+                struct.ae.read(iprot);
+                struct.setAeIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
             default:
               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
           }
@@ -23813,6 +24021,11 @@ import org.slf4j.LoggerFactory;
           struct.ase.write(oprot);
           oprot.writeFieldEnd();
         }
+        if (struct.ae != null) {
+          oprot.writeFieldBegin(AE_FIELD_DESC);
+          struct.ae.write(oprot);
+          oprot.writeFieldEnd();
+        }
         oprot.writeFieldStop();
         oprot.writeStructEnd();
       }
@@ -23843,7 +24056,10 @@ import org.slf4j.LoggerFactory;
         if (struct.isSetAse()) {
           optionals.set(3);
         }
-        oprot.writeBitSet(optionals, 4);
+        if (struct.isSetAe()) {
+          optionals.set(4);
+        }
+        oprot.writeBitSet(optionals, 5);
         if (struct.isSetSuccess()) {
           oprot.writeString(struct.success);
         }
@@ -23856,12 +24072,15 @@ import org.slf4j.LoggerFactory;
         if (struct.isSetAse()) {
           struct.ase.write(oprot);
         }
+        if (struct.isSetAe()) {
+          struct.ae.write(oprot);
+        }
       }
 
       @Override
       public void read(org.apache.thrift.protocol.TProtocol prot, getAPIVersion_result struct) throws org.apache.thrift.TException {
         TTupleProtocol iprot = (TTupleProtocol) prot;
-        BitSet incoming = iprot.readBitSet(4);
+        BitSet incoming = iprot.readBitSet(5);
         if (incoming.get(0)) {
           struct.success = iprot.readString();
           struct.setSuccessIsSet(true);
@@ -23881,6 +24100,11 @@ import org.slf4j.LoggerFactory;
           struct.ase.read(iprot);
           struct.setAseIsSet(true);
         }
+        if (incoming.get(4)) {
+          struct.ae = new org.apache.airavata.model.error.AuthorizationException();
+          struct.ae.read(iprot);
+          struct.setAeIsSet(true);
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchBES.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchBES.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchBES.java
index 44ebfc7..b4fd0bc 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchBES.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchBES.java
@@ -57,7 +57,7 @@ public class CreateLaunchBES {
 
     public static void main(String[] args) throws Exception {
         airavataClient = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-        System.out.println("API version is " + airavataClient.getAPIVersion());
+        System.out.println("API version is " + airavataClient.getAPIVersion(null));
 //        createGateway();
 //        getGateway("testGatewayId");
 //        registerApplications(); // run this only the first time

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
index ed85238..b78bd3d 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
@@ -86,7 +86,7 @@ public class CreateLaunchExperiment {
 
     public static void main(String[] args) throws Exception {
         airavataClient = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-        System.out.println("API version is " + airavataClient.getAPIVersion());
+        System.out.println("API version is " + airavataClient.getAPIVersion(null));
         Experiment experiment = airavataClient.getExperiment("echotest_fcc7127d-73e9-4e43-bc07-07399a7c5efc");
         long creationTime = experiment.getCreationTime();
         Date date = new Date(creationTime);

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperimentUS3.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperimentUS3.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperimentUS3.java
index bf82ed3..2c4aede 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperimentUS3.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperimentUS3.java
@@ -52,7 +52,7 @@ public class CreateLaunchExperimentUS3 {
     public static void main(String[] args) {
         try {
             final Airavata.Client airavata = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-            System.out.println("API version is " + airavata.getAPIVersion());
+            System.out.println("API version is " + airavata.getAPIVersion(null));
 //            addDescriptors();
 //            final String expId = createUS3ExperimentForTrestles(airavata);
             final String expId = createUS3ExperimentForStampede(airavata);

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
index 8cfbd65..197a363 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
@@ -27,6 +27,7 @@ import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule;
 import org.apache.airavata.model.error.AiravataClientException;
 import org.apache.airavata.model.error.AiravataSystemException;
 import org.apache.airavata.model.error.InvalidRequestException;
+import org.apache.airavata.model.security.AuthzToken;
 import org.apache.airavata.model.workspace.experiment.*;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -48,7 +49,7 @@ public class TestCreateLaunchExperiment {
     public static void main(String[] args) {
         try {
             final Airavata.Client airavata = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-            System.out.println("API version is " + airavata.getAPIVersion());
+            System.out.println("API version is " + airavata.getAPIVersion(null));
             Calendar cal1 = Calendar.getInstance();
             cal1.add(Calendar.DATE, -1);
             Long from = cal1.getTimeInMillis();

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterOGCEUS3Application.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterOGCEUS3Application.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterOGCEUS3Application.java
index 6389e7d..359f183 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterOGCEUS3Application.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterOGCEUS3Application.java
@@ -70,7 +70,7 @@ public class RegisterOGCEUS3Application {
     public static void main(String[] args) {
         try {
 			airavataClient = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-			System.out.println("API version is " + airavataClient.getAPIVersion());
+			System.out.println("API version is " + airavataClient.getAPIVersion(null));
 
 			//Register all compute hosts
 			registerXSEDEHosts();

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterSampleApplications.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterSampleApplications.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterSampleApplications.java
index 3464246..c9fc3d6 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterSampleApplications.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterSampleApplications.java
@@ -140,7 +140,7 @@ public class RegisterSampleApplications {
     public static void main(String[] args) {
         try {
             Airavata.Client airavataClient = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-            System.out.println("API version is " + airavataClient.getAPIVersion());
+            System.out.println("API version is " + airavataClient.getAPIVersion(null));
 
             RegisterSampleApplications registerSampleApplications = new RegisterSampleApplications(airavataClient);
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterUS3Application.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterUS3Application.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterUS3Application.java
index 4e0510c..e00c209 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterUS3Application.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/tools/RegisterUS3Application.java
@@ -70,7 +70,7 @@ public class RegisterUS3Application {
     public static void main(String[] args) {
         try {
 			airavataClient = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT);
-			System.out.println("API version is " + airavataClient.getAPIVersion());
+			System.out.println("API version is " + airavataClient.getAPIVersion(null));
 
 			//Register all compute hosts
 			registerXSEDEHosts();

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/thrift-interface-descriptions/airavataAPI.thrift
----------------------------------------------------------------------
diff --git a/airavata-api/thrift-interface-descriptions/airavataAPI.thrift b/airavata-api/thrift-interface-descriptions/airavataAPI.thrift
index 7f027f5..3d107e1 100644
--- a/airavata-api/thrift-interface-descriptions/airavataAPI.thrift
+++ b/airavata-api/thrift-interface-descriptions/airavataAPI.thrift
@@ -33,6 +33,7 @@ include "applicationDeploymentModel.thrift"
 include "applicationInterfaceModel.thrift"
 include "gatewayResourceProfileModel.thrift"
 include "workflowDataModel.thrift"
+include "securityModel.thrift"
 
 namespace java org.apache.airavata.api
 namespace php Airavata.API
@@ -66,10 +67,11 @@ service Airavata {
   /**
    * Fetch Apache Airavata API version
   */
-  string getAPIVersion()
+  string getAPIVersion(1: required securityModel.AuthzToken authzToken)
         throws (1: airavataErrors.InvalidRequestException ire,
                 2: airavataErrors.AiravataClientException ace,
-                3: airavataErrors.AiravataSystemException ase)
+                3: airavataErrors.AiravataSystemException ase,
+                4: airavataErrors.AuthorizationException ae)
 
   string addGateway(1: required workspaceModel.Gateway gateway)
          throws (1: airavataErrors.InvalidRequestException ire,

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/airavata-api/thrift-interface-descriptions/airavataDataModel.thrift
----------------------------------------------------------------------
diff --git a/airavata-api/thrift-interface-descriptions/airavataDataModel.thrift b/airavata-api/thrift-interface-descriptions/airavataDataModel.thrift
index 0149f23..74de1da 100644
--- a/airavata-api/thrift-interface-descriptions/airavataDataModel.thrift
+++ b/airavata-api/thrift-interface-descriptions/airavataDataModel.thrift
@@ -21,6 +21,7 @@
 include "workspaceModel.thrift"
 include "airavataErrors.thrift"
 include "messagingEvents.thrift"
+include "securityModel.thrift"
 
 namespace java org.apache.airavata.model
 namespace php Airavata.Model

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/Constants.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/Constants.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/Constants.java
index 391a3c6..6855a8e 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/Constants.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/Constants.java
@@ -58,4 +58,9 @@ public final class Constants {
     public static final String STAT = "stat";
     public static final String JOB = "job";
     public static final String ZOOKEEPER_TIMEOUT = "zookeeper.timeout";
+    //API security relates property names
+    public static final String IS_API_SECURED = "api.secured";
+    public static final String REMOTE_OAUTH_SERVER_URL = "remote.oauth.authorization.server";
+    public static final String ADMIN_USERNAME = "admin.user.name";
+    public static final String ADMIN_PASSWORD = "admin.password";
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java
index 57a548c..8370e40 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java
@@ -252,4 +252,19 @@ public class ServerSettings extends ApplicationSettings {
         return Boolean.valueOf(getSetting(ENABLE_EMAIL_BASED_MONITORING, "false"));
     }
 
+    public static boolean isAPISecured() throws ApplicationSettingsException {
+        return Boolean.valueOf(getSetting(Constants.IS_API_SECURED));
+    }
+
+    public static String getRemoteOauthServerUrl() throws ApplicationSettingsException {
+        return getSetting(Constants.REMOTE_OAUTH_SERVER_URL);
+    }
+
+    public static String getAdminUsername() throws ApplicationSettingsException {
+        return getSetting(Constants.ADMIN_USERNAME);
+    }
+
+    public static String getAdminPassword() throws ApplicationSettingsException {
+        return getSetting(Constants.ADMIN_PASSWORD);
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/modules/configuration/server/src/main/resources/airavata-server.properties
----------------------------------------------------------------------
diff --git a/modules/configuration/server/src/main/resources/airavata-server.properties b/modules/configuration/server/src/main/resources/airavata-server.properties
index 27e962e..baf4cd1 100644
--- a/modules/configuration/server/src/main/resources/airavata-server.properties
+++ b/modules/configuration/server/src/main/resources/airavata-server.properties
@@ -274,3 +274,11 @@ gfac-experiments=/gfac-experiments
 gfac-server-name=gfac-node0
 orchestrator-server-name=orch-node0
 airavata-server-name=api-node0
+
+########################################################################
+## API Security Configuration
+########################################################################
+api.secured=true
+remote.oauth.authorization.server=https://localhost:9443/services/
+admin.user.name=admin
+admin.password=admin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
----------------------------------------------------------------------
diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
index d56c2b8..4ce3490 100644
--- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
+++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
@@ -68,7 +68,7 @@ public class BaseCaseIT extends WorkflowIntegrationTestBase {
 
     @Test(groups = {"setupTests"})
     public void testSetup() throws Exception {
-        String version = this.client.getAPIVersion();
+        String version = this.client.getAPIVersion(null);
         Assert.assertNotNull(version);
         log("Airavata version - " + version);
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java
----------------------------------------------------------------------
diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java
index b6528f0..fd42c08 100644
--- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java
+++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java
@@ -23,6 +23,7 @@ package org.apache.airavata.integration;
 
 import org.apache.airavata.api.Airavata;
 import org.apache.airavata.api.client.AiravataClientFactory;
+import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.model.error.*;
 import org.apache.airavata.model.workspace.experiment.Experiment;
@@ -113,6 +114,7 @@ public abstract class WorkflowIntegrationTestBase {
             ServerSettings.setSetting(MYPROXY_USER_NAME, myProxyUserName);
             ServerSettings.setSetting(MYPROXY_PWD, myProxyPassword);
             ServerSettings.setSetting(CERT_LOCATION, certLocation);
+            ServerSettings.setSetting(Constants.IS_API_SECURED, "false");
         }
 
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/pom.xml
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/pom.xml b/samples/java-client/secure-client/pom.xml
index 5197cc7..e4dd9d6 100644
--- a/samples/java-client/secure-client/pom.xml
+++ b/samples/java-client/secure-client/pom.xml
@@ -66,10 +66,20 @@
             <version>4.4</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
             <version>1.7.10</version>
         </dependency>
+        <dependency>
+            <groupId>com.googlecode.json-simple</groupId>
+            <artifactId>json-simple</artifactId>
+            <version>1.1</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/AiravataSecurityException.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/AiravataSecurityException.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/AiravataSecurityException.java
new file mode 100644
index 0000000..2d5e959
--- /dev/null
+++ b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/AiravataSecurityException.java
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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.secure.sample;
+
+public class AiravataSecurityException extends Exception {
+    public AiravataSecurityException(String message) {
+        super(message);
+    }
+
+    public AiravataSecurityException() {
+        super();
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Constants.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Constants.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Constants.java
deleted file mode 100644
index 0c2c518..0000000
--- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Constants.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- *
- * 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.secure.sample;
-
-public class Constants {
-    public static final String SERVER_HOST = "localhost";
-    public static final int SERVER_PORT = 8930;
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthAppRegisteringClient.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthAppRegisteringClient.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthAppRegisteringClient.java
new file mode 100644
index 0000000..f547e0d
--- /dev/null
+++ b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthAppRegisteringClient.java
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.secure.sample;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
+import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import javax.net.ssl.*;
+import java.rmi.RemoteException;
+
+public class OAuthAppRegisteringClient {
+    private OAuthAdminServiceStub stub;
+    private final static Logger logger = LoggerFactory.getLogger(OAuthAppRegisteringClient.class);
+
+    public OAuthAppRegisteringClient(String auhorizationServerURL, String username, String password,
+                                     ConfigurationContext configCtx) throws Exception {
+        String serviceURL = auhorizationServerURL + "OAuthAdminService";
+        try {
+            stub = new OAuthAdminServiceStub(configCtx, serviceURL);
+            CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, stub._getServiceClient());
+        } catch (AxisFault e) {
+            logger.error("Error initializing OAuth2 Client");
+            throw new Exception("Error initializing OAuth Client", e);
+        }
+        //TODO:enable proper SSL handshake
+        try {
+            // Get SSL context
+            SSLContext sc = SSLContext.getInstance("SSL");
+
+            // Create empty HostnameVerifier
+            HostnameVerifier hv = new HostnameVerifier() {
+                public boolean verify(String urlHostName, SSLSession session) {
+                    return true;
+                }
+            };
+            HttpsURLConnection.setDefaultHostnameVerifier(hv);
+
+            // Create a trust manager that does not validate certificate chains
+            TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
+                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+                    return null;
+                }
+
+                public void checkClientTrusted(java.security.cert.X509Certificate[] certs,
+                                               String authType) {
+                }
+
+                public void checkServerTrusted(java.security.cert.X509Certificate[] certs,
+                                               String authType) {
+                }
+            }};
+
+            sc.init(null, trustAllCerts, new java.security.SecureRandom());
+            SSLContext.setDefault(sc);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public OAuthConsumerAppDTO registerApplication(String appName, String consumerId, String consumerSecret)
+            throws AiravataSecurityException {
+
+        try {
+            OAuthConsumerAppDTO consumerAppDTO = new OAuthConsumerAppDTO();
+            consumerAppDTO.setApplicationName(appName);
+            // consumer key and secret is set by the application.
+            consumerAppDTO.setOauthConsumerKey(consumerId);
+            consumerAppDTO.setOauthConsumerSecret(consumerSecret);
+            //consumerAppDTO.setUsername(adminUserName);
+            stub.registerOAuthApplicationData(consumerAppDTO);
+            // After registration application is retrieve
+            return stub.getOAuthApplicationDataByAppName(Properties.appName);
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+            throw new AiravataSecurityException("Error in registering the OAuth application.");
+        } catch (RemoteException e) {
+            e.printStackTrace();
+            throw new AiravataSecurityException("Error in registering the OAuth application.");
+        } catch (OAuthAdminServiceException e) {
+            e.printStackTrace();
+            throw new AiravataSecurityException("Error in registering the OAuth application.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthTokenRetrievalClient.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthTokenRetrievalClient.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthTokenRetrievalClient.java
new file mode 100644
index 0000000..10ac3db
--- /dev/null
+++ b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthTokenRetrievalClient.java
@@ -0,0 +1,87 @@
+package org.apache.airavata.secure.sample;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import javax.net.ssl.SSLContext;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OAuthTokenRetrievalClient {
+
+    public String retrieveAccessToken(String consumerId, String consumerSecret, String userName, String password)
+            throws SecurityException {
+
+        HttpPost postMethod = null;
+        try {
+            //TODO:handle SSL handshake properly.
+            org.apache.http.conn.ssl.SSLSocketFactory sf = new org.apache.http.conn.ssl.SSLSocketFactory(
+                    SSLContext.getDefault());
+            sf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            Scheme httpsScheme = new Scheme("https", sf, Properties.authzServerPort);
+            HttpClient httpClient = new DefaultHttpClient();
+            httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);
+
+            postMethod = new HttpPost(Properties.oauthTokenEndPointURL);
+            //build the HTTP request with relevant params for resource owner credential grant type
+            String authInfo = consumerId + ":" + consumerSecret;
+            String authHeader = new String(Base64.encodeBase64(authInfo.getBytes()));
+
+            postMethod.setHeader("Content-Type", "application/x-www-form-urlencoded");
+            postMethod.setHeader("Authorization", "Basic " + authHeader);
+
+            List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
+            urlParameters.add(new BasicNameValuePair("grant_type", "password"));
+            urlParameters.add(new BasicNameValuePair("username", userName));
+            urlParameters.add(new BasicNameValuePair("password", password));
+
+            postMethod.setEntity(new UrlEncodedFormEntity(urlParameters));
+
+            HttpResponse response = httpClient.execute(postMethod);
+
+            BufferedReader rd = new BufferedReader(
+                    new InputStreamReader(response.getEntity().getContent()));
+
+            StringBuilder result = new StringBuilder();
+            String line = "";
+            while ((line = rd.readLine()) != null) {
+                result.append(line);
+            }
+
+            JSONParser parser = new JSONParser();
+            JSONObject jsonObject = (JSONObject) parser.parse(result.toString());
+            return (String) jsonObject.get("access_token");
+        } catch (ClientProtocolException e) {
+            throw new SecurityException(e.getMessage());
+        } catch (UnsupportedEncodingException e) {
+            throw new SecurityException(e.getMessage());
+        } catch (IOException e) {
+            throw new SecurityException(e.getMessage());
+        } catch (NoSuchAlgorithmException e) {
+            throw new SecurityException(e.getMessage());
+        } catch (ParseException e) {
+            throw new SecurityException(e.getMessage());
+        } finally {
+            if (postMethod != null) {
+                postMethod.releaseConnection();
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Properties.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Properties.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Properties.java
new file mode 100644
index 0000000..33661cc
--- /dev/null
+++ b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Properties.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.secure.sample;
+
+public class Properties {
+    //Airavata server host, port
+    public static final String SERVER_HOST = "localhost";
+    public static final int SERVER_PORT = 8930;
+
+    public static String oauthAuthzServerURL = "https://localhost:9443/services/";
+    public static String oauthTokenEndPointURL = "https://localhost:9443/oauth2/token";
+    public static int authzServerPort = 9443;
+    public static String adminUserName = "admin";
+    public static String adminPassword = "admin";
+
+    //OAuth consumer app properties
+    public static String appName = "AiravataGWP1";
+    public static String consumerID = "AiravataGW1";
+    public static String consumerSecret = "AiravataGW1234";
+
+    //resource owner credential
+    public static String userName = "admin";
+    public static String password = "admin";
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/addb4be9/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java
----------------------------------------------------------------------
diff --git a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java
index f94f2ff..56c6992 100644
--- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java
+++ b/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java
@@ -22,21 +22,111 @@ package org.apache.airavata.secure.sample;
 
 import org.apache.airavata.api.client.AiravataClientFactory;
 import org.apache.airavata.model.error.AiravataClientConnectException;
-import org.apache.airavata.model.error.AiravataClientException;
-import org.apache.airavata.model.error.AiravataSystemException;
-import org.apache.airavata.model.error.InvalidRequestException;
 import org.apache.airavata.api.Airavata;
+import org.apache.airavata.model.security.AuthzToken;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
+
+import java.util.Scanner;
 
 public class SecureClient {
     private static Logger logger = LoggerFactory.getLogger(SecureClient.class);
 
-    public static void main(String[] args) throws AiravataClientConnectException, TException {
-        Airavata.Client client = createAiravataClient(Constants.SERVER_HOST, Constants.SERVER_PORT);
-        String version = client.getAPIVersion();
+    public static void main(String[] args) throws Exception {
+        //register OAuth application - this happens once during initialization of the gateway.
+
+        /************************Start obtaining input from user*****************************/
+        System.out.println("");
+        System.out.println("Registering OAuth application representing the client....");
+        System.out.println("Please enter following information as you prefer, or use defaults.");
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("OAuth application name: (default:" + Properties.appName +
+                ", press 'd' to use default value.)");
+        String appNameInput = scanner.next();
+        String appName = null;
+        if (appNameInput.trim().equals("d")) {
+            appName = Properties.appName;
+        } else {
+            appName = appNameInput.trim();
+        }
+
+        System.out.println("Consumer Id: (default:" + Properties.consumerID + ", press 'd' to use default value.)");
+        String consumerIdInput = scanner.next();
+        String consumerId = null;
+        if (consumerIdInput.trim().equals("d")) {
+            consumerId = Properties.consumerID;
+        } else {
+            consumerId = consumerIdInput.trim();
+        }
+
+        System.out.println("Consumer Secret: (default:" + Properties.consumerSecret +
+                ", press 'd' to use default value.)");
+        String consumerSecInput = scanner.next();
+        String consumerSecret = null;
+        if (consumerSecInput.trim().equals("d")) {
+            consumerSecret = Properties.consumerSecret;
+        } else {
+            consumerSecret = consumerSecInput.trim();
+        }
+        /***************************** Finish obtaining input from user*******************************************/
+
+        /*********************** Perform registration of the client as an OAuth app***************************/
+        ConfigurationContext configContext =
+                ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
+        OAuthAppRegisteringClient authAppRegisteringClient = new OAuthAppRegisteringClient(
+                Properties.oauthAuthzServerURL, Properties.adminUserName, Properties.adminPassword, configContext);
+        OAuthConsumerAppDTO appDTO = authAppRegisteringClient.registerApplication(appName, consumerId, consumerSecret);
+        /********************* Complete registering the client ***********************************************/
+        System.out.println("");
+        System.out.println("Registered OAuth app successfully. Following is app's details:");
+        System.out.println("App Name: " + appDTO.getApplicationName());
+        System.out.println("Consumer ID: " + appDTO.getOauthConsumerKey());
+        System.out.println("Consumer Secret: " + appDTO.getOauthConsumerSecret());
+        System.out.println("");
+        //obtain OAuth access token
+
+        /************************Start obtaining input from user*****************************/
+        System.out.println("Obtaining OAuth access token via 'Resource Owner Password' grant type....");
+        System.out.println("Please enter following information as you prefer, or use defaults.");
+        System.out.println("End user's name: (default:" + Properties.userName +
+                ", press 'd' to use default value.)");
+        String userNameInput = scanner.next();
+        String userName = null;
+        if (userNameInput.trim().equals("d")) {
+            userName = Properties.userName;
+        } else {
+            userName = userNameInput.trim();
+        }
+
+        System.out.println("End user's password: (default:" + Properties.password + ", press 'd' to use default value.)");
+        String passwordInput = scanner.next();
+        String password = null;
+        if (passwordInput.trim().equals("d")) {
+            password = Properties.password;
+        } else {
+            password = passwordInput.trim();
+        }
+        /***************************** Finish obtaining input from user*******************************************/
+
+        //obtain the OAuth token for the specified end user.
+        String accessToken = new OAuthTokenRetrievalClient().retrieveAccessToken(consumerId, consumerSecret, userName,
+                password);
+        System.out.println("OAuth access token obtained for the user: " + userName + " is: " + accessToken);
+        System.out.println("");
+
+        //invoke Airavata API by the SecureClient, on behalf of the user.
+        System.out.println("Invoking Airavata API...");
+        Airavata.Client client = createAiravataClient(Properties.SERVER_HOST, Properties.SERVER_PORT);
+        AuthzToken authzToken = new AuthzToken();
+        authzToken.setAccessToken(accessToken);
+        String version = client.getAPIVersion(authzToken);
         System.out.println("Airavata API version: " + version);
+        System.out.println("");
     }
 
     public static Airavata.Client createAiravataClient(String serverHost, int serverPort) throws
@@ -50,24 +140,4 @@ public class SecureClient {
             throw e;
         }
     }
-
-    public static String getAPIVersion(Airavata.Client client) throws TException {
-        try {
-            return client.getAPIVersion();
-        } catch (InvalidRequestException e) {
-            logger.error("Error in retrieving API version.");
-            throw new InvalidRequestException(e);
-        } catch (AiravataClientException e) {
-            logger.error("Error in retrieving API version.");
-            throw new AiravataClientException(e);
-        } catch (AiravataSystemException e) {
-            logger.error("Error in retrieving API version.");
-            throw new AiravataSystemException(e);
-        } catch (TException e) {
-            logger.error("Error in retrieving API version.");
-            throw new TException(e);
-        }
-    }
-
-
 }


Mime
View raw message