Beispiel #1
0
        /// <summary>
        /// Refreshes the session.
        /// </summary>
        public bool RefreshSession()
        {
            try
            {
                bool   refreshed  = false;
                string sessionKey = SessionHelper.BuildSessionKey("LastSSOSessionRefreshTime");

                if (SessionUtils.GetValue(sessionKey) != null && !StringUtils.IsNullOrEmptyOrWS(SSOAuthToken))
                {
                    DateTime lastSSOSessionRefreshTime = DateTimeHelper.GetDateTime(SessionUtils.GetValue(sessionKey), DateTime.MinValue);
                    TimeSpan timeDiff = DateTimeHelper.GetSvcProvDateTimeNow().Subtract(lastSSOSessionRefreshTime);

                    if ((timeDiff.TotalMinutes + 2) > FCMConfig.Security.SSOSessionTimeout)
                    {
                        string newSSOAuthToken;
                        refreshed =
                            SSOAuthWS.RefreshSession(GetSSOAuthData(FCMConfig.Security.SSOApplicationID, SSOAuthToken),
                                                     out newSSOAuthToken);

                        SSOAuthToken = newSSOAuthToken;

                        if (refreshed && !StringUtils.IsNullOrEmptyOrWS(newSSOAuthToken))
                        {
                            SessionUtils.SetValue(sessionKey, DateTimeHelper.GetSvcProvDateTimeNow());
                        }
                        else
                        {
                            Logger.Log(LogLevels.Debug, "Refresh session failed!");
                            throw new AuthenticationException("Refresh session error!");
                        }
                    }
                }

                return(refreshed);
            }
            catch (SoapException ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);

                if (!StringUtils.IsNullOrEmptyOrWS(ex.Message) && ex.Message.Contains("00401"))
                {
                    FCMBusiness.ClearSSOCache();
                    return(RefreshSession());
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);
                return(false);
            }
        }