示例#1
0
        public static List <WebMeta> Auths()
        {
            List <WebMeta> metas = new List <WebMeta>();

            if (WebRuntime.flows.Count > 0)
            {
                var em = WebRuntime.flows.GetEnumerator();
                while (em.MoveNext())
                {
                    MappingAttribute mapping = (MappingAttribute)em.Current.Value[0].Type.GetCustomAttributes(typeof(MappingAttribute), false)[0];



                    WebAuthType authType = WebRuntime.authKeys[em.Current.Key];
                    if (authType == WebAuthType.Check || authType == WebAuthType.UserCheck)
                    {
                        metas.Add(new WebMeta().Put("key", em.Current.Key + ".*").Put("desc", mapping.Desc));
                    }
                }
            }

            if (WebRuntime.activities.Count > 0)
            {
                var em = WebRuntime.activities.GetEnumerator();
                while (em.MoveNext())
                {
                    var em3 = em.Current.Value.GetEnumerator();
                    while (em3.MoveNext())
                    {
                        MappingAttribute mapping = (MappingAttribute)em3.Current.Value.GetCustomAttributes(typeof(MappingAttribute), false)[0];
                        if (WebRuntime.authKeys.ContainsKey(em.Current.Key))
                        {
                            WebAuthType authType = WebRuntime.authKeys[em.Current.Key];
                            if (authType == WebAuthType.Check || authType == WebAuthType.UserCheck)
                            {
                                metas.Add(new WebMeta().Put("key", mapping.Model + "." + mapping.Command).Put("desc", mapping.Desc));
                            }
                        }
                    }
                }
            }
            return(metas);
        }
示例#2
0
        internal static List <WebMeta> Mapping()
        {
            List <WebMeta> metas = new List <WebMeta>();

            if (WebRuntime.webFactorys.Count > 0)
            {
                foreach (var wt in WebRuntime.webFactorys)
                {
                    var     t    = wt.Type;
                    WebMeta meta = new WebMeta();
                    meta.Put("type", t.FullName);
                    meta.Put("name", "." + t.Name);
                    metas.Add(meta);

                    MappingAttribute mapping = (MappingAttribute)t.GetCustomAttributes(typeof(MappingAttribute), false)[0];
                    if (String.IsNullOrEmpty(mapping.Desc) == false)
                    {
                        meta.Put("desc", mapping.Desc);
                    }
                }
            }
            if (WebRuntime.flows.Count > 0)
            {
                var em = WebRuntime.flows.GetEnumerator();
                while (em.MoveNext())
                {
                    var tls = em.Current.Value;
                    foreach (var wt in tls)
                    {
                        var     t    = wt.Type;
                        WebMeta meta = new WebMeta();
                        meta.Put("type", t.FullName);
                        meta.Put("name", em.Current.Key + ".");
                        meta.Put("auth", WebRuntime.authKeys[em.Current.Key].ToString().ToLower());
                        meta.Put("model", em.Current.Key);//.getKey())
                        metas.Add(meta);

                        var mappings = t.GetCustomAttributes(typeof(MappingAttribute), false);//[0];

                        MappingAttribute mapping = (MappingAttribute)mappings[0];
                        if (mappings.Length > 1)
                        {
                            foreach (var m in mappings)
                            {
                                var c = m as MappingAttribute;
                                if (String.Equals(c.Model, em.Current.Key))
                                {
                                    mapping = c;
                                    break;
                                }
                            }
                        }
                        if (String.IsNullOrEmpty(mapping.Desc) == false)
                        {
                            meta.Put("desc", mapping.Desc);
                        }
                    }
                }
            }
            if (WebRuntime.activities.Count > 0)
            {
                var em = WebRuntime.activities.GetEnumerator();
                while (em.MoveNext())
                {
                    var em3 = em.Current.Value.GetEnumerator();
                    while (em3.MoveNext())
                    {
                        var mappings             = em3.Current.Value.GetCustomAttributes(typeof(MappingAttribute), false);
                        MappingAttribute mapping = (MappingAttribute)mappings[0];
                        if (mappings.Length > 1)
                        {
                            foreach (var m in mappings)
                            {
                                var c = m as MappingAttribute;
                                if (String.Equals(c.Model, em.Current.Key) && String.Equals(c.Command, em3.Current.Key))
                                {
                                    mapping = c;
                                    break;
                                }
                            }
                        }

                        WebAuthType authType = mapping.Auth;// WebRuntime.authKeys[em.Current.Key];

                        WebMeta meta = new WebMeta();
                        meta.Put("type", em3.Current.Value.FullName);
                        meta.Put("name", em.Current.Key + "." + em3.Current.Key);
                        meta.Put("auth", authType.ToString().ToLower());
                        meta.Put("model", mapping.Model); //.getKey())
                        meta.Put("cmd", mapping.Command); //.getKey())
                        metas.Add(meta);

                        if (String.IsNullOrEmpty(mapping.Desc) == false)
                        {
                            meta.Put("desc", mapping.Desc);
                        }
                    }
                }
            }
            return(metas);
        }
