use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceBundleIT method shouldDeleteDeletableRole.
@Test
public void shouldDeleteDeletableRole() {
motechRoleService.createRole(new RoleDto("Test-Role", asList("permissionA, permissionB"), true));
RoleDto role = motechRoleService.getRole("Test-Role");
assertNotNull(role);
motechRoleService.deleteRole(role);
role = motechRoleService.getRole("Test-Role");
assertNull(role);
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceBundleIT method shouldCreateNewRole.
@Test
public void shouldCreateNewRole() {
motechRoleService.createRole(new RoleDto("Test-Role", asList("permissionA", "permissionB"), true));
RoleDto role = motechRoleService.getRole("Test-Role");
assertNotNull(role);
assertEquals("Test-Role", role.getRoleName());
assertTrue(role.getPermissionNames().contains("permissionA"));
assertTrue(role.getPermissionNames().contains("permissionB"));
assertTrue(role.isDeletable());
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceBundleIT method shouldRefreshMultipleSessionsOnRoleUpdates.
@Test
public void shouldRefreshMultipleSessionsOnRoleUpdates() throws IOException, InterruptedException {
// create a role
motechRoleService.createRole(new RoleDto("Role1", asList("permissionA", "permissionB"), true));
RoleDto role = motechRoleService.getRole("Role1");
assertNotNull(role);
// create a second user
motechUserService.register("duke", "password", "email", "1234", asList("Role1"), Locale.ENGLISH);
// admin login through HTTP
login();
// just start a session
HttpClient httpClient = HttpClients.createDefault();
httpClient.execute(new HttpGet(String.format("http://localhost:%d/server/motech-platform-server/", TestContext.getJettyPort())));
// add a permission to the role
role.getPermissionNames().add("newPermission");
motechRoleService.updateRole(role);
// verify that the role was updated and the user still has it
role = motechRoleService.getRole("Role1");
assertNotNull(role);
assertEquals(asList("permissionA", "permissionB", "newPermission"), role.getPermissionNames());
UserDto user = motechUserService.getUser("duke");
assertNotNull(user);
assertEquals(asList("Role1"), user.getRoles());
// remove the role from the user so we can delete it
user.setRoles(new ArrayList<String>());
motechUserService.updateUserDetailsWithoutPassword(user);
// delete the role and make sure that it's gone
motechRoleService.deleteRole(role);
role = motechRoleService.getRole("Role1");
assertNull(role);
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MenuBuilderTest method setUpPermissions.
private void setUpPermissions() {
RoleDto emailRoleDto = new RoleDto("emailRole", Arrays.asList("emailPerm", "emailPerm2", "emailPerm3"));
when(roleService.getRole("emailRole")).thenReturn(emailRoleDto);
RoleDto adminRoleDto = new RoleDto("adminRole", Arrays.asList("adminPerm"));
when(roleService.getRole("adminRole")).thenReturn(adminRoleDto);
RoleDto schedulerRoleDto = new RoleDto("schedulerRole", Arrays.asList("schedulerPerm", "test"));
when(roleService.getRole("schedulerRole")).thenReturn(schedulerRoleDto);
RoleDto mdsRoleDto = new RoleDto("mdsRole", Arrays.asList("viewMds"));
when(roleService.getRole("mdsRole")).thenReturn(mdsRoleDto);
RoleDto mcRoleDto = new RoleDto("mdsRole", Arrays.asList("viewCampaign"));
when(roleService.getRole("mcRole")).thenReturn(mcRoleDto);
RoleDto viewRestRole = new RoleDto("viewRestRole", Collections.singletonList("viewRestApi"));
when(roleService.getRole("viewRestRole")).thenReturn(viewRestRole);
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MenuBuilderTest method setUpToTestAccessControlledSubMenuLinks.
private void setUpToTestAccessControlledSubMenuLinks(boolean addSubMenuWithoutAccessControl) {
ModuleRegistrationData fooRegData = new ModuleRegistrationData("foo", "foo");
Map<String, SubmenuInfo> subMenuMap = new HashMap<>();
SubmenuInfo subMenuWithAccessForUserFoo = new SubmenuInfo("#/foo");
subMenuWithAccessForUserFoo.setRoleForAccess("foo");
SubmenuInfo subMenuWithAccessForUserBar = new SubmenuInfo("#/bar");
subMenuWithAccessForUserBar.setRoleForAccess("bar");
SubmenuInfo subMenuWithoutAccessControl = new SubmenuInfo("#/random");
subMenuMap.put("Foo", subMenuWithAccessForUserFoo);
subMenuMap.put("Bar", subMenuWithAccessForUserBar);
if (addSubMenuWithoutAccessControl) {
subMenuMap.put("Random", subMenuWithoutAccessControl);
}
fooRegData.setSubMenu(subMenuMap);
fooRegData.setBundle(bundle);
ModuleRegistrations modules = new ModuleRegistrations();
modules.setModulesWithSubMenu(Arrays.asList(fooRegData));
when(uiFrameworkService.getRegisteredModules()).thenReturn(modules);
RoleDto fooRole = new RoleDto("fooRole", Arrays.asList("foo"));
RoleDto someOtherRole = new RoleDto("someOtherRole", Arrays.asList("someOtherPermission"));
when(roleService.getRole("fooRole")).thenReturn(fooRole);
when(roleService.getRole("someOtherRole")).thenReturn(someOtherRole);
}
Aggregations