상속: GenericPrincipal
예제 #1
0
        /// <summary>
        /// Builds a repository settings object based on the request and request context. Sets up the prefer values, APIM source etc
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static RepositorySettings BuildRepositorySettings(HttpRequestContext requestContext, HttpRequestMessage request)
        {
            var settings = new RepositorySettings();

            IEnumerable <string> preferValues;

            //See: http://tools.ietf.org/html/rfc7240
            if (request.Headers.TryGetValues("Prefer", out preferValues))
            {
                var preferences = preferValues.First().Split(',');

                foreach (var keyValuePair in preferences.Select(p => p.Split('=')).Where(kvp => kvp.Length > 1))
                {
                    settings.Prefer.Add(keyValuePair[0].Trim(), keyValuePair[1].Trim());
                }
            }

            AddHeader(request, settings, ApimConstants.AzureSubscriptionKeyHeader);

            ApimPrincipal principal = requestContext.Principal as ApimPrincipal;

            if (principal != null)
            {
                var identity = principal.Identity as ApimIdentity;
                if (identity != null)
                {
                    settings.Source     = identity.Source;
                    settings.SourceId   = identity.Id;
                    settings.SourceName = identity.Name;
                }
            }

            return(settings);
        }
예제 #2
0
 public bool TryGetValue(string subscriptionId, out ApimPrincipal principal)
 {
     return(mPrincipals.TryGetValue(subscriptionId, out principal));
 }