Exemplo n.º 1
0
        private SAMLLogoutResponse ExtractLogoutResponseValues(XmlDocument doc)
        {
            SAMLLogoutResponse context = new SAMLLogoutResponse(SAMLConstants.ErrorCodes.VALID);

            XmlReader          reader   = new XmlTextReader(new StringReader(doc.OuterXml));
            LogoutResponseType response = Deserialize <LogoutResponseType>(reader);

            context.InResponseTo = response.InResponseTo;
            int statusCode = SAMLConstants.StatusCode.GetStatusCodeFromDesc(
                response.Status.StatusCode.Value);

            if (statusCode < 0 && response.Status.StatusCode.StatusCode != null)
            {
                context.StatusCode = SAMLConstants.StatusCode.GetStatusCodeFromDesc(
                    response.Status.StatusCode.StatusCode.Value);
            }
            else
            {
                context.StatusCode = statusCode;
            }

            if (Math.Abs(response.IssueInstant.Subtract(DateTime.UtcNow).TotalMinutes) > validTimeframe)
            {
                context.ErrorCode = SAMLConstants.ErrorCodes.EXPIRED;
                return(context);
            }
            if (statusCode != SAMLConstants.StatusCode.SUCCESS)
            {
                int subStatusCode = SAMLConstants.StatusCode.GetStatusCodeFromDesc(
                    response.Status.StatusCode.StatusCode.Value);
                if (subStatusCode != -1)
                {
                    context.SubStatusCode = subStatusCode;
                    context.StatusMessage = response.Status.StatusMessage;
                }
                return(context);
            }

            return(context);
        }
Exemplo n.º 2
0
        public SAMLLogoutResponse HandleLogoutResponse(XmlDocument xmlResponse)
        {
            try
            {
                int errorCode;
                SAMLLogoutResponse response;
                if ((errorCode = Verify(xmlResponse, null)) < 0)
                {
                    response = new SAMLLogoutResponse(errorCode);
                }
                else
                {
                    response = ExtractLogoutResponseValues(xmlResponse);
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw new SAMLException("EXCEPTION HandleLogoutResponse", ex);
            }
        }