Beispiel #1
0
 public TestCommand(
     IAuthorizationFacade authorization,
     CommandAttribute commandAttribute,
     AuthorizeAttribute[] authorizeAttributes,
     string[] aliasNames,
     IReadOnlyList <ParameterDefinition> parameters)
     : base(authorization, commandAttribute, authorizeAttributes, aliasNames, parameters)
 {
 }
Beispiel #2
0
 #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
 public AuthorizationMiddleware(
 #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
     RequestDelegate next,
     ILogger logger,
     IAuthorizationFacade auth,
     ApiSettings settings)
 {
     _next               = next;
     _logger             = logger;
     _authorizationLogic = auth;
     _settings           = settings;
 }
        public AuthorizationUnitTests()
        {
            var settings = new ApiSettings
            {
                BlipBotSettings = new BlipBotSettings
                {
                    Authorization = "allowed-authorization"
                }
            };

            _authorizationFacade = new AuthorizationFacade(settings);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandlerCommand"/> class.
        /// </summary>
        /// <param name="authorization">Service that determines if the user has access.</param>
        /// <param name="attribute">General attribute that describes this command.</param>
        /// <param name="authorizeAttributes">Attributes attached to this command.</param>
        /// <param name="aliasNames">Alias names which are also available.</param>
        /// <param name="parameters">Parameter information about this command.</param>
        /// <param name="executor">Executor action to trigger the command.</param>
        public HandlerCommand(
            IAuthorizationFacade authorization,
            CommandAttribute attribute,
            AuthorizeAttribute[] authorizeAttributes,
            string[] aliasNames,
            IReadOnlyList <ParameterDefinition> parameters,
            Func <object[], object> executor)
            : base(authorization, attribute, authorizeAttributes, aliasNames, parameters)
        {
            Guard.Argument(executor, nameof(executor)).NotNull();

            this.executor = executor;
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command"/> class.
        /// </summary>
        /// <param name="attribute">Attribute that describes this command.</param>
        /// <param name="authorizeAttributes">Authorize attributes attached to this command.</param>
        /// <param name="aliasNames">Available alias names of this command.</param>
        /// <param name="parameters">List of parameters of this command.</param>
        /// <param name="authorization">Service used to check if an executor is able to use a command.</param>
        /// <exception cref="ArgumentNullException"><paramref name="attribute"/>, <paramref name="aliasNames"/>, <paramref name="parameters"/> or <paramref name="authorization"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameters"/> or <paramref name="aliasNames"/>contains null.</exception>
        protected Command(
            IAuthorizationFacade authorization,
            CommandAttribute attribute,
            AuthorizeAttribute[] authorizeAttributes,
            string[] aliasNames,
            IReadOnlyList <ParameterDefinition> parameters)
        {
            Guard.Argument(attribute, nameof(attribute)).NotNull();
            Guard.Argument(aliasNames, nameof(aliasNames)).NotNull().DoesNotContainNull();
            Guard.Argument(parameters, nameof(parameters)).NotEmpty().NotNull().DoesNotContainNull();
            Guard.Argument(authorization, nameof(authorization)).NotNull();
            Guard.Argument(authorizeAttributes, nameof(authorizeAttributes)).NotNull().DoesNotContainNull();
            Guard.Argument(parameters.Select(x => x.Name), nameof(parameters)).DoesNotContainDuplicate((_, _) => "All parameter names need to be unique.");

            if (parameters.Count >= 1 && parameters[0].Type != typeof(IPlayer))
            {
                throw new ArgumentException(
                          "The first entry has to have the player as parameter.",
                          nameof(parameters));
            }

            this.authorization       = authorization;
            this.authorizeAttributes = authorizeAttributes;

            var lastDefault = false;

            foreach (var definition in parameters)
            {
                if (lastDefault && definition.HasDefault == false)
                {
                    throw new ArgumentException(
                              $"There cannot be a parameter with no default value after a parameter with default value.",
                              nameof(parameters));
                }

                lastDefault = definition.HasDefault;
            }

            this.Name        = attribute.Name;
            this.AliasNames  = aliasNames;
            this.Group       = attribute.Group;
            this.Parameters  = parameters;
            this.Description = attribute.Description ?? string.Empty;

            this.MinimalArgumentAmount = this.Parameters.Count(x => x.HasDefault == false);
            this.HelpSignature         = this.BuildHelpSignature();
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandFactory"/> class.
        /// </summary>
        /// <param name="authorization">Service that determines if a certain command can be executed.</param>
        public CommandFactory(IAuthorizationFacade authorization)
        {
            Guard.Argument(authorization, nameof(authorization)).NotNull();

            this.authorization = authorization;
        }
Beispiel #7
0
 public AcceptAllPermissionStarter(IAuthorizationFacade authorizationFacade)
 {
     this.authorizationFacade = authorizationFacade;
 }
Beispiel #8
0
 public RconPermissionSampExtensionStarter(IAuthorizationFacade authorizationFacade)
 {
     this.authorizationFacade = authorizationFacade;
 }
Beispiel #9
0
 public UserController(IAuthorizationFacade facade)
 {
     _facade = facade;
 }