use of org.motechproject.security.domain.MotechPermission in project motech by motech.
the class MotechPermissionServiceImpl method addPermission.
@Override
@Transactional
public void addPermission(PermissionDto permission) {
LOGGER.info("Adding permission: {} from bundle: {}", permission.getPermissionName(), permission.getBundleName());
add(new MotechPermission(permission.getPermissionName(), permission.getBundleName()));
// the admin role was potentially updated
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Added permission: {} from bundle: {}", permission.getPermissionName(), permission.getBundleName());
}
use of org.motechproject.security.domain.MotechPermission in project motech by motech.
the class Initialize method initialize.
/**
* Initializes module by creating MOTECH Admin role and permissions
*/
@PostConstruct
public void initialize() {
// Create MOTECH Admin role
if (motechRoleService.getRole(MOTECH_ADMIN) == null) {
List<String> permissionsNames = new LinkedList<>();
List<MotechPermission> permissions = permissionsDataService.retrieveAll();
for (MotechPermission permission : permissions) {
permissionsNames.add(permission.getPermissionName());
}
RoleDto adminRole = new RoleDto(MOTECH_ADMIN, permissionsNames, false);
motechRoleService.createRole(adminRole);
}
// initialize startup permission for Admin role
prepareStartupPermissions();
}
use of org.motechproject.security.domain.MotechPermission in project motech by motech.
the class MotechPermissionServiceImpl method deletePermission.
@Override
@Transactional
public void deletePermission(String permissionName) {
LOGGER.info("Deleting permission: {}", permissionName);
MotechPermission permission = permissionsDataService.findByPermissionName(permissionName);
if (permission != null) {
permissionsDataService.delete(permission);
removePermissionFromRoles(permissionName);
userContextsService.refreshAllUsersContextIfActive();
}
LOGGER.info("Deleted permission: {}", permissionName);
}
use of org.motechproject.security.domain.MotechPermission in project motech by motech.
the class MotechPermissionServiceTest method shouldReturnPermissions.
@Test
public void shouldReturnPermissions() {
MotechPermission perm1 = new MotechPermission("perm1", "bundle1");
MotechPermission perm2 = new MotechPermission("perm2", "bundle2");
when(motechPermissionsDataService.retrieveAll()).thenReturn(asList(perm1, perm2));
List<PermissionDto> result = permissionService.getPermissions();
assertNotNull(result);
assertEquals(asList("perm1", "perm2"), extract(result, on(PermissionDto.class).getPermissionName()));
assertEquals(asList("bundle1", "bundle2"), extract(result, on(PermissionDto.class).getBundleName()));
}
use of org.motechproject.security.domain.MotechPermission in project motech by motech.
the class MotechPermissionServiceBundleIT method shouldDeletePermissions.
@Test
public void shouldDeletePermissions() {
permissionsDataService.create(new MotechPermission("testPermission", "testBundle"));
MotechPermission permission = permissionsDataService.findByPermissionName("testPermission");
assertNotNull(permission);
setUpSecurityContextForDefaultUser(PermissionNames.MANAGE_ROLE_AND_PERMISSION_PERMISSION);
// When
permissionService.deletePermission(permission.getPermissionName());
// Then
List<MotechPermission> permissions = permissionsDataService.retrieveAll();
assertTrue("There shouldn't be any permissions, but found: " + permissions.size(), permissions.isEmpty());
}
Aggregations