Esempio n. 1
0
        public ActionResult SsoLogout()
        {
            try
            {
                int appId = 3;      // ADAP
                using (AuthenticationClient auth = new AuthenticationClient())
                {
                    auth.SsoLogout(SessionHelper.LoginStatus.UserID, SessionHelper.LoginInfo.SessionData, appId, UtilityFunction.GetUserIPAddress());
                }
                SessionHelper.IsUserLoggedIn = false;
                SessionHelper.UserId         = -1;
                SessionHelper.LoginStatus    = null;
            }
            catch (Exception e)
            {
                Debug.WriteLine("* * *  AccountController Logout Exception: " + e.Message);
            }

            SessionHelper.DestroySession();

            string basePortalUrl = WebConfigurationManager.AppSettings["UASAdminURL"];

            return(Redirect(new Uri(new Uri(basePortalUrl), "Portal").ToString()));
        }
Esempio n. 2
0
        public ActionResult SsoLogin(string sessionId = "", string appId = "")
        {
            string portalSessionId = sessionId;

            // Portal Session is saved to be used when using SSO to SecureEmail or other systems that use UAS SSO
            SessionHelper.PortalSession = sessionId;

            string ipAddress    = UtilityFunction.GetUserIPAddress();
            string appSessionId = Session.SessionID;

            int applicationId = UAS.Business.Constants.APPLICATIONID;    // Get the Default Application Id (probably SIS or ADAP)

            try
            {
                if (String.IsNullOrEmpty(appId))
                {
                    appId = "3";        // Default to ADAP - this should proabably be deleted.
                }
                applicationId = Convert.ToInt32(appId);
            }
            catch (Exception excpt)
            {
                Debug.WriteLine("SsoLogin - failed getting applicationId: " + excpt.Message);
                // think DEF (Assmnts) has a specific Error screen that should be used.
                ViewBag.ErrorMessage = "Request.Cookies error: " + excpt.Message;
                return(View("loginSIS"));
            }

            AuthenticationClient webclient = new AuthenticationClient();

            string authResult = string.Empty;

            try
            {
                authResult = webclient.SsoLogin(portalSessionId, ipAddress, applicationId, appSessionId);

                Debug.WriteLine("SsoLogin XML result: " + authResult);
            }
            catch (Exception excptn)
            {
                authResult = "<record><errormessage>" + excptn.Message + "</errormessage></record>";
                Debug.WriteLine("SsoLogin webservice exception: " + excptn.Message);
                ViewBag.ErrorMessage = excptn.Message;
                return(View("loginSIS"));
            }

            try
            {
                UAS.DataDTO.LoginStatus loginStatus = ProcessSsoAuth(authResult);

                UAS.DataDTO.LoginInfo loginInfo = FillLoginInfo(loginStatus);

                string userName = String.Empty;
                Debug.WriteLine("LoginStatus ErrorMessage: " + loginStatus.ErrorMessage);
                Debug.WriteLine("LoginStatus Status: " + loginStatus.Status);
                userName = loginStatus.FirstName + " " + loginStatus.LastName;
                Debug.WriteLine("LoginStatus Name: " + userName);


                if ((loginStatus.Status == 'A') &&
                    (loginStatus.UserID > 0) &&
                    (loginStatus.appGroupPermissions.Count > 0)
                    )
                {
                    loginInfo.IsLoggedIn         = true;
                    SessionHelper.IsUserLoggedIn = true;
                    SessionHelper.LoginInfo      = loginInfo;
                    SessionHelper.LoginStatus    = loginStatus;

                    var userContext = webclient.GetUserContextLightweight(loginStatus.EnterpriseID, loginStatus.UserID);
                    if (userContext == null)
                    {
                        throw new Exception(String.Format("Unable to get UserContext for UserId = {0}.", loginStatus.UserID));
                    }
                    SessionHelper.UserSecurityContext = new UserSecurityContext
                    {
                        UserContext = userContext,
                    };

                    string clientUserId = Request["userId"] as string;
                    Session.Add("clientUserId", clientUserId);

                    if (applicationId == 3)
                    {
                        return(RedirectToAction("Index", "Adap"));
                    }
                    return(RedirectToAction("Index", "Search"));
                }

                SessionHelper.IsUserLoggedIn = false;

                ViewBag.ErrorMessage = loginStatus.ErrorMessage;
            }
            catch (Exception xcptn)
            {
                Debug.WriteLine("SsoLogin exception: " + xcptn.Message);
                ViewBag.ErrorMessage = xcptn.Message;
            }

            return(View("loginSIS"));
        }