private Dictionary <string, AuthPermissions> GetMapForRoute(IHttpRoute route, bool isPublic, List <string> accepted)
        {
            var map = new Dictionary <string, AuthPermissions>();

            var authPermission = new AuthPermissions
            {
                AuthNotRequired = isPublic,
                Accepted        = accepted
            };

            if (route.Constraints.Count == 0)
            {
                map.Add(route.RouteTemplate, authPermission);
                return(map);
            }

            return(GetVerbMapRoute(route, authPermission));
        }
Ejemplo n.º 2
0
        private bool InternalAuthNotRequired(HttpRequestMessage request, out AuthPermissions permissions)
        {
            bool result;

            permissions = null;

            var route = FindRoute(request);

            if (route != null)
            {
                permissions = GetPermissions(route.Route, request);
                if (permissions != null)
                {
                    result = (!permissions.Accepted.Any() && permissions.AuthNotRequired);
                    return(result);
                }
            }
            result = _shouldAllowNotDefined(request);
            return(result);
        }
        private Dictionary <string, AuthPermissions> GetVerbMapRoute(IHttpRoute route, AuthPermissions authPermission)
        {
            var map         = new Dictionary <string, AuthPermissions>();
            var constraints = GetConstraints(route);

            if (constraints.Count > 0)
            {
                foreach (var verb in constraints)
                {
                    if (verb == HttpMethod.Options.Method)
                    {
                        continue;
                    }
                    var key = verb + ":" + route.RouteTemplate;
                    map.Add(key, authPermission);
                }
            }
            else
            {
                map.Add(route.RouteTemplate, authPermission);
            }

            return(map);
        }