use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method deleteRoleTest.
@Test
public void deleteRoleTest() throws Exception {
final String roleName = "roleName";
final Long roleId = 1L;
RoleEntity roleEntity = new RoleEntity(roleName, true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
authorizationUtility.deleteRole(roleId);
Mockito.verify(roleRepository).deleteById(Mockito.any());
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method deleteRoleCustomFalseTest.
@Test
public void deleteRoleCustomFalseTest() {
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
RoleEntity roleEntity = new RoleEntity("name", false);
roleEntity.setId(1L);
Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
try {
authorizationUtility.deleteRole(1L);
fail("Custom parameter of roleEntity set to 'false' did not throw expected AlertForbiddenOperationException.");
} catch (AlertForbiddenOperationException e) {
assertNotNull(e);
}
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method createRoleWithPermissions.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix) {
RoleEntity roleEntity = createRole(roleName, true);
List<PermissionMatrixRelation> permissions = updateRoleOperations(roleEntity, permissionMatrix);
return new UserRoleModel(roleEntity.getId(), roleEntity.getRoleName(), roleEntity.getCustom(), createModelFromPermission(permissions));
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method getRoles.
@Override
@Transactional(readOnly = true)
public Set<UserRoleModel> getRoles() {
List<RoleEntity> roleList = roleRepository.findAll();
Set<UserRoleModel> userRoles = new LinkedHashSet<>();
for (RoleEntity entity : roleList) {
userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId())));
}
return userRoles;
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method updateUserRoles.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void updateUserRoles(Long userId, Collection<UserRoleModel> roles) {
if (null != userId) {
userRoleRepository.bulkDeleteAllByUserId(userId);
if (null != roles && !roles.isEmpty()) {
Collection<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
List<RoleEntity> roleEntities = roleRepository.findRoleEntitiesByRoleNames(roleNames);
List<UserRoleRelation> roleRelations = new LinkedList<>();
for (RoleEntity role : roleEntities) {
roleRelations.add(new UserRoleRelation(userId, role.getId()));
}
userRoleRepository.saveAll(roleRelations);
}
}
}
Aggregations