Ejemplo n.º 1
0
        private static ErrorInformation GetExceptionHandlingInformation(HttpContext httpContext, Exception exception)
        {
            ErrorInformation errorInformation = new ErrorInformation
            {
                Exception = exception
            };

            if (exception is OrgIdMailboxRecentlyCreatedException)
            {
                OrgIdMailboxRecentlyCreatedException ex = exception as OrgIdMailboxRecentlyCreatedException;
                errorInformation.Message   = ex.Message;
                errorInformation.MessageId = new Strings.IDs?(ex.ErrorMessageStringId);
                errorInformation.AddMessageParameter(ex.UserName);
                errorInformation.AddMessageParameter(ex.HoursBetweenAccountCreationAndNow.ToString());
                errorInformation.Mode = ex.ErrorMode;
            }
            else if (exception is OrgIdMailboxNotFoundException)
            {
                OrgIdMailboxNotFoundException ex2 = exception as OrgIdMailboxNotFoundException;
                errorInformation.Message   = ex2.Message;
                errorInformation.MessageId = new Strings.IDs?(ex2.ErrorMessageStringId);
                errorInformation.AddMessageParameter(ex2.UserName);
                errorInformation.Mode = ex2.ErrorMode;
            }
            else if (exception is OrgIdLogonException)
            {
                OrgIdLogonException ex3 = exception as OrgIdLogonException;
                errorInformation.Message          = ex3.Message;
                errorInformation.MessageId        = new Strings.IDs?(ex3.ErrorMessageStringId);
                errorInformation.MessageParameter = ex3.UserName;
            }
            else if (exception is AppPasswordAccessException)
            {
                AppPasswordAccessException ex4 = exception as AppPasswordAccessException;
                errorInformation.Message   = ex4.Message;
                errorInformation.MessageId = new Strings.IDs?(ex4.ErrorMessageStringId);
            }
            else if (exception is LiveClientException || exception is LiveConfigurationException || exception is LiveTransientException || exception is LiveOperationException)
            {
                errorInformation.Message   = exception.Message;
                errorInformation.MessageId = new Strings.IDs?(1317300008);
                string text = httpContext.Request.QueryString["realm"];
                if (!string.IsNullOrEmpty(text))
                {
                    errorInformation.AddMessageParameter(text);
                }
            }
            else if (exception is AccountTerminationException)
            {
                AccountTerminationException ex5 = exception as AccountTerminationException;
                errorInformation.Message          = ex5.Message;
                errorInformation.MessageId        = new Strings.IDs?(ex5.ErrorMessageStringId);
                errorInformation.MessageParameter = ex5.AccountState.ToString();
            }
            return(errorInformation);
        }
