Search in sources :

Example 16 with RoleDto

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

the class RoleControllerSecurityContextIT method shouldAllowRoleDeletionWithoutException.

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

Example 17 with RoleDto

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

the class RoleControllerSecurityContextIT method shouldAllowRoleCreationWithoutException.

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

Example 18 with RoleDto

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

the class RoleControllerSecurityContextIT method shouldNotAllowRoleDeletion.

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

Example 19 with RoleDto

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

the class WebSecurityBundleIT method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    PermissionDto permission = new PermissionDto(PERMISSION_NAME, BUNDLE_NAME);
    RoleDto role = new RoleDto(ROLE_NAME, Collections.singletonList(PERMISSION_NAME));
    if (!userService.hasActiveMotechAdmin()) {
        userService.registerMotechAdmin(ADMIN, ADMIN, "aaa@admin.com", Locale.ENGLISH);
    }
    setUpSecurityContext(ADMIN, ADMIN, getPermissions());
    permissionService.addPermission(permission);
    roleService.createRole(role);
    userService.register(USER_NAME, USER_PASSWORD, USER_EMAIL, USER_EXTERNAL_ID, Arrays.asList(ROLE_NAME, MOTECH_ADMIN), USER_LOCALE);
    originalSecurityProxy = getFromContext(MotechProxyManager.class).getFilterChainProxy();
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) PermissionDto(org.motechproject.security.model.PermissionDto) Before(org.junit.Before)

Example 20 with RoleDto

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

the class WebSecurityBundleIT method testWebSecurityServices.

@Test
public void testWebSecurityServices() throws Exception {
    // given
    PermissionDto permission = new PermissionDto(PERMISSION_NAME, BUNDLE_NAME);
    RoleDto role = new RoleDto(ROLE_NAME, Arrays.asList(PERMISSION_NAME));
    // when
    permissionService.addPermission(permission);
    roleService.createRole(role);
    userService.register(USER_NAME, USER_PASSWORD, USER_EMAIL, USER_EXTERNAL_ID, Arrays.asList(ROLE_NAME), USER_LOCALE);
    // then
    assertTrue(String.format("Permission %s has not been saved", PERMISSION_NAME), permissionService.getPermissions().contains(permission));
    assertEquals(String.format("Role %s has not been saved properly", ROLE_NAME), role, roleService.getRole(ROLE_NAME));
    assertNotNull(String.format("User %s has not been registered", USER_NAME), userService.hasUser(USER_NAME));
    assertTrue(String.format("User doesn't have role %s", ROLE_NAME), userService.getRoles(USER_NAME).contains(ROLE_NAME));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) PermissionDto(org.motechproject.security.model.PermissionDto) 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