Search in sources :

Example 36 with UserRoleModel

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

the class RoleActions method updateWithoutChecks.

@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
    try {
        String roleName = resource.getRoleName();
        Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
        if (existingRole.isPresent()) {
            logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
            if (!existingRole.get().getName().equals(roleName)) {
                authorizationManager.updateRoleName(id, roleName);
            }
            Set<PermissionModel> permissions = resource.getPermissions();
            PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
            authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
            logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
            return new ActionResponse<>(HttpStatus.NO_CONTENT);
        }
        logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
        return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
    } catch (AlertException ex) {
        logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

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