Ejemplo n.º 2
0
        public static bool Authenticate(HttpContext httpContext, string siteName, string authPolicyOverrideValue, string[] memberNameIgnorePrefixes, bool useConsumerRps, out string puid, out string orgIdPuid, out string cid, out string membername, out uint issueTime, out uint loginAttributes, out string responseHeaders, out uint rpsTicketType, out RPSTicket deprecatedRpsTicketObject, out bool hasAcceptedAccrual, out uint rpsAuthState, out bool isOrgIdFederatedMsaIdentity)
        {
            if (!LiveIdAuthentication.IsInitialized)
            {
                throw new InvalidOperationException(Strings.ComponentNotInitialized);
            }
            if (siteName == null)
            {
                throw new ArgumentNullException("siteName");
            }
            hasAcceptedAccrual = false;
            puid                        = null;
            orgIdPuid                   = null;
            cid                         = null;
            membername                  = null;
            issueTime                   = 0U;
            loginAttributes             = 0U;
            responseHeaders             = null;
            rpsTicketType               = 0U;
            deprecatedRpsTicketObject   = null;
            rpsAuthState                = 0U;
            isOrgIdFederatedMsaIdentity = false;
            RPSPropBag rpspropBag = null;
            string     text       = httpContext.Request.QueryString["f"];

            if (!string.IsNullOrEmpty(text))
            {
                ExTraceGlobals.LiveIdAuthenticationModuleTracer.TraceError <string>(0L, "Querystring contains F-code: {0}.", text);
                return(false);
            }
            try
            {
                if (!useConsumerRps)
                {
                    rpspropBag = new RPSPropBag(LiveIdAuthentication.rpsOrgIdSession);
                }
                RPSProfile rpsprofile = null;
                using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(useConsumerRps))
                {
                    int?   rpsErrorCode;
                    string rpsErrorString;
                    rpsprofile = rpshttpAuthClient.Authenticate(siteName, authPolicyOverrideValue, LiveIdAuthentication.sslOffloaded, httpContext.Request, rpspropBag, out rpsErrorCode, out rpsErrorString, out deprecatedRpsTicketObject);
                    LiveIdAuthentication.ValidateRpsCallAndThrowOnFailure(rpsErrorCode, rpsErrorString);
                }
                if (rpsprofile == null)
                {
                    return(false);
                }
                if (!useConsumerRps && deprecatedRpsTicketObject != null)
                {
                    try
                    {
                        using (RPSPropBag rpspropBag2 = new RPSPropBag(LiveIdAuthentication.rpsOrgIdSession))
                        {
                            rpspropBag2["SlidingWindow"] = 0;
                            if (!string.IsNullOrEmpty(authPolicyOverrideValue))
                            {
                                rpspropBag2["AuthPolicy"] = authPolicyOverrideValue;
                            }
                            if (!deprecatedRpsTicketObject.Validate(rpspropBag2))
                            {
                                return(false);
                            }
                        }
                    }
                    catch (COMException ex)
                    {
                        ExTraceGlobals.LiveIdAuthenticationModuleTracer.TraceError <COMException>(0L, "Failed to validate ticket: {0}.", ex);
                        LiveIdErrorHandler.ThrowRPSException(ex);
                    }
                }
                rpsAuthState  = rpsprofile.RPSAuthState;
                rpsTicketType = rpsprofile.TicketType;
                if (LiveIdAuthenticationModule.AppPasswordCheckEnabled && !httpContext.Request.Url.AbsolutePath.StartsWith("/owa/", StringComparison.OrdinalIgnoreCase) && rpsprofile.AppPassword)
                {
                    AppPasswordAccessException exception = new AppPasswordAccessException();
                    httpContext.Response.AppendToLog("&AppPasswordBlocked");
                    Utilities.HandleException(httpContext, exception, false);
                }
                hasAcceptedAccrual = LiveIdAuthentication.HasAcceptedAccruals(rpsprofile);
                orgIdPuid          = rpsprofile.HexPuid;
                cid        = (string.IsNullOrWhiteSpace(rpsprofile.ConsumerCID) ? rpsprofile.HexCID : rpsprofile.ConsumerCID);
                puid       = (string.IsNullOrWhiteSpace(rpsprofile.ConsumerPuid) ? orgIdPuid : rpsprofile.ConsumerPuid);
                membername = rpsprofile.MemberName;
                string text2;
                if (LiveIdAuthentication.TryRemoveMemberNamePrefixes(membername, memberNameIgnorePrefixes, out text2))
                {
                    membername = text2;
                    isOrgIdFederatedMsaIdentity = true;
                }
                issueTime       = rpsprofile.IssueInstant;
                loginAttributes = rpsprofile.LoginAttributes;
                string text3 = loginAttributes.ToString();
                httpContext.Response.AppendToLog("&loginAttributes=" + text3);
                if (!string.IsNullOrWhiteSpace(text3))
                {
                    httpContext.Response.AppendToLog(string.Format("loginAttributes={0}", text3));
                    httpContext.Request.Headers.Add("X-LoginAttributes", text3);
                }
                responseHeaders = rpsprofile.ResponseHeader;
            }
            finally
            {
                if (rpspropBag != null)
                {
                    rpspropBag.Dispose();
                }
            }
            return(true);
        }