예제 #1
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            IFoundation iFoundation     = CoreFoundation.Current;
            Account     account         = null;
            bool        isPreAuthorized = base.AuthorizeCore(httpContext);

            // already verified
            if (httpContext.Items.Contains(CURRENT_ACCOUNT_HTTP_CONTEXT_KEY))
            {
                return(true);
            }

            if (isPreAuthorized)
            {
                StencilFormsAuthorizer authorizer = iFoundation.Resolve <StencilFormsAuthorizer>();
                account = authorizer.Authorize(httpContext.User.Identity.Name);
            }
            if (account == null)
            {
                // try with headers or QS
                NameValueCollection query = httpContext.Request.QueryString;
                string key       = query[API_PARAM_KEY];
                string signature = query[API_PARAM_SIG];

                // from headers
                string value = httpContext.Request.Headers[API_PARAM_KEY];
                if (!string.IsNullOrEmpty(value))
                {
                    key = value;
                }
                value = httpContext.Request.Headers[API_PARAM_SIG];
                if (!string.IsNullOrEmpty(value))
                {
                    signature = value;
                }
                StencilHashedTimeSignatureAuthorizer authorizer = iFoundation.Resolve <StencilHashedTimeSignatureAuthorizer>();
                account = authorizer.Authorize(key, signature);
            }

            if (account != null)
            {
                httpContext.Items[CURRENT_ACCOUNT_HTTP_CONTEXT_KEY] = account;
                try
                {
                    ApiIdentity apiIdentity = new ApiIdentity(account.account_id, string.Format("{0} {1}", account.first_name, account.last_name));
                    var         context     = HttpContext.Current;
                    if (context != null)
                    {
                        context.User = new GenericPrincipal(apiIdentity, new string[0]);
                    }
                }
                catch (Exception ex)
                {
                    iFoundation.LogError(ex, "HttpContext.Current.Account");
                }
                return(true);
            }

            return(false);
        }
예제 #2
0
 /// <summary>
 /// Creates a SynchronizerBase
 /// </summary>
 /// <param name="foundation"></param>
 /// <param name="entityName">Used to notify health system which entity this synchronizer references</param>
 public SynchronizerBase(IFoundation foundation, string entityName, int synchronousTimeoutMilliseconds = 5000)
     : base(foundation, foundation.Resolve <IHandleExceptionProvider>(Assumptions.SWALLOWED_EXCEPTION_HANDLER))
 {
     this.EntityName = entityName;
     this.SynchronousTimeoutMilliseconds         = synchronousTimeoutMilliseconds;
     this.SynchronousCriticalTimeoutMilliseconds = CRITICAL_SYNC_TIMEOUT_MILLISECONDS;
     this.API = foundation.Resolve <StencilAPI>();
 }
예제 #3
0
 public BusinessBase(IFoundation foundation, string trackPrefix)
     : base(foundation, trackPrefix)
 {
     this.DataContextFactory = foundation.Resolve <IStencilContextFactory>();
     this.API = new StencilAPI(foundation);
     this.SharedCacheStatic15 = new AspectCache("BusinessBase", foundation, new ExpireStaticLifetimeManager("BusinessBase", TimeSpan.FromMinutes(15)));
 }
예제 #4
0
 public AzurePushNotifier(IFoundation iFoundation)
     : base(iFoundation)
 {
     this.API   = iFoundation.Resolve <StencilAPI>();
     this.Cache = new AspectCache("AzurePushNotifier", iFoundation, new ExpireStaticLifetimeManager("AzurePushNotifier.Life15", System.TimeSpan.FromMinutes(15), false));
     try
     {
         // known to have bad config in debug
         this.HubClient = NotificationHubClient.CreateClientFromConnectionString(this.AzurePush_Connection, this.AzurePush_HubName);
     }
     catch (Exception ex)
     {
         iFoundation.LogError(ex, "AzurePushNotifier");
     }
 }
 public AccountLoggedInWorker(IFoundation iFoundation)
     : base(iFoundation, WORKER_NAME)
 {
     this.API = iFoundation.Resolve <StencilAPI>();
 }
