diff --git a/README.md b/README.md index 9951c27aea0..d0d77bd3118 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ JDK 1.8. ## Supported OnPrem vCenter Releases: -vCenter 6.0, 6.5, 6.7, 6.7U1, 6.7U2, 6.7U3 +vCenter 6.0, 6.5, 6.7, 6.7U1, 6.7U2, 6.7U3, 7.0 Please refer to the notes in each sample for detailed compatibility information. @@ -88,9 +88,9 @@ When running the samples, parameters can be provided either on the command line, Use a command like the following to display usage information for a particular sample. ```` bash -$java -ea -cp target/vsphere-samples-7.0.0.jar vmware.samples.vcenter.vm.list.ListVMs +$java -ea -cp target/vsphere-samples-7.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs -java -cp target/vsphere-samples-7.0.0.jar vmware.samples.vcenter.vm.list.ListVMs [--config-file ] +java -cp target/vsphere-samples-7.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs [--config-file ] --server --username --password --cluster [--truststorepath ] [--truststorepassword ] [--cleardata] [--skip-server-verification] @@ -114,17 +114,17 @@ Sample Options: Use a command like the following to run a sample using only command line parameters: ```` bash -$java -ea -cp target/vsphere-samples-7.0.0.jar vmware.samples.vcenter.vm.list.ListVMs --server servername --username administrator@vsphere.local --password password --skip-server-verification +$java -ea -cp target/vsphere-samples-7.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs --server servername --username administrator@vsphere.local --password password --skip-server-verification ```` Use a command like the following to run a sample using only a configuration file: ```` bash -$java -ea -cp target/vsphere-samples-7.0.0.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties +$java -ea -cp target/vsphere-samples-7.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties ```` Use the following command to run the sample using a combination of configuration file and command line parameters: ```` bash -$java -ea -cp target/vsphere-samples-7.0.0.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties --server servername +$java -ea -cp target/vsphere-samples-7.0.0.1.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties --server servername ```` ### Importing the samples to eclipse @@ -150,12 +150,12 @@ This will import a basic sample class to your package, which you can then custom ## API Documentation ### vSphere API Documentation +* [VMware vSphere APIs 7.0.0.1 (latest version)](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/7.0.0.1/vsphereautomation-client-sdk/index.html). * [VMware Cloud on AWS vSphere (latest version)](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/cloud/vsphereautomation-client-sdk/index.html). -* [VMware vSphere APIs 6.7.3 (latest version)](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.7.3/vsphereautomation-client-sdk/index.html). - -* Previous releases: [6.5](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.5.0/vsphereautomation-client-sdk/index.html), [6.7.1](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.7.1/vsphereautomation-client-sdk/index.html) +* Previous releases: [6.7.3](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.7.3/vsphereautomation-client-sdk/index.html), +[6.7.1](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.7.1/vsphereautomation-client-sdk/index.html) ### VMware Cloud on AWS API Documentation @@ -229,8 +229,8 @@ Sample Exchange can be allowed to access your GitHub resources, by way of a link Board members are volunteers from the SDK community and VMware staff members, board members are not held responsible for any issues which may occur from running of samples from this repository. Members: -* Kunal Singh (VMware) -* Jobin Jeorge (VMware) +* Sumit Agrawal (VMware) +* Shyla Srinivas (VMware) ### Approval of Additions Items added to the repository, including items from the Board members, require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository. @@ -240,5 +240,6 @@ Items added to the repository, including items from the Board members, require 2 * [vSphere Automation SDK Overview](http://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.vapi.progguide.doc/GUID-AF73991C-FC1C-47DF-8362-184B6544CFDE.html) * [VMware Code](https://code.vmware.com/home) * [VMware Developer Community](https://communities.vmware.com/community/vmtn/developer) -* VMware vSphere [Java API Reference documentation](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/6.7.3/vsphereautomation-client-sdk/index.html). +* VMware vSphere [Java API Reference documentation](https://vmware.github.io/vsphere-automation-sdk-java/vsphere/7.0.0.1/vsphereautomation-client-sdk/index.html). + * [VMware Java forum](https://code.vmware.com/forums/7508/vsphere-automation-sdk-for-java) diff --git a/lib/oidc-oauth2-sdk-0.0.1.jar b/lib/oidc-oauth2-sdk-0.0.1.jar new file mode 100644 index 00000000000..90a474072c9 Binary files /dev/null and b/lib/oidc-oauth2-sdk-0.0.1.jar differ diff --git a/lib/vapi-authentication-2.14.0-javadoc.jar b/lib/vapi-authentication-2.14.0-javadoc.jar deleted file mode 100644 index f74358f675c..00000000000 Binary files a/lib/vapi-authentication-2.14.0-javadoc.jar and /dev/null differ diff --git a/lib/vapi-authentication-2.15.0-javadoc.jar b/lib/vapi-authentication-2.15.0-javadoc.jar new file mode 100644 index 00000000000..e94b978ec9a Binary files /dev/null and b/lib/vapi-authentication-2.15.0-javadoc.jar differ diff --git a/lib/vapi-authentication-2.14.0.jar b/lib/vapi-authentication-2.15.0.jar similarity index 81% rename from lib/vapi-authentication-2.14.0.jar rename to lib/vapi-authentication-2.15.0.jar index b48ef764674..189f9a44aea 100644 Binary files a/lib/vapi-authentication-2.14.0.jar and b/lib/vapi-authentication-2.15.0.jar differ diff --git a/lib/vapi-runtime-2.14.0-javadoc.jar b/lib/vapi-runtime-2.14.0-javadoc.jar deleted file mode 100644 index 8e4ca8f3a1f..00000000000 Binary files a/lib/vapi-runtime-2.14.0-javadoc.jar and /dev/null differ diff --git a/lib/vapi-runtime-2.15.0-javadoc.jar b/lib/vapi-runtime-2.15.0-javadoc.jar new file mode 100644 index 00000000000..f1c36d18a73 Binary files /dev/null and b/lib/vapi-runtime-2.15.0-javadoc.jar differ diff --git a/lib/vapi-runtime-2.14.0.jar b/lib/vapi-runtime-2.15.0.jar similarity index 75% rename from lib/vapi-runtime-2.14.0.jar rename to lib/vapi-runtime-2.15.0.jar index 40a31cb2ce8..51441fda74a 100644 Binary files a/lib/vapi-runtime-2.14.0.jar and b/lib/vapi-runtime-2.15.0.jar differ diff --git a/lib/vapi-samltoken-2.14.0-javadoc.jar b/lib/vapi-samltoken-2.14.0-javadoc.jar deleted file mode 100644 index efe42311857..00000000000 Binary files a/lib/vapi-samltoken-2.14.0-javadoc.jar and /dev/null differ diff --git a/lib/vapi-samltoken-2.15.0-javadoc.jar b/lib/vapi-samltoken-2.15.0-javadoc.jar new file mode 100644 index 00000000000..177fa0ab9c0 Binary files /dev/null and b/lib/vapi-samltoken-2.15.0-javadoc.jar differ diff --git a/lib/vapi-samltoken-2.14.0.jar b/lib/vapi-samltoken-2.15.0.jar similarity index 85% rename from lib/vapi-samltoken-2.14.0.jar rename to lib/vapi-samltoken-2.15.0.jar index 5968c6fd362..8d3bd13c45a 100644 Binary files a/lib/vapi-samltoken-2.14.0.jar and b/lib/vapi-samltoken-2.15.0.jar differ diff --git a/lib/vapi-vmc-sdk-2.14.0.jar b/lib/vapi-vmc-sdk-2.14.0.jar deleted file mode 100644 index 09d1cd7a0a5..00000000000 Binary files a/lib/vapi-vmc-sdk-2.14.0.jar and /dev/null differ diff --git a/lib/vapi-vmc-sdk-2.15.0.jar b/lib/vapi-vmc-sdk-2.15.0.jar new file mode 100644 index 00000000000..3ebd1788448 Binary files /dev/null and b/lib/vapi-vmc-sdk-2.15.0.jar differ diff --git a/lib/vsphereautomation-client-sdk-3.2.0-javadoc.jar b/lib/vsphereautomation-client-sdk-3.3.0-javadoc.jar similarity index 60% rename from lib/vsphereautomation-client-sdk-3.2.0-javadoc.jar rename to lib/vsphereautomation-client-sdk-3.3.0-javadoc.jar index f877261b917..77ad21ba150 100644 Binary files a/lib/vsphereautomation-client-sdk-3.2.0-javadoc.jar and b/lib/vsphereautomation-client-sdk-3.3.0-javadoc.jar differ diff --git a/lib/vsphereautomation-client-sdk-3.2.0.jar b/lib/vsphereautomation-client-sdk-3.3.0.jar similarity index 67% rename from lib/vsphereautomation-client-sdk-3.2.0.jar rename to lib/vsphereautomation-client-sdk-3.3.0.jar index 8c24424986e..532f748131a 100644 Binary files a/lib/vsphereautomation-client-sdk-3.2.0.jar and b/lib/vsphereautomation-client-sdk-3.3.0.jar differ diff --git a/lib/vsphereautomation-lookupservice-1.0.0-javadoc.jar b/lib/vsphereautomation-lookupservice-1.0.0-javadoc.jar index 54cf517fe0c..2665a764c70 100644 Binary files a/lib/vsphereautomation-lookupservice-1.0.0-javadoc.jar and b/lib/vsphereautomation-lookupservice-1.0.0-javadoc.jar differ diff --git a/lib/vsphereautomation-lookupservice-1.0.0.jar b/lib/vsphereautomation-lookupservice-1.0.0.jar index ddae19b8c47..bfd644a2584 100644 Binary files a/lib/vsphereautomation-lookupservice-1.0.0.jar and b/lib/vsphereautomation-lookupservice-1.0.0.jar differ diff --git a/pom.xml b/pom.xml index 27447121a0e..2f8fdc9702c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.vmware vsphere-samples-nodeps - 7.0.0 + 7.0.0.1 jar samples @@ -12,7 +12,7 @@ UTF-8 - 2.14.0 + 2.15.0 1.7.12 4.5.10 4.1.4 @@ -24,12 +24,13 @@ 1.9.4 1.0.0 6.7.3 - 3.2.0 + 3.3.0 1.24.0 2.5.1.0.1.15419398 2.5.1.0.1.15419398 2.5.1.0.1.15419398 1.9.0 + 0.0.1 @@ -51,6 +52,20 @@ maven-install-plugin 2.3.1 + + install-oidc-oauth2-sdk + initialize + + install-file + + + jar + com.vmware.vapi + oidc-oauth2-sdk + ${oidc-oauth2.version} + ./lib/oidc-oauth2-sdk-${oidc-oauth2.version}.jar + + install-draas-bindings initialize @@ -296,6 +311,11 @@ + + com.vmware.vapi + oidc-oauth2-sdk + ${oidc-oauth2.version} + com.vmware.vmc vmc-draas-bindings diff --git a/src/main/java/vmware/samples/common/AuthorizationConstants.java b/src/main/java/vmware/samples/common/AuthorizationConstants.java new file mode 100644 index 00000000000..142d1dd02ca --- /dev/null +++ b/src/main/java/vmware/samples/common/AuthorizationConstants.java @@ -0,0 +1,8 @@ +package vmware.samples.common; + +public class AuthorizationConstants { + public static final String CLIENT_ID="clientId"; + public static final String CLIENT_SECRET="clientSecret"; + public static final String REDIRECT_URI="redirect_uri"; + public static final String REDIRECT_URIS="redirectUris"; +} diff --git a/src/main/java/vmware/samples/common/AuthorizationUtil.java b/src/main/java/vmware/samples/common/AuthorizationUtil.java new file mode 100644 index 00000000000..480d315ee7e --- /dev/null +++ b/src/main/java/vmware/samples/common/AuthorizationUtil.java @@ -0,0 +1,63 @@ +/* + * ******************************************************* + * Copyright VMware, Inc. 2019. All Rights Reserved. + * SPDX-License-Identifier: MIT + * ******************************************************* + * + * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, + * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED + * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, + * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. + */ +package vmware.samples.common; + +import java.util.Map; + +import com.vmware.authorization.AuthorizationRequestExecutor; +import com.vmware.authorization.Constants; +import com.vmware.authorization.IDPFactory; +import com.vmware.authorization.IdentityProviderType; +import com.vmware.authorization.grant.AuthorizationGrant; +import com.vmware.vapi.bindings.Service; +import com.vmware.vapi.bindings.StubConfiguration; +import com.vmware.vapi.protocol.HttpConfiguration; +import com.vmware.vapi.saml.SamlToken; + +import vmware.samples.common.authentication.VapiAuthenticationHelper; +import vmware.samples.vcenter.identity.helpers.VcenterIdentityProvider; +import vmware.samples.vcenter.identity.helpers.VcenterTokenExchange; + +public class AuthorizationUtil { + + private AuthorizationUtil() {} + + public static IdentityProviderType getDefaultIdentityProviderWithType(String vcenterServer, + boolean skipServerVerification) throws Exception { + VcenterIdentityProvider vip = new VcenterIdentityProvider(); + IdentityProviderType identityType = vip.getDefaultIdentityProviderWithType(vcenterServer, + skipServerVerification); + return identityType; + + } + public static T getStub(Class serviceClass, IdentityProviderType identityType, + AuthorizationGrant grantType, String vcenterServer) throws Exception { + + AuthorizationRequestExecutor grantExecutor = IDPFactory.getAuthRequestExecutor(identityType.getType(), + grantType); + Map map = grantExecutor.getAccessAndIdToken(); + VcenterTokenExchange tokenSer = new VcenterTokenExchange(); + SamlToken samlToken = tokenSer.getSAMLToken(map.get(Constants.ACCESS_TOKEN), + map.get(Constants.ID_TOKEN), vcenterServer); + //System.out.println("SAML Bearer Token :" + samlToken); + VapiAuthenticationHelper vapiHelper = new VapiAuthenticationHelper(); + HttpConfiguration httpConfig = vapiHelper.buildHttpConfiguration(true); + StubConfiguration sessionStubConfig = vapiHelper + .loginBySamlBearerToken(vcenterServer, samlToken, httpConfig); + + return vapiHelper.getStubFactory().createStub(serviceClass, + sessionStubConfig); + + } +} + diff --git a/src/main/java/vmware/samples/common/ParametersHelper.java b/src/main/java/vmware/samples/common/ParametersHelper.java index a52218d85b7..7ab3e928d38 100644 --- a/src/main/java/vmware/samples/common/ParametersHelper.java +++ b/src/main/java/vmware/samples/common/ParametersHelper.java @@ -1,6 +1,6 @@ /* * ******************************************************* - * Copyright VMware, Inc. 2016. All Rights Reserved. + * Copyright VMware, Inc. 2019. All Rights Reserved. * SPDX-License-Identifier: MIT * ******************************************************* * @@ -12,6 +12,8 @@ */ package vmware.samples.common; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -32,13 +34,19 @@ import org.apache.commons.configuration.ConversionException; import org.apache.commons.configuration.PropertiesConfiguration; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; + /** * Helper class for parsing command line options or reading the options from a * config file */ public class ParametersHelper { private Map optionMap; + private Map parsedOptions; private static final String CONFIG_FILE = "config-file"; + private static final String OAUTH_APP_JSON = "oauth_app_json"; /** * Adds the common and sample-specific options to the list of options to @@ -72,7 +80,7 @@ public ParametersHelper(List