示例#1
0
        private async Task HandleAuthorized(
            string[] appPermissionsOrRoles, string[] delegatedPermissions, string objectId,
            AuthorizationHandlerContext context, AnyValidPermissionRequirement requirement
            )
        {
            var user = await _usersRepository.GetAUser(objectId);

            if (user == null)
            {
                SetExceptionMessageToHttpContext("Object Id is not in Database!");
                context.Fail();
                return;
            }

            if (IsRoleAdminOrManager(appPermissionsOrRoles))
            {
                if (IsUserAdminInDatabase(user))
                {
                    BuildExceptionMessage(_stringBuilderAdmin, "Admin Logged In:");
                    HandleAuthorized(IsScopeAdmin(delegatedPermissions), _stringBuilderAdmin, context, requirement);
                    return;
                }
                else if (IsUserManagerOnlyInDatabase(user))
                {
                    var projectNumbers = await _projectsRepository.GetAllProjectNumbersOfManager(objectId);

                    BuildExceptionMessage(_stringBuilderAdmin, "Project Manager Logged In:");
                    HandleAuthorized(await IsAuthorizedManager(delegatedPermissions, user, objectId, projectNumbers), _stringBuilderAdmin, context, requirement);
                    return;
                }
            }
            else if (IsRoleRegular(appPermissionsOrRoles))
            {
                BuildExceptionMessage(_stringBuilderRegular, "Regular Logged In:");
                HandleAuthorized(IsAuthorizedRegular(delegatedPermissions, user, objectId), _stringBuilderRegular, context, requirement);
                return;
            }
            else
            {
                SetExceptionMessageToHttpContext("Cannot happen!!!");
                context.Fail();
                return;
            }
        }