Repository: airavata Updated Branches: refs/heads/master b490671ec -> 679771b4e
removing stale clients module Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/679771b4 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/679771b4 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/679771b4 Branch: refs/heads/master Commit: 679771b4e240cb71d481db3546a56dd417e6a6c2 Parents: b490671 Author: scnakandala <[email protected]> Authored: Thu Dec 17 11:28:28 2015 -0500 Committer: scnakandala <[email protected]> Committed: Thu Dec 17 11:28:28 2015 -0500 ---------------------------------------------------------------------- .../java-client-samples/pom.xml | 36 +++ .../client/OAuthAppRegisteringClient.java | 80 ++++++ .../client/OAuthTokenRetrievalClient.java | 124 +++++++++ .../client/secure/client/Properties.java | 47 ++++ .../client/secure/client/SecureClient.java | 255 +++++++++++++++++++ pom.xml | 9 +- samples/java-client/experiment/README | 24 -- samples/java-client/experiment/build.xml | 51 ---- samples/java-client/experiment/pom.xml | 65 ----- .../airavata/api/samples/ExperimentSample.java | 115 --------- samples/java-client/pom.xml | 30 --- samples/java-client/secure-client/pom.xml | 109 -------- .../sample/OAuthAppRegisteringClient.java | 81 ------ .../sample/OAuthTokenRetrievalClient.java | 125 --------- .../airavata/secure/sample/Properties.java | 47 ---- .../airavata/secure/sample/SecureClient.java | 255 ------------------- 16 files changed, 547 insertions(+), 906 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/airavata-api/airavata-client-sdks/java-client-samples/pom.xml ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/pom.xml b/airavata-api/airavata-client-sdks/java-client-samples/pom.xml index 383e057..feee14c 100644 --- a/airavata-api/airavata-client-sdks/java-client-samples/pom.xml +++ b/airavata-api/airavata-client-sdks/java-client-samples/pom.xml @@ -55,6 +55,42 @@ <artifactId>airavata-client-configuration</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-security</artifactId> + <version>${project.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.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.utils</artifactId> + <version>4.2.0</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.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> + <version>4.4</version> + </dependency> + <dependency> + <groupId>com.googlecode.json-simple</groupId> + <artifactId>json-simple</artifactId> + <version>1.1</version> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthAppRegisteringClient.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthAppRegisteringClient.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthAppRegisteringClient.java new file mode 100644 index 0000000..5b3270a --- /dev/null +++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthAppRegisteringClient.java @@ -0,0 +1,80 @@ +/* + * + * 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.secure.client; + +import org.apache.airavata.security.AiravataSecurityException; +import org.apache.airavata.security.util.TrustStoreManager; +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 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); + } + + } + + 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); + //initialize trust store for SSL handshake + TrustStoreManager trustStoreManager = new TrustStoreManager(); + trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH, Properties.TRUST_STORE_PASSWORD); + stub.registerOAuthApplicationData(consumerAppDTO); + // After registration application is retrieve + return stub.getOAuthApplicationDataByAppName(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/679771b4/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthTokenRetrievalClient.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthTokenRetrievalClient.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthTokenRetrievalClient.java new file mode 100644 index 0000000..a37948e --- /dev/null +++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/OAuthTokenRetrievalClient.java @@ -0,0 +1,124 @@ +/* + * + * 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.secure.client; + +import org.apache.airavata.security.AiravataSecurityException; +import org.apache.airavata.security.util.TrustStoreManager; +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.util.ArrayList; +import java.util.List; + +public class OAuthTokenRetrievalClient { + /** + * Retrieve the OAuth Access token via the specified grant type. + * @param consumerId + * @param consumerSecret + * @param userName + * @param password + * @param grantType + * @return + * @throws SecurityException + */ + public String retrieveAccessToken(String consumerId, String consumerSecret, String userName, String password, int grantType) + throws AiravataSecurityException { + + HttpPost postMethod = null; + try { + //initialize trust store to handle SSL handshake with WSO2 IS properly. + TrustStoreManager trustStoreManager = new TrustStoreManager(); + SSLContext sslContext = trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH, + Properties.TRUST_STORE_PASSWORD); + //create https scheme with the trust store + org.apache.http.conn.ssl.SSLSocketFactory sf = new org.apache.http.conn.ssl.SSLSocketFactory(sslContext); + Scheme httpsScheme = new Scheme("https", sf, Properties.authzServerPort); + + HttpClient httpClient = new DefaultHttpClient(); + //set the https scheme in the httpclient + 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>(); + + if (grantType == 1) { + urlParameters.add(new BasicNameValuePair("grant_type", "password")); + urlParameters.add(new BasicNameValuePair("username", userName)); + urlParameters.add(new BasicNameValuePair("password", password)); + + } else if (grantType == 2) { + urlParameters.add(new BasicNameValuePair("grant_type", "client_credentials")); + } + + 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 AiravataSecurityException(e.getMessage(), e); + } catch (UnsupportedEncodingException e) { + throw new AiravataSecurityException(e.getMessage(), e); + } catch (IOException e) { + throw new AiravataSecurityException(e.getMessage(), e); + } catch (ParseException e) { + throw new AiravataSecurityException(e.getMessage(), e); + } finally { + if (postMethod != null) { + postMethod.releaseConnection(); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/Properties.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/Properties.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/Properties.java new file mode 100644 index 0000000..bfff00a --- /dev/null +++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/Properties.java @@ -0,0 +1,47 @@ +/* + * + * 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.secure.client; + +public class Properties { + //Airavata server host, port + public static final String SERVER_HOST = "localhost"; + public static final int SERVER_PORT = 9930; + + //trust store parameters + public static final String TRUST_STORE_PATH = "../../../../../airavata/modules/configuration/server/src/main/resources/client_truststore.jks"; + public static final String TRUST_STORE_PASSWORD = "airavata"; + + 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"; + public static int grantType = 1; + + //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/679771b4/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/SecureClient.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/SecureClient.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/SecureClient.java new file mode 100644 index 0000000..a82ca2b --- /dev/null +++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/secure/client/SecureClient.java @@ -0,0 +1,255 @@ +/* + * + * 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.secure.client; + +import org.apache.airavata.api.Airavata; +import org.apache.airavata.api.client.AiravataClientFactory; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; +import org.apache.airavata.model.error.AiravataClientException; +import org.apache.airavata.model.error.InvalidRequestException; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.security.AiravataSecurityException; +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +public class SecureClient { + private static Logger logger = LoggerFactory.getLogger(SecureClient.class); + + public static void main(String[] args) throws Exception { + Scanner scanner = new Scanner(System.in); + //register client or use existing client + System.out.println(""); + System.out.println("Please select from the following options:"); + System.out.println("1. Register the client as an OAuth application."); + System.out.println("2. Client is already registered. Use the existing credentials."); + String opInput = scanner.next(); + int option = Integer.valueOf(opInput.trim()); + String consumerId = null; + String consumerSecret = null; + if (option == 1) { + //register OAuth application - this happens once during initialization of the gateway. + + /************************Start obtaining input from user*****************************/ + System.out.println(""); + System.out.println("Registering an OAuth application representing the client...."); + System.out.println("Please enter following information as you prefer, or use defaults."); + 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(); + 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(); + 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***************************/ + try { + 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(""); + + } catch (AiravataSecurityException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } else if (option == 2) { + System.out.println(""); + System.out.println("Enter Consumer Id: "); + consumerId = scanner.next().trim(); + System.out.println("Enter Consumer Secret: "); + consumerSecret = scanner.next().trim(); + } + //obtain OAuth access token + + /************************Start obtaining input from user*****************************/ + System.out.println(""); + System.out.println("Please select the preferred grant type: (or press d to use the default option" + Properties.grantType + ")"); + System.out.println("1. Resource Owner Password Credential."); + System.out.println("2. Client Credential."); + + String grantTypeInput = scanner.next().trim(); + int grantType = 0; + if (grantTypeInput.equals("d")) { + grantType = Properties.grantType; + } else { + grantType = Integer.valueOf(grantTypeInput); + } + String userName = null; + String password = null; + if (grantType == 1) { + 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(); + 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(); + if (passwordInput.trim().equals("d")) { + password = Properties.password; + } else { + password = passwordInput.trim(); + } + } else if (grantType == 2) { + System.out.println(""); + System.out.println("Please enter the user name to be passed: "); + String userNameInput = scanner.next(); + userName = userNameInput.trim(); + System.out.println(""); + System.out.println("Obtaining OAuth access token via 'Client Credential' grant type...' grant type...."); + } + + /***************************** Finish obtaining input from user*******************************************/ + try { + //obtain the OAuth token for the specified end user. + String accessToken = new OAuthTokenRetrievalClient().retrieveAccessToken(consumerId, consumerSecret, + userName, password, grantType); + System.out.println(""); + System.out.println("OAuth access token is: " + accessToken); + + //invoke Airavata API by the SecureClient, on behalf of the user. + System.out.println(""); + System.out.println("Invoking Airavata API..."); + System.out.println("Enter the access token to be used: (default:" + accessToken + ", press 'd' to use default value.)"); + String accessTokenInput = scanner.next(); + String acTk = null; + if (accessTokenInput.trim().equals("d")) { + acTk = accessToken; + } else { + acTk = accessTokenInput.trim(); + } + + //obtain as input, the method to be invoked + System.out.println(""); + System.out.println("Enter the number corresponding to the method to be invoked: "); + System.out.println("1. getAPIVersion"); + System.out.println("2. getAllAppModules"); + System.out.println("3. addGateway"); + String methodNumberString = scanner.next(); + int methodNumber = Integer.valueOf(methodNumberString.trim()); + + Airavata.Client client = createAiravataClient(Properties.SERVER_HOST, Properties.SERVER_PORT); + AuthzToken authzToken = new AuthzToken(); + authzToken.setAccessToken(acTk); + Map<String, String> claimsMap = new HashMap<>(); + claimsMap.put("userName", userName); + claimsMap.put("email", "[email protected]"); + authzToken.setClaimsMap(claimsMap); + if (methodNumber == 1) { + + String version = client.getAPIVersion(authzToken); + System.out.println(""); + System.out.println("Airavata API version: " + version); + System.out.println(""); + } else if (methodNumber == 2) { + System.out.println(""); + System.out.println("Enter the gateway id: "); + String gatewayId = scanner.next().trim(); + + List<ApplicationModule> appModules= client.getAllAppModules(authzToken, gatewayId); + System.out.println("Output of getAllAppModuels: "); + for (ApplicationModule appModule : appModules) { + System.out.println(appModule.getAppModuleName()); + } + System.out.println(""); + System.out.println(""); + } else if (methodNumber == 3) { + System.out.println(""); + System.out.println("Enter the gateway id: "); + String gatewayId = scanner.next().trim(); + + Gateway gateway = new Gateway(gatewayId); + gateway.setDomain("airavata.org"); + gateway.setEmailAddress("[email protected]"); + gateway.setGatewayName("airavataGW"); + String output = client.addGateway(authzToken, gateway); + System.out.println(""); + System.out.println("Output of addGateway: " + output); + System.out.println(""); + + } + } catch (InvalidRequestException e) { + e.printStackTrace(); + } catch (TException e) { + e.printStackTrace(); + } catch (AiravataSecurityException e) { + e.printStackTrace(); + } + + } + + public static Airavata.Client createAiravataClient(String serverHost, int serverPort) throws + AiravataClientException { + + //Airavata.Client client = AiravataClientFactory.createAiravataClient(serverHost, serverPort); + Airavata.Client client = AiravataClientFactory.createAiravataSecureClient(serverHost, serverPort, + Properties.TRUST_STORE_PATH, Properties.TRUST_STORE_PASSWORD, 10000); + return client; + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 6eea5e0..c82cc8d 100644 --- a/pom.xml +++ b/pom.xml @@ -355,9 +355,9 @@ <id>scnakandala</id> <name>Supun Nakandala</name> <email>[email protected]</email> - <timezone>+5.5</timezone> - <organization>University of Moratuwa</organization> - <organizationUrl>http://www.mrt.ac.lk/web/</organizationUrl> + <timezone>-5</timezone> + <organization>Indiana University</organization> + <organizationUrl>people.apache.org/~scnakandala</organizationUrl> <roles> <role>committer</role> <role>PMC member</role> @@ -552,14 +552,15 @@ <module>modules/messaging</module> <module>modules/gfac</module> <module>modules/data-manager</module> - <!--<module>modules/workflow-model</module>--> <module>modules/registry</module> <module>modules/security</module> <module>modules/credential-store</module> <module>modules/orchestrator</module> <module>modules/server</module> <module>modules/test-suite</module> + <!-- Deprecated Modules--> <!--<module>modules/integration-tests</module>--> + <!--<module>modules/workflow-model</module>--> <!--<module>modules/workflow</module>--> <!--<module>modules/xbaya-gui</module>--> <module>distribution</module> http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/samples/java-client/experiment/README ---------------------------------------------------------------------- diff --git a/samples/java-client/experiment/README b/samples/java-client/experiment/README deleted file mode 100644 index 3cfa344..0000000 --- a/samples/java-client/experiment/README +++ /dev/null @@ -1,24 +0,0 @@ -Creating an application using Airavata API -========================================== - -This sample demonstrate how to create an Application to run in your localhost. This simply create an echo application to run in your machine with /bin/echo executable. - -Pre Requirements ----------------- - -1. You need to have executable /bin/echo which echo what is given as the argument (Linux or Mac system do have this executable by default) - -2. You have to have registry service running on http://localhost:8080/airavata-registry/api (If you start airavata server distribution without changing any configuration this service will start). - - -Steps to Run ------------- - -1. Unpack Airavata server distribution and start with AIRAVATA_SERVER_HOME/bin/airavata-servers.sh. - -2. go to create-application folder in the airavata-client distribution and run following command. - - ant run - -3. After successful run you can see your application has been created by starting xbaya using airavata xbaya distribution. Connect to the registry service using http://localhost:8080/airavata-registry/api, which is the default setting and you will see the Echo application has registered. - http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/samples/java-client/experiment/build.xml ---------------------------------------------------------------------- diff --git a/samples/java-client/experiment/build.xml b/samples/java-client/experiment/build.xml deleted file mode 100644 index 0061d68..0000000 --- a/samples/java-client/experiment/build.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project name="samples" default="help" basedir="."> - <property name="airavata.home" value="../.."/> - <property name="lib.dir" value="${airavata.home}/lib"/> - <target name="help"> - <echo/> - </target> - <property name="class.dir" value="target/classes"/> - <target name="clean"> - <delete dir="target" quiet="true"/> - <delete dir="${class.dir}" quiet="true"/> - </target> - <target name="run" depends="compile"> - <java classname="org.apache.airavata.api.samples.ExperimentSample" classpathref="javac.classpath" fork="true"/> - </target> - <target name="init"> - <mkdir dir="${class.dir}"/> - <path id="javac.classpath"> - <pathelement path="${class.dir}"/> - <pathelement path="${airavata.home}/lib"/> - <pathelement path="${airavata.home}/conf"/> - <pathelement path="${airavata.home}/samples/create-application/src/main/resources"/> - <fileset dir="${airavata.home}/lib"> - <include name="**/*.jar"/> - </fileset> - </path> - </target> - <target name="compile" depends="init" description="Compile all Java"> - <javac srcdir="src" destdir="${class.dir}" debug="on"> - <classpath refid="javac.classpath"/> - </javac> - </target> -</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/samples/java-client/experiment/pom.xml ---------------------------------------------------------------------- diff --git a/samples/java-client/experiment/pom.xml b/samples/java-client/experiment/pom.xml deleted file mode 100644 index 4f37ccd..0000000 --- a/samples/java-client/experiment/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!--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. --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.airavata</groupId> - <artifactId>samples</artifactId> - <version>0.16-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <modelVersion>4.0.0</modelVersion> - <artifactId>airavata.registry.core.experiment.sample</artifactId> - <name>Samples - Single application experiment</name> - <url>http://airavata.apache.org/</url> - - <dependencies> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>apache-airavata-distribution</artifactId> - <type>pom</type> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-data-models</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-model-utils</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-api-stubs</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.thrift</groupId> - <artifactId>libthrift</artifactId> - <version>${thrift.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/samples/java-client/experiment/src/main/java/org/apache/airavata/api/samples/ExperimentSample.java ---------------------------------------------------------------------- diff --git a/samples/java-client/experiment/src/main/java/org/apache/airavata/api/samples/ExperimentSample.java b/samples/java-client/experiment/src/main/java/org/apache/airavata/api/samples/ExperimentSample.java deleted file mode 100644 index 4722f9e..0000000 --- a/samples/java-client/experiment/src/main/java/org/apache/airavata/api/samples/ExperimentSample.java +++ /dev/null @@ -1,115 +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.api.samples; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.airavata.api.Airavata; -import org.apache.airavata.api.Airavata.Client; -import org.apache.airavata.api.client.AiravataClientFactory; -import org.apache.airavata.client.AiravataAPIFactory; -import org.apache.airavata.client.api.AiravataAPI; -import org.apache.airavata.client.api.exception.AiravataAPIInvocationException; -import org.apache.airavata.client.tools.DocumentCreatorNew; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ClientSettings; -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.ExperimentNotFoundException; -import org.apache.airavata.model.error.InvalidRequestException; -import org.apache.airavata.model.util.ExperimentModelUtil; -import org.apache.airavata.model.workspace.Project; -import org.apache.airavata.model.experiment.ComputationalResourceScheduling; -import org.apache.airavata.model.experiment.DataObjectType; -import org.apache.airavata.model.experiment.DataType; -import org.apache.airavata.model.experiment.ExperimentModel; -import org.apache.airavata.model.experiment.UserConfigurationData; -import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExperimentSample { - private static final Logger log = LoggerFactory.getLogger(ExperimentSample.class); - - protected static AiravataAPI getAiravataAPI() throws AiravataAPIInvocationException { - return AiravataAPIFactory.getAPI("default", "admin"); - } - - protected static Airavata.Client getClient() throws Exception { - String THRIFT_SERVER_HOST = ClientSettings.getSetting("thrift.server.host"); - int THRIFT_SERVER_PORT = Integer.parseInt(ClientSettings.getSetting("thrift.server.port")); - return AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); - - } - public static void main(String[] args) throws Exception { - AiravataAPI airavataAPI = getAiravataAPI(); - DocumentCreatorNew documentCreatorNew = new DocumentCreatorNew(RegistryFactory.getAppCatalog()); - documentCreatorNew.createLocalHostDocs(); - String user = "admin"; - - Project project=new Project(); - project.setName("project1"); - project.setProjectID("project1"); - project.setOwner(user); - Client client = getClient(); - String projectId=client.createProject(project); - System.out.println("Created new project '"+project.getName()+"' with project id "+projectId); - List<DataObjectType> exInputs = new ArrayList<DataObjectType>(); - DataObjectType input = new DataObjectType(); - input.setKey("echo_input"); - input.setType(DataType.STRING); - input.setValue("echo_output=Hello World"); - exInputs.add(input); - - List<DataObjectType> exOut = new ArrayList<DataObjectType>(); - DataObjectType output = new DataObjectType(); - output.setKey("echo_output"); - output.setType(DataType.STDOUT); - output.setValue(""); - exOut.add(output); - - Experiment simpleExperiment = - ExperimentModelUtil.createSimpleExperiment(projectId, user, "echoExperiment", "SimpleEcho0", "SimpleEcho0", exInputs); - simpleExperiment.setExperimentOutputs(exOut); - - ComputationalResourceScheduling scheduling = ExperimentModelUtil.createComputationResourceScheduling("localhost", 1, 1, 1, "normal", 0, 0, 1, "sds128"); - scheduling.setResourceHostId("localhost"); - UserConfigurationData userConfigurationData = new UserConfigurationData(); - userConfigurationData.setAiravataAutoSchedule(false); - userConfigurationData.setOverrideManualScheduledParams(false); - userConfigurationData.setComputationalResourceScheduling(scheduling); - simpleExperiment.setUserConfigurationData(userConfigurationData); - - - - final String expId = client.createExperiment(simpleExperiment); - System.out.println("Experiment Id returned : " + expId); - - - client.launchExperiment(expId,"testToken"); - - System.out.println("Launched successfully"); - - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/samples/java-client/pom.xml ---------------------------------------------------------------------- diff --git a/samples/java-client/pom.xml b/samples/java-client/pom.xml deleted file mode 100644 index f5b59f2..0000000 --- a/samples/java-client/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!--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. --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata</artifactId> - <version>0.16-SNAPSHOT</version> - <relativePath>../../../pom.xml</relativePath> - </parent> - - <modelVersion>4.0.0</modelVersion> - <groupId>org.apache.airavata</groupId> - <artifactId>samples</artifactId> - <name>Samples - Airavata Client Samples</name> - <packaging>pom</packaging> - <url>http://airavata.apache.org/</url> - - <modules> - <!--module>experiment</module--> - <module>secure-client</module> - </modules> -</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/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 deleted file mode 100644 index 8dbc8e8..0000000 --- a/samples/java-client/secure-client/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>samples</artifactId> - <groupId>org.apache.airavata</groupId> - <version>0.16-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>org.apache.airavata</groupId> - <artifactId>secure-client</artifactId> - <version>0.16-SNAPSHOT</version> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-api-stubs</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-model-utils</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-security</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.7.10</version> - </dependency> - <dependency> - <groupId>org.apache.thrift</groupId> - <artifactId>libthrift</artifactId> - <version>${thrift.version}</version> - </dependency> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-model-utils</artifactId> - <version>${project.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.wso2.carbon</groupId> - <artifactId>org.wso2.carbon.utils</artifactId> - <version>4.2.0</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.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> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.7</source> - <target>1.7</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <classpathPrefix>${user.home}/.m2/repository</classpathPrefix> - <classpathLayoutType>repository</classpathLayoutType> - <mainClass>org.apache.airavata.secure.sample.SecureClient</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/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 deleted file mode 100644 index 5292318..0000000 --- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthAppRegisteringClient.java +++ /dev/null @@ -1,81 +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; - -import org.apache.airavata.security.AiravataSecurityException; -import org.apache.airavata.security.util.TrustStoreManager; -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); - } - - } - - 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); - //initialize trust store for SSL handshake - TrustStoreManager trustStoreManager = new TrustStoreManager(); - trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH, Properties.TRUST_STORE_PASSWORD); - stub.registerOAuthApplicationData(consumerAppDTO); - // After registration application is retrieve - return stub.getOAuthApplicationDataByAppName(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/679771b4/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 deleted file mode 100644 index a92a9e6..0000000 --- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/OAuthTokenRetrievalClient.java +++ /dev/null @@ -1,125 +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; - -import org.apache.airavata.security.AiravataSecurityException; -import org.apache.airavata.security.util.TrustStoreManager; -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 { - /** - * Retrieve the OAuth Access token via the specified grant type. - * @param consumerId - * @param consumerSecret - * @param userName - * @param password - * @param grantType - * @return - * @throws SecurityException - */ - public String retrieveAccessToken(String consumerId, String consumerSecret, String userName, String password, int grantType) - throws AiravataSecurityException { - - HttpPost postMethod = null; - try { - //initialize trust store to handle SSL handshake with WSO2 IS properly. - TrustStoreManager trustStoreManager = new TrustStoreManager(); - SSLContext sslContext = trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH, - Properties.TRUST_STORE_PASSWORD); - //create https scheme with the trust store - org.apache.http.conn.ssl.SSLSocketFactory sf = new org.apache.http.conn.ssl.SSLSocketFactory(sslContext); - Scheme httpsScheme = new Scheme("https", sf, Properties.authzServerPort); - - HttpClient httpClient = new DefaultHttpClient(); - //set the https scheme in the httpclient - 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>(); - - if (grantType == 1) { - urlParameters.add(new BasicNameValuePair("grant_type", "password")); - urlParameters.add(new BasicNameValuePair("username", userName)); - urlParameters.add(new BasicNameValuePair("password", password)); - - } else if (grantType == 2) { - urlParameters.add(new BasicNameValuePair("grant_type", "client_credentials")); - } - - 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 AiravataSecurityException(e.getMessage(), e); - } catch (UnsupportedEncodingException e) { - throw new AiravataSecurityException(e.getMessage(), e); - } catch (IOException e) { - throw new AiravataSecurityException(e.getMessage(), e); - } catch (ParseException e) { - throw new AiravataSecurityException(e.getMessage(), e); - } finally { - if (postMethod != null) { - postMethod.releaseConnection(); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/679771b4/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 deleted file mode 100644 index 50e563a..0000000 --- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/Properties.java +++ /dev/null @@ -1,47 +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 Properties { - //Airavata server host, port - public static final String SERVER_HOST = "localhost"; - public static final int SERVER_PORT = 9930; - - //trust store parameters - public static final String TRUST_STORE_PATH = "../../../../../airavata/modules/configuration/server/src/main/resources/client_truststore.jks"; - public static final String TRUST_STORE_PASSWORD = "airavata"; - - 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"; - public static int grantType = 1; - - //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/679771b4/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 deleted file mode 100644 index 992d17d..0000000 --- a/samples/java-client/secure-client/src/main/java/org/apache/airavata/secure/sample/SecureClient.java +++ /dev/null @@ -1,255 +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; - -import org.apache.airavata.api.client.AiravataClientFactory; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; -import org.apache.airavata.model.error.*; -import org.apache.airavata.api.Airavata; -import org.apache.airavata.model.security.AuthzToken; -import org.apache.airavata.model.workspace.Gateway; -import org.apache.airavata.security.AiravataSecurityException; -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.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; - -public class SecureClient { - private static Logger logger = LoggerFactory.getLogger(SecureClient.class); - - public static void main(String[] args) throws Exception { - Scanner scanner = new Scanner(System.in); - //register client or use existing client - System.out.println(""); - System.out.println("Please select from the following options:"); - System.out.println("1. Register the client as an OAuth application."); - System.out.println("2. Client is already registered. Use the existing credentials."); - String opInput = scanner.next(); - int option = Integer.valueOf(opInput.trim()); - String consumerId = null; - String consumerSecret = null; - if (option == 1) { - //register OAuth application - this happens once during initialization of the gateway. - - /************************Start obtaining input from user*****************************/ - System.out.println(""); - System.out.println("Registering an OAuth application representing the client...."); - System.out.println("Please enter following information as you prefer, or use defaults."); - 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(); - 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(); - 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***************************/ - try { - 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(""); - - } catch (AiravataSecurityException e) { - e.printStackTrace(); - throw e; - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } else if (option == 2) { - System.out.println(""); - System.out.println("Enter Consumer Id: "); - consumerId = scanner.next().trim(); - System.out.println("Enter Consumer Secret: "); - consumerSecret = scanner.next().trim(); - } - //obtain OAuth access token - - /************************Start obtaining input from user*****************************/ - System.out.println(""); - System.out.println("Please select the preferred grant type: (or press d to use the default option" + Properties.grantType + ")"); - System.out.println("1. Resource Owner Password Credential."); - System.out.println("2. Client Credential."); - - String grantTypeInput = scanner.next().trim(); - int grantType = 0; - if (grantTypeInput.equals("d")) { - grantType = Properties.grantType; - } else { - grantType = Integer.valueOf(grantTypeInput); - } - String userName = null; - String password = null; - if (grantType == 1) { - 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(); - 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(); - if (passwordInput.trim().equals("d")) { - password = Properties.password; - } else { - password = passwordInput.trim(); - } - } else if (grantType == 2) { - System.out.println(""); - System.out.println("Please enter the user name to be passed: "); - String userNameInput = scanner.next(); - userName = userNameInput.trim(); - System.out.println(""); - System.out.println("Obtaining OAuth access token via 'Client Credential' grant type...' grant type...."); - } - - /***************************** Finish obtaining input from user*******************************************/ - try { - //obtain the OAuth token for the specified end user. - String accessToken = new OAuthTokenRetrievalClient().retrieveAccessToken(consumerId, consumerSecret, - userName, password, grantType); - System.out.println(""); - System.out.println("OAuth access token is: " + accessToken); - - //invoke Airavata API by the SecureClient, on behalf of the user. - System.out.println(""); - System.out.println("Invoking Airavata API..."); - System.out.println("Enter the access token to be used: (default:" + accessToken + ", press 'd' to use default value.)"); - String accessTokenInput = scanner.next(); - String acTk = null; - if (accessTokenInput.trim().equals("d")) { - acTk = accessToken; - } else { - acTk = accessTokenInput.trim(); - } - - //obtain as input, the method to be invoked - System.out.println(""); - System.out.println("Enter the number corresponding to the method to be invoked: "); - System.out.println("1. getAPIVersion"); - System.out.println("2. getAllAppModules"); - System.out.println("3. addGateway"); - String methodNumberString = scanner.next(); - int methodNumber = Integer.valueOf(methodNumberString.trim()); - - Airavata.Client client = createAiravataClient(Properties.SERVER_HOST, Properties.SERVER_PORT); - AuthzToken authzToken = new AuthzToken(); - authzToken.setAccessToken(acTk); - Map<String, String> claimsMap = new HashMap<>(); - claimsMap.put("userName", userName); - claimsMap.put("email", "[email protected]"); - authzToken.setClaimsMap(claimsMap); - if (methodNumber == 1) { - - String version = client.getAPIVersion(authzToken); - System.out.println(""); - System.out.println("Airavata API version: " + version); - System.out.println(""); - } else if (methodNumber == 2) { - System.out.println(""); - System.out.println("Enter the gateway id: "); - String gatewayId = scanner.next().trim(); - - List<ApplicationModule> appModules= client.getAllAppModules(authzToken, gatewayId); - System.out.println("Output of getAllAppModuels: "); - for (ApplicationModule appModule : appModules) { - System.out.println(appModule.getAppModuleName()); - } - System.out.println(""); - System.out.println(""); - } else if (methodNumber == 3) { - System.out.println(""); - System.out.println("Enter the gateway id: "); - String gatewayId = scanner.next().trim(); - - Gateway gateway = new Gateway(gatewayId); - gateway.setDomain("airavata.org"); - gateway.setEmailAddress("[email protected]"); - gateway.setGatewayName("airavataGW"); - String output = client.addGateway(authzToken, gateway); - System.out.println(""); - System.out.println("Output of addGateway: " + output); - System.out.println(""); - - } - } catch (InvalidRequestException e) { - e.printStackTrace(); - } catch (TException e) { - e.printStackTrace(); - } catch (AiravataSecurityException e) { - e.printStackTrace(); - } - - } - - public static Airavata.Client createAiravataClient(String serverHost, int serverPort) throws - AiravataClientException { - - //Airavata.Client client = AiravataClientFactory.createAiravataClient(serverHost, serverPort); - Airavata.Client client = AiravataClientFactory.createAiravataSecureClient(serverHost, serverPort, - Properties.TRUST_STORE_PATH, Properties.TRUST_STORE_PASSWORD, 10000); - return client; - - - } -} \ No newline at end of file
