Search in sources :

Example 1 with RoleDto

use of org.motechproject.security.model.RoleDto in project motech by motech.

the class RoleControllerSecurityContextIT method shouldAllowRoleUpdateWithoutException.

@Test
public void shouldAllowRoleUpdateWithoutException() {
    login(USER_WITH_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
    roleController.updateRole(new RoleDto());
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 2 with RoleDto

use of org.motechproject.security.model.RoleDto in project motech by motech.

the class RoleControllerSecurityContextIT method shouldNotAllowRoleUpdate.

@Test(expected = AccessDeniedException.class)
public void shouldNotAllowRoleUpdate() {
    login(USER_WITHOUT_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
    roleController.updateRole(new RoleDto("someRole", Collections.<String>emptyList()));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 3 with RoleDto

use of org.motechproject.security.model.RoleDto in project motech by motech.

the class RoleControllerSecurityContextIT method shouldDenyRoleCreation.

@Test(expected = AccessDeniedException.class)
public void shouldDenyRoleCreation() {
    login(USER_WITHOUT_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
    roleController.saveRole(new RoleDto());
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 4 with RoleDto

use of org.motechproject.security.model.RoleDto in project motech by motech.

the class SecurityRoleLoaderTest method shouldUpdateExistingRoles.

@Test
public void shouldUpdateExistingRoles() throws IOException {
    when(roleService.getRole("Test Role")).thenReturn(new RoleDto("Test Role", Collections.<String>emptyList(), false));
    when(applicationContext.getResource("roles.json")).thenReturn(resource);
    when(applicationContext.getBean(BundleContext.class)).thenReturn(bundleContext);
    when(resource.exists()).thenReturn(true);
    try (InputStream in = getClass().getClassLoader().getResourceAsStream("roles.json")) {
        when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(in)));
    }
    securityRoleLoader.loadRoles(applicationContext);
    verify(roleService).getRole("Test Role");
    ArgumentCaptor<RoleDto> roleCaptor = ArgumentCaptor.forClass(RoleDto.class);
    verify(roleService).updateRole(roleCaptor.capture());
    assertEquals("Test Role", roleCaptor.getValue().getRoleName());
    assertEquals(asList("perm1", "perm2"), roleCaptor.getValue().getPermissionNames());
    ArgumentCaptor<PermissionDto> permissionCaptor = ArgumentCaptor.forClass(PermissionDto.class);
    verify(permissionService, times(2)).addPermission(permissionCaptor.capture());
    verifyPermission("perm1", SYMBOLIC_NAME, permissionCaptor.getAllValues().get(0));
    verifyPermission("perm2", SYMBOLIC_NAME, permissionCaptor.getAllValues().get(1));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 5 with RoleDto

use of org.motechproject.security.model.RoleDto in project motech by motech.

the class RoleControllerTest method shouldGetRoleDetailsGivenItsName.

@Test
public void shouldGetRoleDetailsGivenItsName() throws Exception {
    String roleName = "foo";
    RoleDto role = new RoleDto(roleName, Arrays.asList("permission1"));
    when(roleService.getRole(roleName)).thenReturn(role);
    mockMvc.perform(get(String.format("/web-api/roles/role/%s", roleName))).andExpect(status().isOk()).andExpect(content().string("{\"roleName\":\"foo\",\"originalRoleName\":\"foo\",\"permissionNames\":[\"permission1\"],\"deletable\":false}"));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

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