Search in sources :

Example 26 with RoleDto

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);
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 27 with RoleDto

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());
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 28 with RoleDto

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);
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 29 with RoleDto

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);
}
Also used : RoleDto(org.motechproject.security.model.RoleDto)

Example 30 with RoleDto

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);
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) ModuleRegistrations(org.motechproject.osgi.web.util.ModuleRegistrations) HashMap(java.util.HashMap) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData) SubmenuInfo(org.motechproject.osgi.web.SubmenuInfo)

Aggregations

RoleDto (org.motechproject.security.model.RoleDto)30 Test (org.junit.Test)21 PermissionDto (org.motechproject.security.model.PermissionDto)5 InputStream (java.io.InputStream)3 MotechRole (org.motechproject.security.domain.MotechRole)3 MotechUser (org.motechproject.security.domain.MotechUser)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)1 SubmenuInfo (org.motechproject.osgi.web.SubmenuInfo)1 ModuleRegistrations (org.motechproject.osgi.web.util.ModuleRegistrations)1 MotechPermission (org.motechproject.security.domain.MotechPermission)1