Search in sources :

Example 1 with PermissionDto

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

the class MotechPermissionServiceTest method shouldAddPermissions.

@Test
public void shouldAddPermissions() {
    PermissionDto permissionDto = new PermissionDto("permName", "bundleName");
    permissionService.addPermission(permissionDto);
    ArgumentCaptor<MotechPermission> captor = ArgumentCaptor.forClass(MotechPermission.class);
    verify(motechPermissionsDataService).create(captor.capture());
    assertEquals("permName", captor.getValue().getPermissionName());
    assertEquals("bundleName", captor.getValue().getBundleName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 2 with PermissionDto

use of org.motechproject.security.model.PermissionDto 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 3 with PermissionDto

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

the class MotechPermissionServiceBundleIT method shouldNotCreateNewPermissionIfPermissionAlreadyExists.

@Test
public void shouldNotCreateNewPermissionIfPermissionAlreadyExists() {
    final String permissionName = "samePersmission";
    permissionService.addPermission(new PermissionDto(new MotechPermission(permissionName, "test1")));
    permissionService.addPermission(new PermissionDto(new MotechPermission(permissionName, "test2")));
    PermissionDto motechPermission = permissionService.findPermissionByName(permissionName);
    List<MotechPermission> allPermission = permissionsDataService.retrieveAll();
    int numberOfPermissionWithSameName = 0;
    for (MotechPermission permission : allPermission) {
        if (permissionName.equalsIgnoreCase(permission.getPermissionName())) {
            ++numberOfPermissionWithSameName;
        }
    }
    assertEquals(1, numberOfPermissionWithSameName);
    assertEquals("test1", motechPermission.getBundleName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 4 with PermissionDto

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

the class MotechPermissionServiceBundleIT method shouldFindByPermissionName.

@Test
public void shouldFindByPermissionName() {
    permissionsDataService.create(new MotechPermission("testPermission", "testBundle"));
    PermissionDto testPermission = permissionService.findPermissionByName("testPermission");
    assertEquals("testPermission", testPermission.getPermissionName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 5 with PermissionDto

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

the class Initialize method prepareStartupPermissions.

/**
 * Creates and adds all necessary startup permissions
 */
private void prepareStartupPermissions() {
    // Web Security module
    PermissionDto manageUserPermission = new PermissionDto(MANAGE_USER_PERMISSION, WEB_SECURITY);
    PermissionDto manageRoleAndPermissionPermission = new PermissionDto(MANAGE_ROLE_AND_PERMISSION_PERMISSION, WEB_SECURITY);
    PermissionDto manageURLPermission = new PermissionDto(MANAGE_URL_PERMISSION, WEB_SECURITY);
    permissionService.addPermission(manageUserPermission);
    permissionService.addPermission(manageRoleAndPermissionPermission);
    permissionService.addPermission(manageURLPermission);
    // MDS module
    PermissionDto mdsSchemaAccess = new PermissionDto(MDS_SCHEMA_ACCESS_PERMISSION, MDS_MODULE);
    PermissionDto mdsSettingsAccess = new PermissionDto(MDS_SETTINGS_ACCESS_PERMISSION, MDS_MODULE);
    PermissionDto mdsDataAccess = new PermissionDto(MDS_DATA_ACCESS_PERMISSION, MDS_MODULE);
    permissionService.addPermission(mdsSchemaAccess);
    permissionService.addPermission(mdsSettingsAccess);
    permissionService.addPermission(mdsDataAccess);
    // Email module
    PermissionDto viewEmailLogs = new PermissionDto(VIEW_BASIC_EMAIL_LOGS_PERMISSION, EMAIL);
    PermissionDto viewDetailedLogs = new PermissionDto(VIEW_DETAILED_EMAIL_LOGS_PERMISSION, EMAIL);
    permissionService.addPermission(viewEmailLogs);
    permissionService.addPermission(viewDetailedLogs);
}
Also used : PermissionDto(org.motechproject.security.model.PermissionDto)

Aggregations

PermissionDto (org.motechproject.security.model.PermissionDto)10 Test (org.junit.Test)7 RoleDto (org.motechproject.security.model.RoleDto)5 MotechPermission (org.motechproject.security.domain.MotechPermission)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Before (org.junit.Before)2