get/put passwordPolicy

This commit is contained in:
danikov 2012-03-11 13:25:25 +00:00
parent d4843a5c31
commit 969141a7eb
8 changed files with 187 additions and 17 deletions

View File

@ -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
);
}

View File

@ -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<OrgPasswordPolicySettings> 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<OrgPasswordPolicySettings> 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<OrgLeaseSettings> 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<OrgVAppTemplateLeaseSettings> updateVAppTemplateLeaseSettings(
@EndpointParam URI orgRef,
@BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings group);
@BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings);
}

View File

@ -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.
*
* <pre>
* GET /admin/org/{id}/settings/passwordPolicy
* </pre>
*
* @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.
*
* <pre>
* PUT /admin/org/{id}/settings/passwordPolicy
* </pre>
* @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.

View File

@ -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() {

View File

@ -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() {

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrgPasswordPolicySettings xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="edit" type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"/>
<AccountLockoutEnabled>false</AccountLockoutEnabled>
<InvalidLoginsBeforeLockout>5</InvalidLoginsBeforeLockout>
<AccountLockoutIntervalMinutes>10</AccountLockoutIntervalMinutes>
</OrgPasswordPolicySettings>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrgPasswordPolicySettings xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="edit" type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"/>
<AccountLockoutEnabled>true</AccountLockoutEnabled>
<InvalidLoginsBeforeLockout>6</InvalidLoginsBeforeLockout>
<AccountLockoutIntervalMinutes>11</AccountLockoutIntervalMinutes>
</OrgPasswordPolicySettings>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OrgPasswordPolicySettings type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy" xmlns="http://www.vmware.com/vcloud/v1.5">
<Link rel="edit" type="application/vnd.vmware.admin.organizationPasswordPolicySettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"/>
<AccountLockoutEnabled>true</AccountLockoutEnabled>
<InvalidLoginsBeforeLockout>6</InvalidLoginsBeforeLockout>
<AccountLockoutIntervalMinutes>11</AccountLockoutIntervalMinutes>
</OrgPasswordPolicySettings>