Пример #1
0
        public override AudienceSpecifiedNotificationBase DeepCloneWithAudience(IAudience audience)
        {
            var result = new AudienceVoidNotification(
                audience);

            return(result);
        }
Пример #2
0
        static IAudience Op <T>(IAudience a, IAudience init)
            where T : class, IAudienceCompounder, new()
        {
            if (a != null)
            {
                if (init is T)
                {
                    var self = init as T;
                    List <IAudience> list = self.Audiences.ToList();
                    if (a is T)
                    {
                        var other = a as T;
                        list.AddRange(other.Audiences);
                    }
                    else
                    {
                        list.Add(a);
                    }

                    self.Audiences = list;
                }
                else
                {
                    return new T {
                               Audiences = new[] { init, a }
                    }
                };
            }
            return(init);
        }
Пример #3
0
        /// <summary>
        /// 新しいインスタンスを生成します。
        /// </summary>
        /// <param name="singer">歌手</param>
        /// <param name="audience">観客</param>
        public House(ILoggerFactory loggerFactory, ISinger singer, IAudience audience)
        {
            _logger = loggerFactory.CreateLogger <House>();

            Singer   = singer;
            Audience = audience;
        }
Пример #4
0
        /// Generated the token in format JWT
        /// </summary>
        /// <param name="data">Data for generated token</param>
        /// <returns>Token generated</returns>
        /// <author> Natalia Ladino - [email protected] </author>
        public string Protect(AuthenticationTicket data)
        {
            string audienceId = data.Properties.Dictionary.ContainsKey(AudiencePropertyKey) ? data.Properties.Dictionary[AudiencePropertyKey] : null;

            if (string.IsNullOrWhiteSpace(audienceId))
            {
                throw new InvalidOperationException(Resources.Message_es.InvalidAudience);
            }

            blAUdience = new BlAudience();
            Audience audience = blAUdience.GetAudienceByClientId(audienceId);

            if (!string.IsNullOrEmpty(audience.Secret))
            {
                string symmetricKeyAsBase64 = audience.Secret;
                var    keyByteArray         = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
                var    signingKey           = new  HmacSigningCredentials(keyByteArray);
                var    issued  = data.Properties.IssuedUtc;
                var    expires = data.Properties.ExpiresUtc;

                var token = new JwtSecurityToken(issuerGenerated, audienceId, data.Identity.Claims, issued.Value.LocalDateTime, expires.Value.LocalDateTime, signingKey);

                var handler = new JwtSecurityTokenHandler();

                var jwt = handler.WriteToken(token);

                return(jwt);
            }
            else
            {
                throw new InvalidOperationException(Resources.Message_es.ExceptionSecret);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AudienceSpecifiedNotificationBase"/> class.
        /// </summary>
        /// <param name="audience">Audience to send the notification to.</param>
        protected AudienceSpecifiedNotificationBase(
            IAudience audience)
        {
            new { audience }.AsArg().Must().NotBeNull();

            this.Audience = audience;
        }
Пример #6
0
        public GetDeliveryChannelConfigsOp DeepCloneWithAudience(IAudience audience)
        {
            var result = new GetDeliveryChannelConfigsOp(
                this.Notification?.DeepClone(),
                audience);

            return(result);
        }
        public GetAudienceResult DeepCloneWithAudience(IAudience audience)
        {
            var result = new GetAudienceResult(
                audience,
                this.Failures?.DeepClone(),
                this.FailureAction.DeepClone());

            return(result);
        }
Пример #8
0
        public PrepareToSendOnChannelOp DeepCloneWithAudience(IAudience audience)
        {
            var result = new PrepareToSendOnChannelOp(
                this.Notification?.DeepClone(),
                audience,
                this.DeliveryChannel?.DeepClone(),
                this.InheritableTags?.DeepClone());

            return(result);
        }
Пример #9
0
        public static IAudience Or(this IAudience a, IAudience b)
        {
            if (a == null)
                throw new ArgumentNullException("a");

            if (a is AudienceBase)
                return (a as AudienceBase).Or(b);

            throw new InvalidOperationException("Type is not supported: " + a.GetType().FullName);
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetDeliveryChannelConfigsOp"/> class.
        /// </summary>
        /// <param name="notification">The notification to send.</param>
        /// <param name="audience">The audience for the notification.</param>
        public GetDeliveryChannelConfigsOp(
            INotification notification,
            IAudience audience)
        {
            new { notification }.AsArg().Must().NotBeNull();
            new { audience }.AsArg().Must().NotBeNull();

            this.Notification = notification;
            this.Audience     = audience;
        }
Пример #11
0
        public ArgonautUser(bool validated, IAudience audience, string validationFailureUserMessage = "")
        {
            if (audience == null)
            {
                this.Validated = false;
            }

            this.Validated = validated;
            this.Audience  = audience;
            this.ValidationFailureUserMessage = validationFailureUserMessage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetAudienceResult"/> class.
        /// </summary>
        /// <param name="audience">The resolved audience.</param>
        /// <param name="failures">The failures that occurred when executing the operation.</param>
        /// <param name="failureAction">The action to take when <paramref name="failures"/> contains one or more elements.</param>
        public GetAudienceResult(
            IAudience audience,
            IReadOnlyCollection <IFailure> failures,
            FailureAction failureAction)
        {
            new { failures }.AsArg().Must().NotContainAnyNullElementsWhenNotNull();
            new { failureAction }.AsArg().Must().NotBeEqualTo(FailureAction.Unknown);

            this.Audience      = audience;
            this.Failures      = failures;
            this.FailureAction = failureAction;
        }
Пример #13
0
        public JWTBuilder(IAudience audience)
        {
            if (audience == null)
            {
                throw new ArgumentNullException(nameof(IAudience));
            }

            _audience = audience;

            this.validationParameters = new JWTValidationParametersGenerator(audience);
            this._standardClaims      = new List <Claim>();
            this._additionalClaims    = new List <Claim>();
        }
Пример #14
0
        public static AudienceNot Not(this IAudience a)
        {
            if (a == null)
            {
                return(null);
            }

            if (a is AudienceBase)
            {
                return((a as AudienceBase).Not());
            }

            throw new InvalidOperationException("Type is not supported: " + a.GetType().FullName);
        }
Пример #15
0
        public static IAudience Or(this IAudience a, IAudience b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }

            if (a is AudienceBase)
            {
                return((a as AudienceBase).Or(b));
            }

            throw new InvalidOperationException("Type is not supported: " + a.GetType().FullName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PrepareToSendOnChannelOp"/> class.
        /// </summary>
        /// <param name="notification">The notification to send.</param>
        /// <param name="audience">The audience for the notification.</param>
        /// <param name="deliveryChannel">The channel on which to deliver the notification.</param>
        /// <param name="inheritableTags">OPTIONAL tags that can be inherited from a prior step in the workflow.  DEFAULT is null, indicating that there was no prior step or that no tags have been established in the workflow.</param>
        public PrepareToSendOnChannelOp(
            INotification notification,
            IAudience audience,
            IDeliveryChannel deliveryChannel,
            IReadOnlyCollection <NamedValue <string> > inheritableTags = null)
        {
            new { notification }.AsArg().Must().NotBeNull();
            new { audience }.AsArg().Must().NotBeNull();
            new { deliveryChannel }.AsArg().Must().NotBeNull();

            this.Notification    = notification;
            this.Audience        = audience;
            this.DeliveryChannel = deliveryChannel;
            this.InheritableTags = inheritableTags;
        }
Пример #17
0
        public static void AddArgonaut(this IServiceCollection services, IAudience audience)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (audience == null)
            {
                throw new ArgumentNullException(nameof(audience));
            }

            var jwtBuilder = new Argonaut.Internal.JWTBuilder(audience);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options => options.TokenValidationParameters = jwtBuilder.validationParameters.SecretAndExpirationDate());
        }
Пример #18
0
        private async Task <GetDeliveryChannelConfigsResult> GetDeliveryChannelConfigsAsync(
            INotification notification,
            IAudience audience)
        {
            GetDeliveryChannelConfigsResult result;

            try
            {
                var getDeliveryChannelConfigsOp = new GetDeliveryChannelConfigsOp(notification, audience);

                result = await this.getDeliveryChannelConfigsProtocol.ExecuteAsync(getDeliveryChannelConfigsOp);

                result.AsOp().Must().NotBeNull(Invariant($"Executing {nameof(GetDeliveryChannelConfigsOp)} should not return null."));
            }
            catch (Exception ex)
            {
                result = new GetDeliveryChannelConfigsResult(null, new[] { new ExceptionThrownFailure(ex.ToString()) }, FailureAction.Stop);
            }

            return(result);
        }
Пример #19
0
        /// <summary>
        /// Configuration of server of authorization
        /// </summary>
        /// <param name="app">Param of current context</param>
        public void ConfigureOAuth(IAppBuilder app)
        {
            blAUdience = new BlAudience();
            List <string> allowedAudienceIds = new List <string>();
            List <IIssuerSecurityTokenProvider> providers = new List <IIssuerSecurityTokenProvider>();

            var             issuer        = ConfigurationManager.AppSettings["issuer"];
            List <Audience> AudiencesList = blAUdience.GetAudiences();

            app.Use <BlAuthenticationMiddleware>(); //Allows override of Invoke OWIN commands ////El objetivo de esta petición es sobreescribir la petición para
            //// invocar el negocio BlAuthenticationMiddleware y retornar el codigo de no autorizado en la generación del token.

            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                //For Dev enviroment only (on production should be AllowInsecureHttp = false)
                AllowInsecureHttp         = bool.Parse(ConfigurationManager.AppSettings["allowInsecureHttp"]),
                TokenEndpointPath         = new PathString(ConfigurationManager.AppSettings["pathToken"]),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(Convert.ToInt16(ConfigurationManager.AppSettings["expiredToken"])),
                Provider          = new BlCustomOAuthProvider(),
                AccessTokenFormat = new BlCustomJwtFormat(issuer)
            };

            // OAuth 2.0 Bearer Access Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions); //// El objetivo de esta instrucción es configurar el servidor de autorización.

            foreach (var validAudience in AudiencesList)
            {
                allowedAudienceIds.Add(validAudience.ClientId);
                providers.Add(new SymmetricKeyIssuerSecurityTokenProvider(issuer, TextEncodings.Base64Url.Decode(validAudience.Secret)));
            }

            // Api controllers with an [Authorize] attribute will be validated with JWT
            app.UseJwtBearerAuthentication(
                new JwtBearerAuthenticationOptions
            {
                AuthenticationMode           = AuthenticationMode.Active,
                AllowedAudiences             = allowedAudienceIds.ToArray(),
                IssuerSecurityTokenProviders = providers.ToArray()
            });
        }
Пример #20
0
        private AuditResult CheckUser(SampleEmployee person, IAudience audience, JSchema schema)
        {
            IList <ValidationError> errors = new List <ValidationError>();

            var userToCheck = person.ToJson();

            //var schema = audience.Schema.GetProviderSpecificSchema(this.Name);

            bool valid = userToCheck.IsValid(schema, out errors);

            // map these to our own error object
            var auditErrors = new List <AuditError>();

            foreach (var error in errors)
            {
                auditErrors.Add(new AuditError(error, audience, this, schema));
            }

            var result = new AuditResult(person, auditErrors);

            return(result);
        }
Пример #21
0
        static IAudience BatchOps(IEnumerable <IAudience> arr, IAudience init, Func <IAudience, IAudience> op)
        {
            IAudience res = init;

            if (arr != null)
            {
                arr = from a in arr where a != null select a;
                if (arr.Count() != 0)
                {
                    foreach (IAudience a in arr)
                    {
                        if (a == null)
                        {
                            continue;
                        }

                        res = op(a);
                    }
                }
            }
            return(res);
        }
Пример #22
0
        private async Task <PrepareToSendOnChannelResult> PrepareToSendOnChannelAsync(
            INotification notification,
            IAudience audience,
            IDeliveryChannel channel,
            IReadOnlyCollection <NamedValue <string> > inheritableTags)
        {
            PrepareToSendOnChannelResult result;

            try
            {
                var prepareToSendOnChannelOp = new PrepareToSendOnChannelOp(notification, audience, channel, inheritableTags);

                result = await this.prepareToSendOnChannelProtocol.ExecuteAsync(prepareToSendOnChannelOp);

                result.AsOp().Must().NotBeNull(Invariant($"Executing {nameof(PrepareToSendOnChannelOp)} should not return null."));
            }
            catch (Exception ex)
            {
                result = new PrepareToSendOnChannelResult(null, new[] { new ExceptionThrownFailure(ex.ToString()) }, PrepareToSendOnChannelFailureAction.DoNotSendOnChannel);
            }

            return(result);
        }
Пример #23
0
        /// <summary>
        /// Validate the request
        /// </summary>
        /// <param name="context">Context of the request</param>
        /// <returns>Request validated</returns>
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            try
            {
                blAUdience = new BlAudience();

                string clientId     = string.Empty;
                string clientSecret = string.Empty;

                if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
                {
                    context.TryGetFormCredentials(out clientId, out clientSecret);
                }

                if (context.ClientId == null)
                {
                    context.SetError("ClienteId_Invalido", Resources.Message_es.InvalidClient);
                    return(Task.FromResult <object>(null));
                }

                Audience audience = blAUdience.GetAudienceByClientId(clientId);

                if (audience == null)
                {
                    context.SetError("ClienteId_Invalido", string.Format(Resources.Message_es.InvalidClient, context.ClientId));
                    return(Task.FromResult <object>(null));
                }

                context.Validated();
                return(Task.FromResult <object>(null));
            }
            catch (Exception ex)
            {
                ExceptionLogging.LogException(ex);
                return(Task.FromResult <object>(null));
            }
        }
Пример #24
0
 public Push(IAudience audience, String alert = null, IEnumerable<BaseAlert> deviceAlerts = null)
     : this(alert, deviceAlerts)
 {
     Audience = audience;
 }
 public virtual AudienceSpecifiedNotificationBase DeepCloneWithAudience(IAudience audience)
 {
     throw new NotImplementedException("This method should be abstract.  It was generated as virtual so that you aren't forced to override it when you create a new model that derives from this model.  It will be overridden in the generated designer file.");
 }
Пример #26
0
 public Persistence(ILogger <Persistence> logger, IDatabase database, IAudience audience)
 {
     _logger   = logger;
     _database = database;
     _audience = audience;
 }
Пример #27
0
 public ProductService(ILogger <ProductService> logger, IMicroKernel kernel, IAudience audience)
 {
     _logger   = logger;
     _kernel   = kernel;
     _audience = audience;
 }
Пример #28
0
 public Push(IAudience audience, String alert = null, IEnumerable <BaseAlert> deviceAlerts = null)
     : this(alert, deviceAlerts)
 {
     Audience = audience;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AudienceVoidNotification"/> class.
 /// </summary>
 /// <param name="audience">The audience.</param>
 public AudienceVoidNotification(
     IAudience audience)
     : base(audience)
 {
 }
Пример #30
0
        static public JWTBuilder New(IAudience options)
        {
            var builder = new JWTBuilder(options);

            return(builder);
        }
Пример #31
0
 public AudienceController(IAudience audienceService, ILogger <AudienceController> logger, IHostingEnvironment env)
 {
     _audienceService = audienceService;
     _logger          = logger;
     _env             = env;
 }
Пример #32
0
 public AuthorizationController(ILogger <AuthorizationController> logger, IAudience audienceService)
 {
     _logger          = logger;
     _audienceService = audienceService;
 }