Search in sources :

Example 6 with UserRoleModel

use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.

the class DefaultRoleAccessorTest method getRolesTest.

@Test
public void getRolesTest() {
    RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
    roleEntity.setId(1L);
    Mockito.when(roleRepository.findAll()).thenReturn(List.of(roleEntity));
    DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
    Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles();
    UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
    assertEquals(1, userRoleModelsSet.size());
    assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
Also used : RoleEntity(com.synopsys.integration.alert.database.user.RoleEntity) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Test(org.junit.jupiter.api.Test)

Example 7 with UserRoleModel

use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.

the class DefaultRoleAccessorTest method getRolesByRoleIdsTest.

@Test
public void getRolesByRoleIdsTest() {
    RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
    roleEntity.setId(1L);
    Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
    DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
    Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles(List.of(1L));
    UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
    assertEquals(1, userRoleModelsSet.size());
    assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
Also used : RoleEntity(com.synopsys.integration.alert.database.user.RoleEntity) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Test(org.junit.jupiter.api.Test)

Example 8 with UserRoleModel

use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel 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));
}
Also used : RoleEntity(com.synopsys.integration.alert.database.user.RoleEntity) PermissionMatrixRelation(com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with UserRoleModel

use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.

the class RoleActionsTest method updateTest.

@Test
public void updateTest() throws Exception {
    String newRoleName = "newRoleName";
    Long longId = 1L;
    PermissionModel permissionModel = createPermissionModel();
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, newRoleName, Set.of(permissionModel));
    UserRoleModel userRoleModel = new UserRoleModel(longId, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
    Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
    Mockito.when(roleAccessor.getRoles()).thenReturn(Set.of());
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.update(1L, rolePermissionModel);
    Mockito.verify(authorizationManager).updateRoleName(Mockito.eq(longId), Mockito.eq(newRoleName));
    Mockito.verify(authorizationManager).updatePermissionsForRole(Mockito.anyString(), Mockito.any());
    assertTrue(rolePermissionModelActionResponse.isSuccessful());
    assertFalse(rolePermissionModelActionResponse.hasContent());
    assertEquals(HttpStatus.NO_CONTENT, rolePermissionModelActionResponse.getHttpStatus());
}
Also used : UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Test(org.junit.jupiter.api.Test)

Example 10 with UserRoleModel

use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.

the class RoleActionsTest method getOneTest.

@Test
public void getOneTest() {
    PermissionModel permissionModel = createPermissionModel();
    UserRoleModel userRoleModel = new UserRoleModel(1L, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
    Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.getOne(1L);
    assertTrue(rolePermissionModelActionResponse.isSuccessful());
    assertTrue(rolePermissionModelActionResponse.hasContent());
    assertEquals(HttpStatus.OK, rolePermissionModelActionResponse.getHttpStatus());
}
Also used : UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Test(org.junit.jupiter.api.Test)

Aggregations

UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)36 Test (org.junit.jupiter.api.Test)24 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)17 UserRoleRelation (com.synopsys.integration.alert.database.user.UserRoleRelation)8 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)7 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)4 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)4 AuthenticationType (com.synopsys.integration.alert.common.enumeration.AuthenticationType)4 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)4 LinkedHashSet (java.util.LinkedHashSet)4 Transactional (org.springframework.transaction.annotation.Transactional)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 RoleAccessor (com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor)3 DefaultUserRole (com.synopsys.integration.alert.common.enumeration.DefaultUserRole)3 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)3 UserAccessor (com.synopsys.integration.alert.common.persistence.accessor.UserAccessor)3 AuthenticationTypeDetails (com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails)3 Collection (java.util.Collection)3