示例#3
0
        bool Verify(string model, string cmd)
        {
            if (this.IsVerify.HasValue == false)
            {
                this.IsVerify = this.Session.IsAuthorization(model, cmd);
                if (this.IsVerify == true)
                {
                    return(true);
                }
                String      key      = String.Format("{0}.{1}", model, cmd);
                WebAuthType authType = WebAuthType.Check;
                if (WebRuntime.authKeys.ContainsKey(key))
                {
                    authType = WebRuntime.authKeys[key];
                }
                else if (WebRuntime.authKeys.ContainsKey(model))
                {
                    authType = WebRuntime.authKeys[model];
                }
                var user = UMC.Security.Identity.Current;
                System.Security.Principal.IPrincipal principal = user;// WebADNuke.Security.Identity.Current;



                switch (authType)
                {
                case WebAuthType.All:
                    this.IsVerify = true;
                    return(true);

                case WebAuthType.User:
                    if (principal.IsInRole(Security.Membership.UserRole))
                    {
                        this.IsVerify = true;
                        return(true);
                    }
                    break;

                case WebAuthType.UserCheck:
                    if (principal.IsInRole(Security.Membership.AdminRole))
                    {
                        this.IsVerify = true;
                        return(true);
                    }
                    else if (principal.IsInRole(Security.Membership.UserRole))
                    {
                        if (UMC.Security.AuthManager.IsAuthorization(key))
                        {
                            this.IsVerify = true;
                            return(true);
                        }
                    }
                    break;

                case WebAuthType.Check:
                    if (principal.IsInRole(Security.Membership.AdminRole))
                    {
                        this.IsVerify = true;
                        return(true);
                    }
                    else if (user.IsAuthenticated)
                    {
                        if (UMC.Security.AuthManager.IsAuthorization(key))
                        {
                            this.IsVerify = true;
                            return(true);
                        }
                    }

                    break;

                case WebAuthType.Admin:
                    if (principal.IsInRole(Security.Membership.AdminRole))
                    {
                        this.IsVerify = true;
                        return(true);
                    }
                    break;

                case WebAuthType.Guest:
                    if (user.IsAuthenticated)
                    {
                        this.IsVerify = true;
                        return(true);
                    }
                    else
                    {
                        this.OuterHeaders           = new Hashtable();
                        this.ClientEvent            = WebEvent.Prompt | WebEvent.DataEvent;
                        this.OuterHeaders["Prompt"] = new WebMeta().Put("Title", "提示", "Text", "您没有登录,请登录");

                        this.OuterHeaders["DataEvent"] = new WebMeta().Put("type", "Login");
                        return(false);
                    }
                }

                this.OuterHeaders = new Hashtable();
                this.ClientEvent  = WebEvent.Prompt; //| WebEvent.DataEvent;
                if (principal.IsInRole(Security.Membership.UserRole) == false)
                {
                    this.OuterHeaders["Prompt"]    = new WebMeta().Put("Title", "提示", "Text", "您没有登录或权限受限");
                    this.ClientEvent               = WebEvent.Prompt | WebEvent.DataEvent;
                    this.OuterHeaders["DataEvent"] = new WebMeta().Put("type", "Close");
                }
                else
                {
                    this.OuterHeaders["Prompt"] = new WebMeta().Put("Title", "提示", "Text", "您的权限受限,请与管理员联系");
                }
                return(false);
            }
            return(true);
        }