コード例 #1
0
        private static void RoleValidation(int roleId, HttpActionContext actionContext)
        {
            var actionName     = actionContext.ActionDescriptor.ActionName;
            var controllerName = actionContext.ControllerContext.ControllerDescriptor.ControllerName;
            var roleConfigurationRepository = SimpleInjectorModule.GetContainer().GetInstance <IRoleConfigurationRepository>();

            var permissionType = new PermissionType().GetValue(controllerName);
            var roleConfigsValidatePermission = roleConfigurationRepository.FindBy(roleConfig => roleConfig.RoleId == roleId && roleConfig.PermissionId == permissionType);

            if (roleConfigsValidatePermission.IsEmpty())
            {
                ExceptionExtensions.ThrowCustomException(HttpStatusCode.Forbidden, "No tienes permisos");
            }

            var accessLevelType = new AccessLevelType().GetValue(actionName);
            var roleConfigsValidateAccesLevel = roleConfigsValidatePermission.FirstOrDefault(roleConfig => roleConfig.PermissionId == permissionType && roleConfig.AccessLevelId == accessLevelType);

            if (roleConfigsValidateAccesLevel.IsNull())
            {
                ExceptionExtensions.ThrowCustomException(HttpStatusCode.Forbidden, "No tienes nivel de acceso");
            }
        }
コード例 #2
0
 public AccessLevelAttribute(AccessLevelType levelType)
 {
     this.LevelType = levelType;
 }