Search in sources :

Example 6 with RoleDto

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

the class RolesBundleIT method testThatRoleThatAllowsRoleManagementIsPresent.

@Test
public void testThatRoleThatAllowsRoleManagementIsPresent() throws InterruptedException {
    RoleDto role = roleService.getRole(MOTECH_ADMIN);
    assertNotNull(role);
    assertTrue(role.getPermissionNames().contains(PermissionNames.MANAGE_ROLE_AND_PERMISSION_PERMISSION));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) Test(org.junit.Test)

Example 7 with RoleDto

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

the class AuthoritiesServiceImplTest method shouldRetrieveAuthorities.

@Test
public void shouldRetrieveAuthorities() {
    MotechUser user = mock(MotechUser.class);
    RoleDto role = mock(RoleDto.class);
    List<String> roles = Arrays.asList("role1");
    when(user.getRoles()).thenReturn(roles);
    when(motechRoleService.getRole("role1")).thenReturn(role);
    List<String> permissions = Arrays.asList("permission1");
    when(role.getPermissionNames()).thenReturn(permissions);
    List<GrantedAuthority> authorities = authoritiesService.authoritiesFor(user);
    assertThat(authorities.size(), Is.is(1));
    assertThat(authorities.get(0).getAuthority(), Is.is("permission1"));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) MotechUser(org.motechproject.security.domain.MotechUser) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.Test)

Example 8 with RoleDto

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

the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsDeleted.

@Test
public void shouldRefreshUserContextWhenRoleIsDeleted() {
    RoleDto role = new RoleDto("role1", asList("permission1"));
    MotechRole motechRole = mock(MotechRole.class);
    when(motechRole.isDeletable()).thenReturn(true);
    when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
    motechRoleService.deleteRole(role);
    verify(userContextsService).refreshAllUsersContextIfActive();
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) MotechRole(org.motechproject.security.domain.MotechRole) Test(org.junit.Test)

Example 9 with RoleDto

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

the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsUpdated.

@Test
public void shouldRefreshUserContextWhenRoleIsUpdated() {
    RoleDto role = new RoleDto("role1", asList("permission1"));
    MotechRole motechRole = mock(MotechRole.class);
    when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
    motechRoleService.updateRole(role);
    verify(userContextsService).refreshAllUsersContextIfActive();
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) MotechRole(org.motechproject.security.domain.MotechRole) Test(org.junit.Test)

Example 10 with RoleDto

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

the class MotechRoleServiceBundleIT method shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists.

@Test
public void shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists() {
    String roleName = "sameRole";
    motechRoleService.createRole(new RoleDto(roleName, asList("per1", "per2"), false));
    motechRoleService.createRole(new RoleDto(roleName, asList("per3", "per4"), false));
    MotechRole motechRole = rolesDataService.findByRoleName(roleName);
    List<MotechRole> allRoles = rolesDataService.retrieveAll();
    int numberOfRoles = 0;
    for (MotechRole role : allRoles) {
        if (roleName.equalsIgnoreCase(role.getRoleName())) {
            ++numberOfRoles;
        }
    }
    assertEquals(1, numberOfRoles);
    assertEquals("per1", motechRole.getPermissionNames().get(0));
    assertEquals("per2", motechRole.getPermissionNames().get(1));
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) MotechRole(org.motechproject.security.domain.MotechRole) 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