private IMethodExecutor FindAccessorForMethod(List <Type> argumentTypes, object targetObject, IEvaluationContext evaluationContext) { AccessException accessException = null; var methodResolvers = evaluationContext.MethodResolvers; foreach (var methodResolver in methodResolvers) { try { var methodExecutor = methodResolver.Resolve(evaluationContext, targetObject, _name, argumentTypes); if (methodExecutor != null) { return(methodExecutor); } } catch (AccessException ex) { accessException = ex; break; } } var method = FormatHelper.FormatMethodForMessage(_name, argumentTypes); var className = FormatHelper.FormatClassNameForMessage(targetObject is Type type ? type : targetObject.GetType()); if (accessException != null) { throw new SpelEvaluationException(StartPosition, accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(StartPosition, SpelMessage.METHOD_NOT_FOUND, method, className); } }
public void Decide(IPrincipalToken principal, object cntext) { if (!principal.GetGrandedPermission().Contains(cntext as PermissionInfo)) { AccessException ex = new AccessException("无权限") { CheckObject = cntext }; throw ex; } }
private void ThrowSimpleExceptionIfPossible(object value, AccessException ex) { if (ex.InnerException is TargetInvocationException) { var rootCause = ex.InnerException.InnerException; if (rootCause is SystemException exception) { throw exception; } throw new ExpressionInvocationTargetException(StartPosition, "A problem occurred when trying to execute method '" + _name + "' on object of type [" + value.GetType().FullName + "]", rootCause); } }
public (HttpStatusCode, Problem) HandleException(Exception exception) { return(exception switch { WhoAreYouException ex => Handle(ex), AccessException ex => Handle(ex), NotFoundException ex => Handle(ex), ServiceAvailabilityException ex => Handle(ex), ValidationException ex => Handle(ex), SerializationException ex => Handle(ex), ConflictException ex => Handle(ex), _ => Handle(exception), });
private void CheckPermission(PermissionInfoCollection pc, PermissionInfo pinfo, object checkObject, out bool result, bool throwException = true) { result = true; if (!pc.Contains(pinfo)) { result = false; if (throwException) { AccessException ae = new AccessException("there is no access for " + FactoryServices.PrincipalStorageFactory.GetStorage().GetCurrentToken().Name); ae.CheckObject = checkObject; throw ae; } } }
private HttpErrorModel DefineHttpError(Exception exception) { return(exception switch { SignInException _ => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = "Неверный логин / пароль!" }, StatusCode = 400 }, IdentityUserException identityUserExc => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = identityUserExc.Description, Details = identityUserExc.Errors }, StatusCode = 409, NeedToLog = Regex.Matches(identityUserExc.Description, @"\p{IsBasicLatin}").Count > 0 }, AlreadyExistsException alrExistsExc => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = alrExistsExc.ParamName == null ? $"{alrExistsExc.Message} уже существует!" : $"{alrExistsExc.Message} с такми {alrExistsExc.ParamName} уже существует!" }, StatusCode = 400 }, NotFoundException notFoundExc => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = notFoundExc.Description }, StatusCode = 404 }, MissingParametersException missParamsExc => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = "Необходимо заполнить все поля!", Details = missParamsExc.MissingParameters }, StatusCode = 400 }, AccessException accessExc => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = accessExc.Message }, StatusCode = 403 }, _ => new HttpErrorModel { Details = new HttpErrorModel.ErrorDetails { Text = "Неопределенная ошибка сервера!" }, StatusCode = 500 }, });