예제 #1
0
        public IIdentity GetUserIdentity(IHttpRequestDescriptor request)
        {
            var name    = AnyGuestName;
            var auth    = AllowGuest;
            var isadmin = AnyGuestIsAdmin;
            var type    = "guest";
            var guest   = true;

            if (IsLocal(request.LocalEndPoint))
            {
                name    = LocalGuestName;
                auth    = AllowLocalGuest;
                isadmin = LocalGuestIsAdmin;
                type    = "localguest";
            }
            TrustedOrigin origin = null;

            if (!isadmin && (origin = GetTrust(request)) != null)
            {
                guest   = false;
                auth    = true;
                isadmin = true;
                type    = "trusted";
                name    = origin.Name;
            }

            return(new Identity {
                Name = name,
                IsAuthenticated = auth,
                AuthenticationType = type,
                IsAdmin = isadmin,
                IsGuest = guest
            });
        }
예제 #2
0
        public override void InitializeFromXml(XElement element)
        {
            element = element.Element("logon");

            if (null != element)
            {
                element = element.Element("default");
            }
            if (null != element)
            {
                var schema = element.ChooseAttr("schema", "code");
                if (!string.IsNullOrWhiteSpace(schema))
                {
                    if ("localguest" == schema)
                    {
                        ApplyLocalGuestSchema();
                    }
                    else if ("anyguest" == schema)
                    {
                        ApplyAnyGuestSchema();
                    }
                    else if ("localtrust" == schema)
                    {
                        ApplyLocalTrustSchema();
                    }
                    else if ("fulltrust" == schema)
                    {
                        ApplyFullTrustSchema();
                    }
                    else if ("secure" == schema)
                    {
                        ApplySecureSchema();
                    }
                }
                AllowGuest        = element.Attr("guest", AllowGuest.ToString()).ToBool();
                AllowLocalGuest   = element.Attr("localguest", AllowLocalGuest.ToString()).ToBool();
                LocalGuestIsAdmin = element.Attr("localguestadmin", LocalGuestIsAdmin.ToString()).ToBool();
                AnyGuestIsAdmin   = element.Attr("guestadmin", AnyGuestIsAdmin.ToString()).ToBool();

                AllowGuest        = AllowGuest && AllowLocalGuest;
                LocalGuestIsAdmin = AllowLocalGuest && LocalGuestIsAdmin;
                AnyGuestIsAdmin   = AnyGuestIsAdmin && LocalGuestIsAdmin;


                AnyGuestName = element.Attr("guestname", AnyGuestName);
                if (string.IsNullOrWhiteSpace(AnyGuestName))
                {
                    AnyGuestName = "guest";
                }

                LocalGuestName = element.Attr("localguestname", LocalGuestName);
                if (string.IsNullOrWhiteSpace(AnyGuestName))
                {
                    AnyGuestName = "localguest";
                }
                var i = 0;
                foreach (var e in element.Elements("trusted"))
                {
                    var rip = e.Attr("remote", "127.0.0.1");
                    if (string.IsNullOrWhiteSpace(rip))
                    {
                        rip = "127.0.0.1";
                    }

                    var lip = e.Attr("local", "127.0.0.1");
                    if (string.IsNullOrWhiteSpace(lip))
                    {
                        lip = "127.0.0.1";
                    }
                    var lport  = e.Attr("port", "0").ToInt();
                    var origin = e.Attr("origin", "*");
                    if (string.IsNullOrWhiteSpace(origin))
                    {
                        origin = "*";
                    }
                    IPAddress remote = null;
                    IPAddress local  = null;

                    if (rip != "*")
                    {
                        remote = IPAddress.Parse(rip);
                    }
                    if (lip != "*")
                    {
                        local = IPAddress.Parse(lip);
                    }
                    var name = e.Attr("code");
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        name = "trusted" + i;
                    }

                    var trusted = new TrustedOrigin {
                        LocalAddressName  = lip,
                        RemoteAddressName = rip,
                        LocalAddress      = local,
                        RemoteAddress     = remote,
                        LocalPort         = lport,
                        Origin            = origin,
                        Name = name
                    };
                    TrustedOrigins.Add(trusted);
                    i++;
                }
            }
        }