]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e9b4efc2ce0caaeb20e3fe8420e97a22a09b5a62
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2010 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 /*
25  * To change this template, choose Tools | Templates
26  * and open the template in the editor.
27  */
28 package org.collectionspace.services.security.client.test;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Date;
33 import java.util.Hashtable;
34 import java.util.List;
35
36 import javax.ws.rs.core.Response;
37
38 import org.collectionspace.services.account.AccountsCommon;
39 import org.collectionspace.services.authorization.AccountRole;
40 import org.collectionspace.services.authorization.AccountValue;
41 import org.collectionspace.services.authorization.perms.ActionType;
42 import org.collectionspace.services.authorization.perms.EffectType;
43 import org.collectionspace.services.authorization.perms.Permission;
44 import org.collectionspace.services.authorization.perms.PermissionAction;
45 import org.collectionspace.services.authorization.PermissionRole;
46 import org.collectionspace.services.authorization.PermissionValue;
47 import org.collectionspace.services.authorization.Role;
48 import org.collectionspace.services.authorization.RoleValue;
49 import org.collectionspace.services.client.AccountClient;
50 import org.collectionspace.services.client.AccountFactory;
51 import org.collectionspace.services.client.AccountRoleClient;
52 import org.collectionspace.services.client.AccountRoleFactory;
53 import org.collectionspace.services.client.CollectionSpaceClient;
54 import org.collectionspace.services.client.DimensionClient;
55 import org.collectionspace.services.client.DimensionFactory;
56 import org.collectionspace.services.client.PayloadOutputPart;
57 import org.collectionspace.services.client.PermissionClient;
58 import org.collectionspace.services.client.PermissionFactory;
59 import org.collectionspace.services.client.PermissionRoleClient;
60 import org.collectionspace.services.client.PermissionRoleFactory;
61 import org.collectionspace.services.client.PoxPayloadIn;
62 import org.collectionspace.services.client.PoxPayloadOut;
63 import org.collectionspace.services.client.RoleClient;
64 import org.collectionspace.services.client.RoleFactory;
65 import org.collectionspace.services.client.test.BaseServiceTest;
66 import org.collectionspace.services.dimension.DimensionsCommon;
67 import org.collectionspace.services.jaxb.AbstractCommonList;
68 import org.testng.Assert;
69 import org.testng.annotations.Test;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
72 import org.testng.annotations.AfterClass;
73 import org.testng.annotations.BeforeClass;
74
75 /**
76  * AuthorizationServiceTest, carries out tests against a
77  * deployed and running Permission, Role, AccountRole, PermissionRole and
78  * CollectionObject Services.
79  *
80  * Pre-requisite : authorization-mgt/client tests seed some permissions used
81  * by this test
82  *
83  * $LastChangedRevision: 917 $
84  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
85  */
86 public class MultiTenancyTest extends BaseServiceTest<AbstractCommonList> {
87
88     private static class UserInfo {
89         String userName;
90         String password;
91
92         UserInfo(String u, String p) {
93             userName = u;
94             password = p;
95         }
96     }
97     
98     private final String CLASS_NAME = MultiTenancyTest.class.getName();
99     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
100     private final static String TENANT_1_ADMIN_USER = "admin@core.collectionspace.org";
101     private final static String TENANT_2_ADMIN_USER = "admin@testsci.collectionspace.org";
102     private final static String TENANT_ADMIN_PASS = "Administrator";
103     private final static String TENANT_1_USER = "user1@museum1.org";
104     private final static String TENANT_2_USER = "user2@museum2.org";
105     private final static String TENANT_1 = "1";
106     private final static String TENANT_2 = "2";
107     private final static String TEST_ROLE_NAME = "ROLE_TEST_REGISTRAR";
108     private final static String TEST_SERVICE_A = "dimensions";
109
110     // Instance variables specific to this test.
111     private String TENANT_RESOURCE_1 = null;
112     private String TENANT_RESOURCE_2 = null;
113     //key for userAccounts is userId
114     private Hashtable<String, AccountValue> userAccounts = new Hashtable<String, AccountValue>();
115     //key for permValues is id as there could be several perms for the same resource
116     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
117     //key for all tenantXXX tables is tenant id, expecting only one entity per tenant for this test
118     private Hashtable<String, UserInfo> tenantAdminUsers = new Hashtable<String, UserInfo>();
119     private Hashtable<String, AccountValue> tenantAccounts = new Hashtable<String, AccountValue>();
120     private Hashtable<String, RoleValue> tenantRoles = new Hashtable<String, RoleValue>();
121     private Hashtable<String, Role> tenantAdminRoles = new Hashtable<String, Role>();
122     private Hashtable<String, PermissionValue> tenantPermissions = new Hashtable<String, PermissionValue>();
123
124     /*
125      * This method is called only by the parent class, AbstractServiceTestImpl
126      */
127     @Override
128     protected String getServicePathComponent() {
129         return null;
130     }
131
132     @BeforeClass(alwaysRun = true)
133     public void seedData() throws Exception {
134         //tenant admin users are used to create accounts, roles and permissions and relationships
135         //assumption : two tenant admin users exist before running this test
136         tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS));
137         tenantAdminUsers.put(TENANT_2, new UserInfo(TENANT_2_ADMIN_USER, TENANT_ADMIN_PASS));
138
139         seedAccounts();
140         seedPermissions();
141         seedRoles();
142         seedAccountRoles();
143         seedPermissionRoles();
144     }
145
146     private void seedAccounts() throws Exception {
147         seedAccount(TENANT_1, TENANT_1_USER);
148         seedAccount(TENANT_2, TENANT_2_USER);
149     }
150
151     private void seedAccount(String tenantId, String userId) throws Exception {
152         //create account using default user in admin role but assign tenant id
153         //create username, email and password same for simplicity
154         String accId = createAccount(tenantId, userId, userId);
155         AccountValue ava = new AccountValue();
156         ava.setScreenName(userId);
157         ava.setUserId(userId);
158         ava.setAccountId(accId);
159         userAccounts.put(ava.getUserId(), ava);
160         tenantAccounts.put(tenantId, ava);
161         if (logger.isDebugEnabled()) {
162             logger.debug("seedAccount tenantId=" + tenantId + " userId=" + userId);
163         }
164     }
165
166     private void seedPermissions() throws Exception {
167         String resource = TEST_SERVICE_A;
168
169         PermissionAction pac = new PermissionAction();
170         pac.setName(ActionType.CREATE);
171         PermissionAction par = new PermissionAction();
172         par.setName(ActionType.READ);
173         PermissionAction pau = new PermissionAction();
174         pau.setName(ActionType.UPDATE);
175         PermissionAction pad = new PermissionAction();
176         pad.setName(ActionType.DELETE);
177
178         //both users can create, read and update and delete
179         List<PermissionAction> testActions = new ArrayList<PermissionAction>();
180         testActions.add(pac);
181         testActions.add(par);
182         testActions.add(pau);
183         testActions.add(pad);
184
185         seedPermission(TENANT_1, resource, testActions, EffectType.PERMIT);
186         seedPermission(TENANT_2, resource, testActions, EffectType.PERMIT);
187     }
188
189     private void seedPermission(String tenantId,
190             String resource, List<PermissionAction> testActions, EffectType effect) throws Exception {
191         //create permission using default user in admin role but assign tenant id
192         String id = createPermission(tenantId, resource, testActions, effect);
193         PermissionValue pv = new PermissionValue();
194         pv.setResourceName(resource);
195         pv.setPermissionId(id);
196         permValues.put(pv.getPermissionId(), pv);
197         tenantPermissions.put(tenantId, pv);
198         if (logger.isDebugEnabled()) {
199             logger.debug("seedPermission tenantId=" + tenantId
200                     + " permId=" + id + " resource=" + resource);
201         }
202     }
203
204     private void seedRoles() throws Exception {
205         //create role using default user in admin role but assign tenant id
206         //use the same role name to check constraints
207         seedRole(TENANT_1, TEST_ROLE_NAME);
208         seedRole(TENANT_2, TEST_ROLE_NAME);
209     }
210
211     private void seedRole(String tenantId, String roleName) throws Exception {
212         String rid = createRole(tenantId, roleName);
213         RoleValue rv = new RoleValue();
214         rv.setRoleId(rid);
215         rv.setRoleName(roleName);
216         tenantRoles.put(tenantId, rv);
217         if (logger.isDebugEnabled()) {
218             logger.debug("seedRole tenantId=" + tenantId + " roleName=" + roleName);
219         }
220     }
221
222     private void seedAccountRoles() throws Exception {
223         for (String tenantId : tenantAccounts.keySet()) {
224             AccountValue av = (AccountValue) tenantAccounts.get(tenantId);
225             seedAccountRole(tenantId, av.getUserId());
226         }
227     }
228
229     private void seedAccountRole(String tenantId, String userId) throws Exception {
230         List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
231         tenantRoleValues.add(tenantRoles.get(tenantId));
232         createAccountRole(tenantId, userAccounts.get(userId), tenantRoleValues);
233         if (logger.isDebugEnabled()) {
234             logger.debug("seedAccountRole tenantId=" + tenantId + " userId=" + userId);
235         }
236     }
237
238     private void seedPermissionRoles() throws Exception {
239         for (String tenantId : tenantPermissions.keySet()) {
240             PermissionValue pv = tenantPermissions.get(tenantId);
241             seedPermissionRole(tenantId, pv.getPermissionId());
242         }
243     }
244
245     private void seedPermissionRole(String tenantId, String permId) throws Exception {
246         List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
247         tenantRoleValues.add(tenantRoles.get(tenantId));
248         PermissionValue pv = permValues.get(permId);
249         createPermissionRole(tenantId, permValues.get(permId), tenantRoleValues);
250         if (logger.isDebugEnabled()) {
251             logger.debug("seedPermissionRole tenantId=" + tenantId
252                     + " permId=" + permId + " resource=" + pv.getResourceName());
253         }
254     }
255
256     /* (non-Javadoc)
257      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
258      */
259     @Override
260     protected CollectionSpaceClient getClientInstance() {
261         return null;
262     }
263     
264         @Override
265         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
266                 return null;
267         }
268
269     /* (non-Javadoc)
270      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
271      */
272     @Override
273     protected AbstractCommonList getCommonList(Response response) {
274         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
275         throw new UnsupportedOperationException();
276     }
277
278     // ---------------------------------------------------------------
279     // CRUD tests : CREATE tests
280     // ---------------------------------------------------------------
281     // Success outcomes
282
283     @Test(dataProvider = "testName")
284     public void create(String testName) throws Exception {
285         TENANT_RESOURCE_1 = create(testName, TENANT_1_USER, TENANT_1);
286         if (logger.isDebugEnabled()) {
287             logger.debug(testName + ": tenantId= " + TENANT_1
288                     + " userId=" + TENANT_1_USER
289                     + " TENANT_RESOURCE_1 id=" + TENANT_RESOURCE_1);
290         }
291     }
292
293     @Test(dataProvider = "testName")
294     public void create2(String testName) throws Exception {
295         TENANT_RESOURCE_2 = create(testName, TENANT_2_USER, TENANT_2);
296         if (logger.isDebugEnabled()) {
297             logger.debug(testName + ": tenantId= " + TENANT_2
298                     + " userId=" + TENANT_2_USER
299                     + " TENANT_RESOURCE_2 id=" + TENANT_RESOURCE_2);
300         }
301     }
302
303     private String create(String testName, String userName, String tenatnId) throws Exception {
304         String result = null;
305         
306         setupCreate();
307         //
308         // Create a new client and change the default AuthN credentials
309         //
310         DimensionClient client = new DimensionClient();
311         client.setAuth(true, userName, true, userName, true);
312         //
313         // Setup a dimension object to create
314         //
315         String identifier = createIdentifier();
316         DimensionsCommon dimension = new DimensionsCommon();
317         dimension.setDimension("dimensionType");
318         dimension.setMeasurementUnit("measurementUnit-" + identifier);
319         dimension.setValueDate(new Date().toString());
320         //
321         // Create a payload and send the POST request
322         //
323         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
324                 dimension);
325         Response res = client.create(multipart);
326         try {
327                 assertStatusCode(res, testName);
328                 result = extractId(res);
329         } finally {
330                 if (res != null) {
331                 res.close();
332             }
333         }
334
335         return result;
336
337     }
338
339     // ---------------------------------------------------------------
340     // CRUD tests : READ tests
341     // ---------------------------------------------------------------
342     // Success outcomes
343     @Test(dataProvider = "testName",
344                 dependsOnMethods = {"create"})
345     public void read(String testName) throws Exception {
346         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER);
347         Assert.assertNotNull(dimension);
348         if (logger.isDebugEnabled()) {
349             logger.debug(testName + ": tenantId= " + TENANT_1
350                     + " userId=" + TENANT_1_USER
351                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
352         }
353     }
354
355     @Test(dataProvider = "testName",
356                 dependsOnMethods = {"create2"})
357     public void read2(String testName) throws Exception {
358         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER);
359         Assert.assertNotNull(dimension);
360         if (logger.isDebugEnabled()) {
361             logger.debug(testName + ": tenantId= " + TENANT_2
362                     + " userId=" + TENANT_2_USER
363                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
364         }
365     }
366
367     private DimensionsCommon read(String testName, String id, String userName) throws Exception {
368         DimensionsCommon result = null;
369         
370         setupRead();
371         // Submit the request to the service and store the response.
372         DimensionClient client = new DimensionClient();
373         client.setAuth(true, userName, true, userName, true);
374         Response res = client.read(id);
375         try {
376                 assertStatusCode(res, testName);
377                 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
378                 result = (DimensionsCommon) extractPart(input,
379                         client.getCommonPartName(), DimensionsCommon.class);
380         } finally {
381                 if (res != null) {
382                 res.close();
383             }
384         }
385         
386         return result;
387     }
388
389     // ---------------------------------------------------------------
390     // CRUD tests : READ_LIST tests
391     // ---------------------------------------------------------------
392
393     @Test(dataProvider = "testName",
394                 dependsOnMethods = {"read2"})
395     public void updateNonExistent(String testName) throws Exception {
396         
397         setupUpdateNonExistent();
398         //
399         // Create a new client and change the default AuthN credentials
400         //
401         DimensionClient client = new DimensionClient();
402         //TENANT_1_USER is not allowed to update the resource of TENANT_2
403         client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true);
404         //
405         // Create a new dimension object to try to update
406         //
407         DimensionsCommon dimension = new DimensionsCommon();
408         dimension.setDimension("dimensionType");
409         // Update the content of this resource.
410         dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
411         dimension.setValueDate("updated-" + dimension.getValueDate());
412         //
413         // Create and send a dimension payload for the UPDATE request
414         //
415         PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
416         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension);
417         Response res = client.update(TENANT_RESOURCE_2, output);
418         try {
419                 assertStatusCode(res, testName);
420         } finally {
421                 if (res != null) {
422                 res.close();
423             }
424         }
425     }
426
427     // ---------------------------------------------------------------
428     // CRUD tests : DELETE tests
429     // ---------------------------------------------------------------
430     // Success outcomes
431     @Test(dataProvider = "testName",
432                 dependsOnMethods = {"deleteNonExistent"})
433     public void delete(String testName) throws Exception {
434         int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER);
435     }
436
437     @Test(dataProvider = "testName",
438                 dependsOnMethods = {"updateNonExistent"})
439     public void delete2(String testName) throws Exception {
440         int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER);
441
442     }
443
444     private int delete(String testName, String id, String userName) throws Exception {
445         int result = -1;
446         
447         // Perform setup.
448         setupDelete();
449         // Submit the request to the service and store the response.
450         DimensionClient client = new DimensionClient();
451         client.setAuth(true, userName, true, userName, true);
452         Response res = client.delete(id);
453         try {
454                 result = assertStatusCode(res, testName);
455         } finally {
456                 if (res != null) {
457                 res.close();
458             }
459         }
460         
461         return result;
462     }
463
464     // Failure outcomes
465     @Test(dataProvider = "testName",
466                 dependsOnMethods = {"read"})
467     public void deleteNonExistent(String testName) throws Exception {
468         //ignoring this test as the service side returns 200 now even if it does
469         //not find a record in the db
470
471         // Perform setup.
472         setupDelete();
473
474         // Submit the request to the service and store the response.
475         DimensionClient client = new DimensionClient();
476         //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1
477         client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true);
478         Response res = client.delete(TENANT_RESOURCE_1);
479         try {
480                 int statusCode = res.getStatus();
481                 // Check the status code of the response: does it match
482                 // the expected response(s)?
483                 if (logger.isDebugEnabled()) {
484                     logger.debug(testName + ": status = " + statusCode);
485                 }
486                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
487                         invalidStatusCodeMessage(testRequestType, statusCode));
488                 //going to incorrect Nuxeo domain would give DocumentNotFoundException
489                 //instead of giving FORBIDDEN
490                 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
491         } finally {
492                 if (res != null) {
493                 res.close();
494             }
495         }
496     }
497     
498     // ---------------------------------------------------------------
499     // Utility methods used by tests above
500     // ---------------------------------------------------------------
501     @AfterClass(alwaysRun = true)
502     public void cleanUp() throws Exception {
503         setupDelete();
504         String noTest = System.getProperty("noTestCleanup");
505         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
506             if (logger.isDebugEnabled()) {
507                 logger.debug("Skipping Cleanup phase ...");
508             }
509             return;
510         }
511         if (logger.isDebugEnabled()) {
512             logger.debug("Cleaning up temporary resources created for testing ...");
513         }
514
515         //tenant admin users are used to create accounts, roles and permissions and relationships
516         //assumption : two tenant admin users exist before running this test
517
518         deletePermissionRoles();
519         deleteAccountRoles();
520         //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
521         //deletePermissions();
522         deleteRoles();
523         deleteAccounts();
524     }
525
526     private void deletePermissionRoles() throws Exception {
527         for (String tenantId : tenantPermissions.keySet()) {
528             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
529             tenantRoleValues.add(tenantRoles.get(tenantId));
530             PermissionValue pv = tenantPermissions.get(tenantId);
531             deletePermissionRole(tenantId, pv, tenantRoleValues);
532         }
533     }
534
535     private void deleteAccountRoles() throws Exception {
536         for (String tenantId : tenantAccounts.keySet()) {
537             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
538             tenantRoleValues.add(tenantRoles.get(tenantId));
539             AccountValue av = tenantAccounts.get(tenantId);
540             deleteAccountRole(tenantId, av, tenantRoleValues);
541         }
542     }
543
544     private void deletePermissions() throws Exception {
545         for (String tenantId : tenantPermissions.keySet()) {
546             PermissionValue pv = tenantPermissions.get(tenantId);
547             deletePermission(tenantId, pv.getPermissionId());
548         }
549     }
550
551     private void deleteRoles() throws Exception {
552         for (String tenantId : tenantRoles.keySet()) {
553             RoleValue rv = tenantRoles.get(tenantId);
554             deleteRole(tenantId, rv.getRoleId());
555         }
556     }
557
558     private void deleteAccounts() throws Exception {
559         for (String tenantId : tenantAccounts.keySet()) {
560             AccountValue av = tenantAccounts.get(tenantId);
561             deleteAccount(tenantId, av.getAccountId());
562         }
563     }
564
565     private String createPermission(String tenantId, String resName,
566             List<PermissionAction> actions, EffectType effect) throws Exception {
567         String result = null;
568         
569         setupCreate();
570         PermissionClient permClient = new PermissionClient();
571         UserInfo ui = tenantAdminUsers.get(tenantId);
572         permClient.setAuth(true, ui.userName, true, ui.password, true);
573         Permission permission = PermissionFactory.createPermissionInstance(resName,
574                 "default permissions for " + resName,
575                 actions, effect, true, true, true);
576         permission.setTenantId(tenantId);
577         Response res = permClient.create(permission);
578         try {
579                 assertStatusCode(res, "CreatePermission");
580                 result = extractId(res);
581         } finally {
582                 if (res != null) {
583                 res.close();
584             }
585         }
586         
587         return result;
588     }
589
590     private void deletePermission(String tenantId, String permId) throws Exception {
591         setupDelete();
592         PermissionClient permClient = new PermissionClient();
593         UserInfo ui = tenantAdminUsers.get(tenantId);
594         permClient.setAuth(true, ui.userName, true, ui.password, true);
595         Response res = permClient.delete(permId);
596         try {
597                 assertStatusCode(res, "DeletePermission");
598         } finally {
599                 if (res != null) {
600                 res.close();
601             }
602         }
603     }
604
605     private String createRole(String tenantId, String roleName) throws Exception {
606         String result = null;
607         
608         setupCreate();
609         RoleClient roleClient = new RoleClient();
610         UserInfo ui = tenantAdminUsers.get(tenantId);
611         roleClient.setAuth(true, ui.userName, true, ui.password, true);
612         Role role = RoleFactory.createRoleInstance(roleName,
613                         roleName, //the display name
614                 "role for " + roleName, true);
615         role.setTenantId(tenantId);
616         Response res = roleClient.create(role);
617         try {
618                 assertStatusCode(res, "CreateRole");
619                 result = extractId(res);
620         } finally {
621                 if (res != null) {
622                 res.close();
623             }
624         }
625         
626         return result;
627     }
628
629     private void deleteRole(String tenantId, String roleId) throws Exception {
630         setupDelete();
631         RoleClient roleClient = new RoleClient();
632         UserInfo ui = tenantAdminUsers.get(tenantId);
633         roleClient.setAuth(true, ui.userName, true, ui.password, true);
634         Response res = roleClient.delete(roleId);
635         try {
636                 assertStatusCode(res, "DeleteRole");
637         } finally {
638                 if (res != null) {
639                 res.close();
640             }
641         }
642     }
643
644     private String createAccount(String tenantId, String userName, String email) throws Exception {
645         String result = null;
646         
647         setupCreate();
648         AccountClient accountClient = new AccountClient();
649         UserInfo ui = tenantAdminUsers.get(tenantId);
650         accountClient.setAuth(true, ui.userName, true, ui.password, true);
651         AccountsCommon account = AccountFactory.createAccountInstance(
652                 userName, userName, userName, email, tenantId,
653                 true, false, true, true);
654         Response res = accountClient.create(account);
655         try {
656                 assertStatusCode(res, "CreateAccount");
657                 result = extractId(res);
658         } finally {
659                 if (res != null) {
660                 res.close();
661             }
662         }
663         
664         return result;
665     }
666
667     private void deleteAccount(String tenantId, String accId) throws Exception {
668         setupDelete();
669         AccountClient accClient = new AccountClient();
670         UserInfo ui = tenantAdminUsers.get(tenantId);
671         accClient.setAuth(true, ui.userName, true, ui.password, true);
672         Response res = accClient.delete(accId);
673         try {
674                 assertStatusCode(res, "DeleteAccount");
675         } finally {
676                 if (res != null) {
677                 res.close();
678             }
679         }
680     }
681
682     private String createAccountRole(String tenantId, AccountValue av,
683             Collection<RoleValue> rvs) throws Exception {
684         String result = null;
685         
686         setupCreate();
687         // Submit the request to the service and store the response.
688         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
689                 av, rvs, true, true);
690         AccountRoleClient client = new AccountRoleClient();
691         UserInfo ui = tenantAdminUsers.get(tenantId);
692         client.setAuth(true, ui.userName, true, ui.password, true);
693         Response res = client.create(av.getAccountId(), accRole);
694         try {
695                 assertStatusCode(res, "CreateAccountRole");
696                 result = extractId(res);
697         } finally {
698                 if (res != null) {
699                 res.close();
700             }
701         }
702
703         return result;
704     }
705
706     private void deleteAccountRole(String tenantId, AccountValue av,
707             List<RoleValue> rvs) throws Exception {
708         // Perform setup.
709         setupDelete();
710
711         // Submit the request to the service and store the response.
712         AccountRoleClient client = new AccountRoleClient();
713         UserInfo ui = tenantAdminUsers.get(tenantId);
714         client.setAuth(true, ui.userName, true, ui.password, true);
715         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
716                 av, rvs, true, true);
717         Response res = client.delete(av.getAccountId());
718         try {
719                 assertStatusCode(res, "DeleteAccountRole");
720         } finally {
721                 if (res != null) {
722                 res.close();
723             }
724         }
725     }
726
727     private String createPermissionRole(String tenantId, PermissionValue pv,
728             Collection<RoleValue> rvs) throws Exception {
729         String result = null;
730         
731         setupCreate();
732         List<RoleValue> rvls = new ArrayList<RoleValue>();
733         rvls.addAll(rvs);
734         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
735                 pv, rvls, true, true);
736         PermissionRoleClient client = new PermissionRoleClient();
737         UserInfo ui = tenantAdminUsers.get(tenantId);
738         client.setAuth(true, ui.userName, true, ui.password, true);
739         Response res = client.create(pv.getPermissionId(), permRole);
740         try {
741                 assertStatusCode(res, "createPermissionRole");
742                 result = extractId(res);
743         }  finally {
744                 if (res != null) {
745                 res.close();
746             }
747         }
748         
749         return result;
750     }
751
752     private void deletePermissionRole(String tenantId, PermissionValue pv, List<RoleValue> rvls) throws Exception {
753         // Perform setup.
754         setupDelete();
755
756         // Submit the request to the service and store the response.
757         PermissionRoleClient client = new PermissionRoleClient();
758         UserInfo ui = tenantAdminUsers.get(tenantId);
759         client.setAuth(true, ui.userName, true, ui.password, true);
760         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
761                 pv, rvls, true, true);
762         Response res = client.delete(pv.getPermissionId());
763         try {
764                 assertStatusCode(res, "DeletePermissionRole");
765         } finally {
766                 if (res != null) {
767                 res.close();
768             }
769         }
770     }
771
772         @Override
773         protected String getServiceName() {
774                 // TODO Auto-generated method stub
775         throw new UnsupportedOperationException();
776         }
777
778         @Override
779         protected Class<AbstractCommonList> getCommonListType() {
780                 // TODO Auto-generated method stub
781                 throw new UnsupportedOperationException();
782         }
783 }