diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 05ae7f2421..64b187d015 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -139,6 +139,8 @@ public class VCloudDirectorMediaType { public static final String ORG_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppLeaseSettings+xml"; + public static final String ORG_PASSWORD_POLICY_SETTINGS = "application/vnd.vmware.admin.organizationPasswordPolicySettings+xml"; + /** * * All acceptable media types. @@ -158,6 +160,6 @@ public class VCloudDirectorMediaType { NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, - ORG_LEASE_SETTINGS + ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index 74c38465b2..063c23f639 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -34,6 +34,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -67,9 +68,29 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + /** + * @see AdminOrgClient#getPasswordPolicy(URI) + */ + @GET + @Path("/settings/passwordPolicy") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getPasswordPolicy( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updatePasswordPolicy(URI, OrgPasswordPolicySettings) + */ + @PUT + @Path("/settings/passwordPolicy") + @Consumes(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updatePasswordPolicy( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings); /** * @see AdminOrgClient#getVAppLeaseSettings(URI) @@ -93,7 +114,7 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateVAppLeaseSettings( @EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgLeaseSettings group); + @BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings); /** * @see AdminOrgClient#getVAppTemplateLeaseSettings(URI) @@ -117,6 +138,6 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateVAppTemplateLeaseSettings( @EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings group); + @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index fdb3f962da..2b86054340 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** @@ -55,9 +56,30 @@ public interface AdminOrgClient extends OrgClient { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy + /** + * Retrieves password policy settings for an organization. + * + *
+    * GET /admin/org/{id}/settings/passwordPolicy
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgPasswordPolicySettings getPasswordPolicy(URI orgRef); -// PUT /admin/org/{id}/settings/passwordPolicy + /** + * Updates password policy settings for organization. + * + *
+    * PUT /admin/org/{id}/settings/passwordPolicy
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgPasswordPolicySettings updatePasswordPolicy(URI orgRef, + OrgPasswordPolicySettings newSettings); /** * Gets organization resource cleanup settings on the level of vApp. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java index 44b37023d0..b177892512 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java @@ -24,7 +24,9 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; @@ -39,9 +41,9 @@ import org.testng.annotations.Test; public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { private Reference orgRef = Reference.builder() - .type("application/vnd.vmware.admin.???+xml") +// .type("application/vnd.vmware.admin.???+xml") .name("???") - .href(URI.create(endpoint + "/admin/org/???")) + .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build(); // GET /admin/org/{id} @@ -64,9 +66,64 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + @Test + public void testGetPasswordPolicy() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/passwordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpResponseBuilder().build()); + + OrgPasswordPolicySettings expected = orgPasswordPolicy(); + + assertEquals(client.getAdminOrgClient().getPasswordPolicy(orgRef.getURI()), expected); + } + + public static final OrgPasswordPolicySettings orgPasswordPolicy() { + return OrgPasswordPolicySettings.builder() + .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")) + .build()) + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")) + .accountLockoutEnabled(false) + .invalidLoginsBeforeLockout(5) + .accountLockoutIntervalMinutes(10) + .build(); + } + + @Test + public void testUpdateOrgPasswordPolicy() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/???/settings/passwordPolicy") + .xmlFilePayload("/org/admin/updatePasswordPolicySource.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updatePasswordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpResponseBuilder().build()); + + OrgPasswordPolicySettings expected = updateOrgPasswordPolicy(); + + assertEquals(client.getAdminOrgClient().updatePasswordPolicy(orgRef.getURI(), expected), expected); + } + + public static final OrgPasswordPolicySettings updateOrgPasswordPolicy() { + return orgPasswordPolicy().toBuilder() + .accountLockoutEnabled(true) + .invalidLoginsBeforeLockout(6) + .accountLockoutIntervalMinutes(11) + .build(); + } @Test(enabled = false) public void testGetVAppLeaseSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 7e81d09ec6..bcb7913871 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -25,6 +25,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; @@ -54,8 +55,9 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ private ReferenceType orgRef; private AdminOrg org; - OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + OrgPasswordPolicySettings passwordPolicy; OrgLeaseSettings vAppLeaseSettings; + OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; @Override @BeforeClass(inheritGroups = true) @@ -85,9 +87,54 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + @Test(testName = "GET /admin/org/{id}/settings/passwordPolicy") + public void testGetPasswordPolicy() { + passwordPolicy = orgClient.getPasswordPolicy(orgRef.getURI()); + + Checks.checkPasswordPolicySettings(passwordPolicy); + } + + @Test(testName = "PUT /admin/org/{id}/settings/passwordPolicy", + dependsOnMethods = { "testGetPasswordPolicy" }) + public void testUpdatePasswordPolicy() { + boolean accountLockoutEnabled = passwordPolicy.isAccountLockoutEnabled(); + Integer invalidLoginsBeforeLockout = passwordPolicy.getInvalidLoginsBeforeLockout(); + Integer accountLockoutIntervalMinutes = passwordPolicy.getAccountLockoutIntervalMinutes(); + + try { + passwordPolicy = passwordPolicy.toBuilder() + .accountLockoutEnabled(!accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout+1) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes+1) + .build(); + + passwordPolicy = orgClient.updatePasswordPolicy( + orgRef.getURI(), passwordPolicy); + + assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(passwordPolicy.getInvalidLoginsBeforeLockout(), invalidLoginsBeforeLockout+1), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "storageLeaseSeconds")); + assertTrue(equal(passwordPolicy.getAccountLockoutIntervalMinutes(), accountLockoutIntervalMinutes+1), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "deploymentLeaseSeconds")); + + //TODO negative tests? + + Checks.checkPasswordPolicySettings(passwordPolicy); + } finally { + passwordPolicy = passwordPolicy.toBuilder() + .accountLockoutEnabled(accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes) + .build(); + + passwordPolicy = orgClient.updatePasswordPolicy( + orgRef.getURI(), passwordPolicy); + } + } @Test(testName = "GET /admin/org/{id}/settings/vAppLeaseSettings") public void testGetVAppLeaseSettings() { diff --git a/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml b/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml new file mode 100644 index 0000000000..e48f20fbfd --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml @@ -0,0 +1,7 @@ + + + + false + 5 + 10 + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml new file mode 100644 index 0000000000..da245c8361 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml @@ -0,0 +1,7 @@ + + + + true + 6 + 11 + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml new file mode 100644 index 0000000000..706ac57a85 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml @@ -0,0 +1,7 @@ + + + + true + 6 + 11 + \ No newline at end of file