Exemplo n.º 1
0
 public override void WebInitialize(WebCallContext webContext)
 {
     base.WebInitialize(webContext);
       if (string.IsNullOrWhiteSpace(Settings.RedirectUrl)) {
     // Initialize RedirectUrl; get service base address and set proper redirect URL
     // It is convenient to do it automatically here - so that it works automatically in real world apps, in any environment - test, staging or production.
     var uri = new Uri(webContext.RequestUrl);
     var baseAddress = uri.GetComponents(UriComponents.Scheme | UriComponents.HostAndPort, UriFormat.Unescaped);
     var baseAddressR = baseAddress.Replace("localhost", "127.0.0.1"); //By default we use IP address for local testing, this is required for most oauth servers
     Settings.RedirectUrl = baseAddressR + "/api/oauth_redirect";
       }
 }
Exemplo n.º 2
0
 public override void HandleRequest(WebCallContext context, HttpRequestMessage request)
 {
     var versions = GetIncomingValue(context);
       if (string.IsNullOrWhiteSpace(versions))
     return;
       //Parse
       var arrVersions = versions.Split(',');
       if (arrVersions.Length < 1)
     return;
       int value;
       if (int.TryParse(arrVersions[0], out value))
     context.MinUserSessionVersion = value;
       if (arrVersions.Length > 1 && int.TryParse(arrVersions[1], out value))
     context.MinCacheVersion = value;
 }
Exemplo n.º 3
0
 protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
 {
     //Note: when exception is thrown here, it is not routed to exc filter, everything just crashes,
       // so be careful not to throw anything in controller.Initialize
       base.Initialize(controllerContext);
       try {
     WebContext = WebHelper.GetWebCallContext(this);
     if(WebContext == null)
       return;
     OpContext = WebContext.OperationContext;
     ErrorLog = OpContext.App.GetService<IErrorLogService>();
       } catch(Exception ex) {
     System.Diagnostics.Trace.WriteLine("Exception in controller.Initialize: " + ex.ToLogString());
     if(ErrorLog != null)
       ErrorLog.LogError(ex, OpContext);
       }
 }
Exemplo n.º 4
0
        //Utilities
        protected string GetIncomingValue(WebCallContext context)
        {
            if (!Direction.IsSet(WebTokenDirection.Input)) //it is not input token
            return null;
              switch (this.TokenType) {
            case WebTokenType.Cookie:
              var cookies = context.GetIncomingCookies(this.TokenName);
              if (cookies == null)
            return null;
              if (cookies.Count == 1)
            return cookies[0].Value;
              return string.Join(";", cookies.Select(ck => ck.Value));

            case WebTokenType.Header:
              var values = context.GetIncomingHeader(this.TokenName);
              if (values == null || values.Count == 0)
            return null;
              if (values.Count == 1)
            return values[0];
              return string.Join(";", values);
              }//switch
              return null;
        }
Exemplo n.º 5
0
 public override void HandleResponse(WebCallContext context, HttpResponseMessage response)
 {
     var versions = context.MinUserSessionVersion + "," + context.MinCacheVersion;
       context.OutgoingHeaders.Add(this.TokenName, versions);
 }
Exemplo n.º 6
0
 public static void MarkConfidential(this WebCallContext context)
 {
     context.Flags |= WebCallFlags.Confidential;
 }
Exemplo n.º 7
0
 public virtual void WebInitialize(Web.WebCallContext webContext)
 {
 }
Exemplo n.º 8
0
 public WebCallInfo(EntityApp app, WebCallContextHandlerSettings settings, HttpRequestMessage request) {
   Request = request;
   WebContext = new WebCallContext(request, app.TimeService.UtcNow, app.TimeService.ElapsedMilliseconds, 
       GetIncomingCookies, GetIncomingHeaderValues);
   WebContext.OperationContext = new OperationContext(app, UserInfo.Anonymous, WebContext, settings.ConnectionReuseMode);
   Request.Properties[WebCallContext.WebCallContextKey] = WebContext;
   WebContext.RequestUrl = request.RequestUri.ToString();
   WebContext.HttpMethod = request.Method.ToString().ToUpperInvariant();
   WebContext.RequestSize = request.Content.GetLength();
   //Check if it is one of the sensitive URLs
   var path = request.RequestUri.LocalPath;
   // The only way to get IPaddress it seems is thru use of HttpContext (from ASP.NET host).
   // NOTE: it is available only under ASP.NET/IIS host, not in self-hosting scenario
   var ctxWrapper = WebHelper.GetHttpContextWrapper(request);
   if (ctxWrapper != null) {
     //IIS hosting
     WebContext.Referrer = ctxWrapper.Request.UrlReferrer + string.Empty;
     WebContext.IPAddress = ctxWrapper.Request.UserHostAddress;
   } else {
     //Self hosting
     // webCallContext.IPAddress = "(unknown)"; 
   }
   //Set log level for this call
   WebContext.OperationContext.LogLevel = settings.LogLevel;
 }
Exemplo n.º 9
0
 private Guid? LogError(Exception exception, WebCallContext webCallInfo) {
   if(_errorLog == null)
     return null;
   var id = _errorLog.LogError(exception, webCallInfo.OperationContext);
   return id;
 }
Exemplo n.º 10
0
 public WebCallEventArgs(WebCallContext webContext)
 {
     WebContext = webContext;
 }
Exemplo n.º 11
0
 protected void SetOutgoingValue(WebCallContext context, string value)
 {
     if (!Direction.IsSet(WebTokenDirection.Output)) //it is not output token
     return;
       switch (this.TokenType) {
     case WebTokenType.Cookie:
       context.OutgoingCookies.Add(new System.Net.Cookie(this.TokenName, value));
       return;
     case WebTokenType.Header:
       context.OutgoingHeaders.Add(this.TokenName, value);
       return;
       }//switch
 }
Exemplo n.º 12
0
 public virtual void HandleResponse(WebCallContext context, HttpResponseMessage response)
 {
 }
Exemplo n.º 13
0
 public virtual void HandleRequest(WebCallContext context, HttpRequestMessage request)
 {
 }
Exemplo n.º 14
0
 public static void SetHeaders(this HttpResponseMessage response, WebCallContext webContext) {
   foreach(var kv in webContext.OutgoingHeaders) {
     if (kv.Key.StartsWith("Content-", StringComparison.InvariantCultureIgnoreCase)) {
       if(response.Content == null)
         continue; 
       var headers = response.Content.Headers;
       if (headers.Contains(kv.Key)) headers.Remove(kv.Key);
       headers.Add(kv.Key, kv.Value); 
     } else {
       var headers = response.Headers; 
       if (headers.Contains(kv.Key)) headers.Remove(kv.Key); 
       headers.Add(kv.Key, kv.Value);
     }
   }
 }
Exemplo n.º 15
0
 public void Log(WebCallContext webContext)
 {
     _backgroundSaveService.AddObject(webContext);
 }