예제 #6
0
        public bool AuthorizedRequest(HttpActionContext actionContext)
        {
            IFoundation iFoundation     = CoreFoundation.Current; //weak usage of CoreFoundation.Current
            Account     account         = null;
            bool        isPreAuthorized = base.IsAuthorized(actionContext);

            // already verified [same request?]
            if (actionContext.Request.Properties.ContainsKey(CURRENT_ACCOUNT_HTTP_CONTEXT_KEY))
            {
                return(true);
            }


            if (isPreAuthorized)
            {
                StencilFormsAuthorizer authorizer = iFoundation.Resolve <StencilFormsAuthorizer>();
                account = authorizer.Authorize(actionContext.RequestContext.Principal.Identity.Name);
            }

            if (account == null)
            {
                NameValueCollection query = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.ToString());

                // from query string
                string key       = query[API_PARAM_KEY];
                string signature = query[API_PARAM_SIG];

                // from headers
                if (actionContext.Request.Headers.Contains(API_PARAM_KEY))
                {
                    string value = actionContext.Request.Headers.GetValues(API_PARAM_KEY).FirstOrDefault();
                    if (!string.IsNullOrEmpty(value))
                    {
                        key = value;
                    }
                }
                if (actionContext.Request.Headers.Contains(API_PARAM_SIG))
                {
                    string value = actionContext.Request.Headers.GetValues(API_PARAM_SIG).FirstOrDefault();
                    if (!string.IsNullOrEmpty(value))
                    {
                        signature = value;
                    }
                }
                StencilHashedTimeSignatureAuthorizer authorizer = iFoundation.Resolve <StencilHashedTimeSignatureAuthorizer>();
                account = authorizer.Authorize(key, signature);
            }

            if (account != null)
            {
                actionContext.Request.Properties[CURRENT_ACCOUNT_HTTP_CONTEXT_KEY] = account;
                try
                {
                    ApiIdentity apiIdentity = new ApiIdentity(account.account_id, string.Format("{0} {1}", account.first_name, account.last_name));
                    var         context     = HttpContext.Current;
                    if (context != null)
                    {
                        context.User = new GenericPrincipal(apiIdentity, new string[0]);
                    }
                }
                catch (Exception ex)
                {
                    iFoundation.LogError(ex, "HttpContext.Current.User");
                }
                string platform = string.Empty;
                try
                {
                    if (actionContext.Request.Headers.Contains(PARAM_PLATFORM))
                    {
                        string value = actionContext.Request.Headers.GetValues(PARAM_PLATFORM).FirstOrDefault();
                        if (!string.IsNullOrEmpty(value))
                        {
                            platform += value;
                        }
                    }
                    if (actionContext.Request.Headers.Contains(PARAM_VERSION))
                    {
                        string value = actionContext.Request.Headers.GetValues(PARAM_VERSION).FirstOrDefault();
                        if (!string.IsNullOrEmpty(value))
                        {
                            platform += " - v" + value;
                        }
                    }
                }
                catch (Exception ex)
                {
                    iFoundation.LogError(ex, "HttpContext.Current.User");
                }

                AccountLoggedInWorker.EnqueueRequest(iFoundation, new LoggedInRequest()
                {
                    account_id = account.account_id,
                    platform   = platform,
                    login_utc  = DateTime.UtcNow
                });
                return(true);
            }

            return(false);
        }
예제 #7
0
 public IndexerBase(IFoundation iFoundation, string trackPrefix, string documentType)
     : base(iFoundation, iFoundation.Resolve <IHandleExceptionProvider>(Assumptions.SWALLOWED_EXCEPTION_HANDLER), trackPrefix)
 {
     DocumentType = documentType;
     this.API     = new StencilAPI(iFoundation);
 }
예제 #8
0
 public AmazonImageResizeDaemon(IFoundation iFoundation)
     : base(iFoundation)
 {
     this.API   = iFoundation.Resolve <StencilAPI>();
     this.Cache = new AspectCache("AmazonImageResizeDaemon", iFoundation, new ExpireStaticLifetimeManager("AmazonImageResizeDaemon.Life15", System.TimeSpan.FromMinutes(15), false));
 }
예제 #9
0
 public RestApiBaseController(IFoundation iFoundation, IHandleExceptionProvider iHandleExceptionProvider)
     : base(iFoundation, iHandleExceptionProvider)
 {
     this.API = iFoundation.Resolve <StencilAPI>();
 }
예제 #10
0
 public RestApiBaseController(IFoundation iFoundation)
     : base(iFoundation)
 {
     this.API = iFoundation.Resolve <StencilAPI>();
 }
예제 #11
0
 public ElasticSyncNotifySynchronizer(IFoundation foundation)
     : base(foundation)
 {
     this.API   = foundation.Resolve <StencilAPI>();
     this.Cache = new AspectCache("ElasticSyncNotifySynchronizer", foundation, new ExpireStaticLifetimeManager("ElasticSyncNotifySynchronizer.Life15", System.TimeSpan.FromMinutes(15), false));
 }
 public StencilHashedTimeSignatureAuthorizer(IFoundation iFoundation)
     : base(iFoundation)
 {
     this.TimedCache = new AspectCache("StencilHashedTimeSignatureAuthorizer.TimedCache", iFoundation, new ExpireStaticLifetimeManager("StencilHashedTimeSignatureAuthorizer.TimedCache.Static", TimeSpan.FromMinutes(5), false));
     this.API        = iFoundation.Resolve <StencilAPI>();
 }