*/
@Before
public void setup() {
try {
final Collection root = DatabaseManager.getCollection(baseUri + "/db", "admin", "");
UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
ums.chmod("rwxr-xr-x"); //ensure /db is always 755
//remove accounts 'test1', 'test2' and 'test3'
removeAccounts(ums, new String[]{"test1", "test2", "test3"});
//remove group 'users'
removeGroups(ums, new String[]{"users"});
final Group group = new GroupAider("exist", "users");
ums.addGroup(group);
UserAider user = new UserAider("test1", group);
user.setPassword("test1");
ums.addAccount(user);
final Group extGroup = new GroupAider("exist", "extusers");
ums.addGroup(extGroup);
ums.addAccountToGroup("test1", "extusers");
user = new UserAider("test2", group);
user.setPassword("test2");
ums.addAccount(user);
user = new UserAider("test3", ums.getGroup("guest"));
user.setPassword("test3");
ums.addAccount(user);
// create a collection /db/securityTest1 as owned by "test1:users" and mode 0770
CollectionManagementService cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
Collection test = cms.createCollection("securityTest1");
ums = (UserManagementService) test.getService("UserManagementService", "1.0");
//change ownership to test1
final Account test1 = ums.getAccount("test1");
ums.chown(test1, "users");
// full permissions for user and group, none for world
ums.chmod(0770);
test = DatabaseManager.getCollection(baseUri + "/db/securityTest1", "test1", "test1");
// create a resource /db/securityTest1/test.xml owned by "test1:users" and mode 0770
Resource resource = test.createResource("test.xml", XMLResource.RESOURCE_TYPE);
resource.setContent("<test/>");
test.storeResource(resource);
ums.chmod(resource, 0770);
resource = test.createResource("test.bin", BinaryResource.RESOURCE_TYPE);
resource.setContent("binary-test".getBytes());
test.storeResource(resource);
ums.chmod(resource, 0770);
// create a collection /db/securityTest2 as user "test1"
cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
Collection testCol2 = cms.createCollection("securityTest2");
ums = (UserManagementService) testCol2.getService("UserManagementService", "1.0");
//change ownership to test1
ums.chown(test1, "users");
// full permissions for user and group, none for world
ums.chmod(0775);
// create a collection /db/securityTest3 as user "test3"
cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
Collection testCol3 = cms.createCollection("securityTest3");
ums = (UserManagementService) testCol3.getService("UserManagementService", "1.0");
//change ownership to test3
final Account test3 = ums.getAccount("test3");
ums.chown(test3, "users");
// full permissions for all
ums.chmod(0777);
} catch(final XMLDBException xmldbe) {
xmldbe.printStackTrace();
fail(xmldbe.getMessage());
}
}