Esempio n. 1
0
        public KeystoneAuthDataV41 GetAuthData(DefaultDataContract msg)
        {
            CPContext          context      = CPContext.Current;
            string             loginName    = null;
            string             domain       = null;
            string             userName     = context.GetUserName(out loginName, out domain);
            string             languageCode = msg.Header.Language;
            AuthApplicationMsg application  = new AuthApplicationMsg()
            {
                Id              = CPConfig.Application.Id,
                Name            = CPConfig.Application.Name,
                DefaultLanguage = CPConfig.Application.DefaultLanguage,
            };
            List <KS_ApplicationMsg>      ks_applications = new List <KS_ApplicationMsg>();
            KeystoneApplicationCollection applications    = CPConfig.Keystone.Applications;

            if (applications != null)
            {
                foreach (KeystoneApplicationElement app in applications)
                {
                    ks_applications.Add(new KS_ApplicationMsg()
                    {
                        Id   = app.Id,
                        Name = app.Name
                    });
                }
            }
            KeystoneAuthDataV41 result = new KeystoneAuthDataV41()
            {
                Header = msg.Header,
                Body   = new KeystoneAuthDataMsg()
                {
                    Application     = application,
                    KS_Applications = ks_applications,
                }
            };

            KeystoneAuthUserMsg    userInfo;
            List <RoleAttribute>   roleAttributeList;
            List <Role>            roleList;
            List <AuthFunctionMsg> functionList;

            AuthFactory.GetInstance().GetAuthData(loginName, domain, out userInfo, out roleAttributeList, out roleList, out functionList);

            result.Body.AuthUser       = userInfo;
            result.Body.RoleAttributes = roleAttributeList;
            result.Body.Roles          = roleList;
            result.Body.Functions      = functionList;
            result.Body.MenuData       = new KeyStoneBiz().GetMenuItems(loginName, domain, languageCode, functionList);

            return(result);
        }
Esempio n. 2
0
        public KeystoneAuthDataV41 GetAuthData(DefaultDataContract msg)
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MockDataForKeystoneAuth.xml");

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(filePath);
            }

            KeystoneAuthDataV41 serviceResult = SerializationUtility.LoadFromXml <KeystoneAuthDataV41>(filePath);

            return(serviceResult);
        }
Esempio n. 3
0
        public KeystoneAuthDataV41 AutoLogin(DefaultDataContract msg)
        {
            HttpContext context = HttpContext.Current;

            //判断是否是logout后的自动登录,如果是返回数据NULL,并阻止自动登录。
            HttpCookie cookie = context.Request.Cookies[m_key_SignOut];

            if (cookie != null)
            {
                var responseCookie = new HttpCookie(m_key_SignOut);
                responseCookie.Expires = DateTime.Now.AddDays(-30);
                context.Response.Cookies.Add(responseCookie);
                return(new KeystoneAuthDataV41 {
                    Body = null
                });
            }


            if (CPConfig.Application.AutoLogin && !context.Request.IsAuthenticated)
            {
                TryLogin();
            }
            if (context.Request.IsAuthenticated)
            {
                if (HttpContext.Current.Session["IsLoginSystem"] == null)
                {
                    string    loginName = null;
                    string    domain    = null;
                    CPContext cpContext = CPContext.Current;
                    string    userName  = cpContext.GetUserName(out loginName, out domain);
                    TraceLoginEventLog(loginName);
                    HttpContext.Current.Session["IsLoginSystem"] = true;
                }
                KeystoneAuthDataV41 result = new KeystoneAuthDataV41
                {
                    Body = GetAuthData(msg).Body
                };
                return(result);
            }
            return(new KeystoneAuthDataV41 {
                Body = null
            });
        }