Exemple #1
0
#pragma warning restore CA1707 // Identifiers should not contain underscores

        /// <summary>
        /// Convertit le modèle <see cref="UserGrant"/> en une <see cref="ResourceGrant"/>.
        /// </summary>
        /// <returns></returns>
        public ResourceGrant ToResourceGrant()
        {
            ResourceGrant result = B_CONSULT ? ResourceGrant.Read : 0;

            result |= B_CREATE ? ResourceGrant.Create : 0;
            result |= B_UPDATE ? ResourceGrant.Update : 0;
            result |= B_DELETE ? ResourceGrant.Delete : 0;
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Appelle le code de vérification d'autorisations.
        /// </summary>
        /// <param name="context"></param>
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            string userId = context.HttpContext.User?.GetEmail();
            // interrogation de la base des habilitations pour obtenir l'ensemble des droits de l'utilisateur sur la ressource en question
            ResourceGrant effectiveGrants = _resourceAuthorizationService.GetGrantsForResource(userId, _resourceName);

            // vérification des droits  de l'utilisateur (provenant de la base habilitations) avec le droit requis pour la ressource  en question
            if (effectiveGrants == ResourceGrant.None || !effectiveGrants.HasFlag(_requiredGrants))
            {
                context.Result = new ForbidResult();
            }
        }
Exemple #3
0
            public void Progress(ResourceGrant resources)
            {
                if (ResourcesStillNeeded <= 0 || building.Deleted)
                {
                    return;
                }

                if (resources.ReachedCapacity)
                {
                    buildProcess     = blueprint.ResourceCost;
                    building.Health += blueprint.MaxHealth - healthGiven;
                    building.onCompleted();
                    return;
                }

                buildProcess += resources.Amount;
                var expectedHealthGiven = (int)(CurrentProgressFraction * blueprint.MaxHealth);

                building.Health += expectedHealthGiven - healthGiven;
                healthGiven      = expectedHealthGiven;
            }
Exemple #4
0
 /// <summary>
 /// Crée une instance de <see cref="ResourceAuthorizeFilter"/> pour la resource et les autorisations spécifiées.
 /// </summary>
 /// <param name="resourceName">Le nom de la ressource.</param>
 /// <param name="requiredGrants">Les autorisations nécessaires sur la ressource.</param>
 /// <param name="resourceAuthorizationService">Le service permettant d'effectuer la vérification.</param>
 public ResourceAuthorizeFilter(string resourceName, ResourceGrant requiredGrants, IResourceAuthorizationService resourceAuthorizationService)
 {
     _resourceName   = resourceName;
     _requiredGrants = requiredGrants;
     _resourceAuthorizationService = resourceAuthorizationService;
 }
 public ResourceAuthorizeAttribute(string resourceName, ResourceGrant requiredGrants) : base(typeof(ResourceAuthorizeFilter))
 {
     Arguments = new object[] { resourceName, requiredGrants };
 }