コード例 #1
0
        public SessionInfo Abandon()
        {
            var cookie = MiniImsServer.CurrentContext.Request.Cookies["_s"];

            var value = Guid.Empty;

            if (cookie != null && Guid.TryParse(cookie.Value, out value))
            {
                ISessionManagerService sessionService = ApplicationContext.Current.GetService <ISessionManagerService>();
                var sessionInfo = sessionService.Delete(value);
                if (MiniImsServer.CurrentContext.Request.Cookies["_s"] == null)
                {
                    MiniImsServer.CurrentContext.Response.SetCookie(new Cookie("_s", Guid.Empty.ToString(), "/")
                    {
                        Expired = true, Expires = DateTime.Now.AddSeconds(-20)
                    });
                }

                if (sessionInfo != null)
                {
                    AuditUtil.AuditLogout(sessionInfo.Principal);
                }
            }

            return(new SessionInfo());
        }
コード例 #2
0
        public SessionInfo GetSession()
        {
            NameValueCollection query = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            ISessionManagerService sessionService = ApplicationContext.Current.GetService <ISessionManagerService>();

            if (query.ContainsKey("_id"))
            {
                return(sessionService.Get(Guid.Parse(query["_id"][0])));
            }
            else
            {
                return(AuthenticationContext.Current.Session);
            }
        }
コード例 #3
0
        public SessionInfo Authenticate([RestMessage(RestMessageFormat.FormData)] NameValueCollection authRequest)
        {
            ISessionManagerService sessionService = ApplicationContext.Current.GetService <ISessionManagerService>();

            SessionInfo retVal = null;

            List <String> usernameColl  = null,
                          tfaSecretColl = null,
                          passwordColl  = null;

            authRequest.TryGetValue("username", out usernameColl);
            authRequest.TryGetValue("password", out passwordColl);
            authRequest.TryGetValue("tfaSecret", out tfaSecretColl);

            String username  = usernameColl?.FirstOrDefault().ToLower(),
                   password  = passwordColl?.FirstOrDefault(),
                   tfaSecret = tfaSecretColl?.FirstOrDefault();

            switch (authRequest["grant_type"][0])
            {
            case "password":
                retVal = sessionService.Authenticate(username, password);
                break;

            case "refresh":
                retVal = sessionService.Refresh(AuthenticationContext.Current.Session, null);     // Force a re-issue
                break;

            case "tfa":
                retVal = sessionService.Authenticate(username, password, tfaSecret);
                break;
            }

            if (retVal == null)
            {
                throw new SecurityException();
            }
            else
            {
                var lanugageCode = retVal?.UserEntity?.LanguageCommunication?.FirstOrDefault(o => o.IsPreferred)?.LanguageCode;

                CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(CultureInfo.DefaultThreadCurrentUICulture?.TwoLetterISOLanguageName ?? "en");

                if (lanugageCode != null)
                {
                    CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(lanugageCode);
                }

                // Set the session
                if (!authRequest.ContainsKey("scope"))
                {
                    MiniImsServer.CurrentContext.Response.SetCookie(new Cookie("_s", retVal.Key.ToString())
                    {
                        HttpOnly = true,
                        Secure   = true,
                        Path     = "/",
                        Domain   = MiniImsServer.CurrentContext.Request.Url.Host
                    });
                }
                return(retVal);
            }
        }