mirror of https://github.com/apache/jclouds.git
admin user client base
This commit is contained in:
parent
adc275673d
commit
0ee77f99ec
|
@ -26,6 +26,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.Org;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.User;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.Network;
|
||||
import org.jclouds.vcloud.director.v1_5.features.AdminCatalogAsyncClient;
|
||||
|
@ -37,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient;
|
|||
import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient;
|
||||
|
||||
|
@ -128,4 +130,10 @@ public interface VCloudDirectorAsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
AdminOrgAsyncClient getAdminOrgClient();
|
||||
|
||||
/**
|
||||
* @return asynchronous access to {@link User} features
|
||||
*/
|
||||
@Delegate
|
||||
UserAsyncClient getUserClient();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.Org;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.User;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.Network;
|
||||
import org.jclouds.vcloud.director.v1_5.features.AdminCatalogClient;
|
||||
|
@ -41,6 +42,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgClient;
|
|||
import org.jclouds.vcloud.director.v1_5.features.QueryClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UploadClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UserClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VdcClient;
|
||||
|
||||
|
@ -131,4 +133,10 @@ public interface VCloudDirectorClient {
|
|||
*/
|
||||
@Delegate
|
||||
AdminOrgClient getAdminOrgClient();
|
||||
|
||||
/**
|
||||
* @return synchronous access to {@link User} features
|
||||
*/
|
||||
@Delegate
|
||||
UserClient getUserClient();
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;
|
|||
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UploadClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.UserClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient;
|
||||
|
@ -109,6 +111,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
.put(AdminCatalogClient.class, AdminCatalogAsyncClient.class)
|
||||
.put(AdminOrgClient.class, AdminOrgAsyncClient.class)
|
||||
.put(GroupClient.class, GroupAsyncClient.class)
|
||||
.put(UserClient.class, UserAsyncClient.class)
|
||||
.build();
|
||||
|
||||
public VCloudDirectorRestClientModule() {
|
||||
|
|
|
@ -22,13 +22,16 @@ import static com.google.common.base.Objects.equal;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
|
@ -88,7 +91,7 @@ import com.google.common.collect.Sets;
|
|||
"deployedVmQuota",
|
||||
"role",
|
||||
"password",
|
||||
"groupReferences"
|
||||
"groups"
|
||||
})
|
||||
public class User
|
||||
extends EntityType<User>
|
||||
|
@ -122,7 +125,7 @@ public class User
|
|||
private Integer deployedVmQuota;
|
||||
private Reference role;
|
||||
private String password;
|
||||
private Object /* GroupsList */ groupReferences;
|
||||
private List<Reference> groups;
|
||||
|
||||
/**
|
||||
* @see User#getFullName()
|
||||
|
@ -261,20 +264,27 @@ public class User
|
|||
}
|
||||
|
||||
/**
|
||||
* @see User#getGroupReferences()
|
||||
* @see User#getGroups()
|
||||
*/
|
||||
public Builder groupReferences(Object /* GroupsList */ groupReferences) {
|
||||
this.groupReferences = groupReferences;
|
||||
public Builder groups(List<Reference> groups) {
|
||||
this.groups = ImmutableList.copyOf(groups);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see User#getGroups()
|
||||
*/
|
||||
public Builder group(Reference group) {
|
||||
this.groups.add(checkNotNull(group, "group"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public User build() {
|
||||
return new User(href, type, links, description, tasks, id,
|
||||
name, fullName, emailAddress, telephone, isEnabled, isLocked,
|
||||
im, nameInSource, isAlertEnabled, alertEmailPrefix, alertEmail,
|
||||
isExternal, isDefaultCached, isGroupRole, storedVmQuota, deployedVmQuota,
|
||||
role, password, groupReferences);
|
||||
role, password, groups);
|
||||
}
|
||||
|
||||
|
||||
|
@ -357,7 +367,7 @@ public class User
|
|||
.deployedVmQuota(in.getDeployedVmQuota())
|
||||
.role(in.getRole())
|
||||
.password(in.getPassword())
|
||||
.groupReferences(in.getGroupReferences());
|
||||
.groups(in.getGroups());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,14 +405,14 @@ public class User
|
|||
protected Reference role;
|
||||
@XmlElement(name = "Password")
|
||||
protected String password;
|
||||
@XmlElement(name = "GroupReferences")
|
||||
protected Object /* GroupsList */ groupReferences;
|
||||
@XmlElementWrapper(name = "GroupReferences")
|
||||
protected List<Reference> groups;
|
||||
|
||||
public User(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
|
||||
String name, String fullName, String emailAddress, String telephone, Boolean enabled, Boolean locked,
|
||||
String im, String nameInSource, Boolean alertEnabled, String alertEmailPrefix, String alertEmail,
|
||||
Boolean external, Boolean defaultCached, Boolean groupRole, Integer storedVmQuota, Integer deployedVmQuota,
|
||||
Reference role, String password, Object groupReferences) {
|
||||
Reference role, String password, List<Reference> groups) {
|
||||
super(href, type, links, description, tasks, id, name);
|
||||
this.fullName = fullName;
|
||||
this.emailAddress = emailAddress;
|
||||
|
@ -421,7 +431,7 @@ public class User
|
|||
this.deployedVmQuota = deployedVmQuota;
|
||||
this.role = role;
|
||||
this.password = password;
|
||||
this.groupReferences = groupReferences;
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
private User() {
|
||||
|
@ -605,8 +615,8 @@ public class User
|
|||
* @return possible object is
|
||||
* {@link GroupsListType }
|
||||
*/
|
||||
public Object /* GroupsList */ getGroupReferences() {
|
||||
return groupReferences;
|
||||
public List<Reference> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -633,7 +643,7 @@ public class User
|
|||
equal(deployedVmQuota, that.deployedVmQuota) &&
|
||||
equal(role, that.role) &&
|
||||
equal(password, that.password) &&
|
||||
equal(groupReferences, that.groupReferences);
|
||||
equal(groups, that.groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -655,7 +665,7 @@ public class User
|
|||
deployedVmQuota,
|
||||
role,
|
||||
password,
|
||||
groupReferences);
|
||||
groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -678,7 +688,7 @@ public class User
|
|||
.add("deployedVmQuota", deployedVmQuota)
|
||||
.add("role", role)
|
||||
.add("password", password)
|
||||
.add("groupReferences", groupReferences).toString();
|
||||
.add("groups", groups).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
||||
|
||||
/**
|
||||
* @see GroupClient
|
||||
* @author danikov
|
||||
*/
|
||||
@RequestFilters(AddVCloudAuthorizationToRequest.class)
|
||||
public interface UserAsyncClient {
|
||||
// POST /admin/org/{id}/users
|
||||
|
||||
// GET /admin/user/{id}
|
||||
|
||||
// PUT /admin/user/{id}
|
||||
|
||||
// DELETE /admin/user/{id}
|
||||
|
||||
// POST /admin/user/{id}/action/unlock
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Group;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to {@link Group} objects.
|
||||
*
|
||||
* @see GroupAsyncClient
|
||||
* @author danikov
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface UserClient {
|
||||
// POST /admin/org/{id}/users
|
||||
|
||||
// GET /admin/user/{id}
|
||||
|
||||
// PUT /admin/user/{id}
|
||||
|
||||
// DELETE /admin/user/{id}
|
||||
|
||||
// POST /admin/user/{id}/action/unlock
|
||||
}
|
|
@ -748,4 +748,52 @@ public class Checks {
|
|||
// parent type
|
||||
checkResourceType(settings);
|
||||
}
|
||||
|
||||
public static void checkUser(User user) {
|
||||
// Check optional fields
|
||||
// NOTE fullName cannot be checked
|
||||
// NOTE isEnabled cannot be checked
|
||||
// NOTE isLocked cannot be checked
|
||||
// NOTE im cannot be checked
|
||||
// NOTE nameInSource cannot be checked
|
||||
// NOTE isAlertEnabled cannot be checked
|
||||
// NOTE alterEmailPrefix cannot be checked
|
||||
// NOTE isExternal cannot be checked
|
||||
// NOTE isDefaultCached cannot be checked
|
||||
// NOTE isGroupRole cannot be checked
|
||||
// NOTE password cannot be checked
|
||||
|
||||
if (user.getEmailAddress() != null) {
|
||||
checkEmailAddress(user.getEmailAddress());
|
||||
}
|
||||
if (user.getTelephone() != null) {
|
||||
checkTelephone(user.getTelephone());
|
||||
}
|
||||
if (user.getAlertEmail() != null) {
|
||||
checkEmailAddress(user.getAlertEmail());
|
||||
}
|
||||
if (user.getStoredVmQuota() != null) {
|
||||
assertTrue(user.getStoredVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0,
|
||||
"User", "storedVmQuota", user.getStoredVmQuota()));
|
||||
}
|
||||
if (user.getDeployedVmQuota() != null) {
|
||||
assertTrue(user.getDeployedVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0,
|
||||
"User", "deployedVmQuota", user.getDeployedVmQuota()));
|
||||
}
|
||||
if (user.getRole() != null) {
|
||||
checkReferenceType(user.getRole());
|
||||
}
|
||||
if (user.getGroups() != null) {
|
||||
for (Reference group : user.getGroups()) {
|
||||
checkReferenceType(group);
|
||||
}
|
||||
}
|
||||
|
||||
// parent type
|
||||
checkEntityType(user);
|
||||
}
|
||||
|
||||
public static void checkTelephone(String number) {
|
||||
// TODO: regex validate telephone
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test the {@link GroupClient} by observing its side effects.
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
@Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest")
|
||||
public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
|
||||
|
||||
private Reference userRef = Reference.builder()
|
||||
.href(URI.create(endpoint + "/admin/user/???"))
|
||||
.build();
|
||||
|
||||
// POST /admin/org/{id}/users
|
||||
|
||||
// GET /admin/user/{id}
|
||||
|
||||
// PUT /admin/user/{id}
|
||||
|
||||
// DELETE /admin/user/{id}
|
||||
|
||||
// POST /admin/user/{id}/action/unlock
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests live behavior of {@link AdminGroupClient}.
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
@Test(groups = { "live", "admin", "adminUser" }, singleThreaded = true, testName = "UserClientLiveTest")
|
||||
public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
public static final String GROUP = "admin group";
|
||||
|
||||
/*
|
||||
* Convenience references to API clients.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Shared state between dependant tests.
|
||||
*/
|
||||
|
||||
@Override
|
||||
@BeforeClass(inheritGroups = true)
|
||||
public void setupRequiredClients() {
|
||||
}
|
||||
|
||||
// POST /admin/org/{id}/users
|
||||
|
||||
// GET /admin/user/{id}
|
||||
|
||||
// PUT /admin/user/{id}
|
||||
|
||||
// DELETE /admin/user/{id}
|
||||
|
||||
// POST /admin/user/{id}/action/unlock
|
||||
}
|
Loading…
Reference in New Issue