setMockCreator(new MockCreator() {
@Override
public GeoServerSecurityManager createSecurityManager(MockTestData testData) throws Exception {
GeoServerSecurityManager secMgr = createMock(GeoServerSecurityManager.class);
GeoServerRoleStore roleStore1 = createRoleStore("test", secMgr, "role1", "parent1");
addRolesToCreate(roleStore1, "", "duplicated", "xxx");
GeoServerRoleStore roleStore2 = createRoleStore("test1", secMgr, "duplicated");
expect(secMgr.listRoleServices()).andReturn(
new TreeSet<String>(Arrays.asList("test", "test1"))).anyTimes();
replay(roleStore1, roleStore2, secMgr);
return secMgr;
}
});
GeoServerSecurityManager secMgr = getSecurityManager();
GeoServerRoleStore roleStore = (GeoServerRoleStore) secMgr.loadRoleService("test");
RoleStoreValidationWrapper store = new RoleStoreValidationWrapper(roleStore);
try {
store.addRole(store.createRoleObject(""));
fail("empty role name should throw exception");
} catch (IOException ex) {
assertSecurityException(ex, NAME_REQUIRED);
}
try {
store.addRole(store.createRoleObject(""));
fail("empty role name should throw exception");
} catch (IOException ex) {
assertSecurityException(ex, NAME_REQUIRED);
}
GeoServerRole role1 = store.getRoleByName("role1");
try {
store.addRole(role1);
fail("already existing role name should throw exception");
} catch (IOException ex) {
assertSecurityException(ex, ALREADY_EXISTS, "role1");
}
for (GeoServerRole srole : GeoServerRole.SystemRoles) {
try {
store.addRole(store.createRoleObject(srole.getAuthority()));
fail("reserved role name should throw exception");
} catch (IOException ex) {
assertSecurityException(ex, RESERVED_NAME, srole.getAuthority());
}
}
GeoServerRoleStore roleStore1 = (GeoServerRoleStore) secMgr.loadRoleService("test1");
RoleStoreValidationWrapper store1 = new RoleStoreValidationWrapper(roleStore1);
try {
store.addRole(store.createRoleObject("duplicated"));
fail("reserved role name should throw exception");