コード例 #1
0
ファイル: LogoutRequest.cs プロジェクト: contact4manoj/Fedlet
        /// <summary>
        /// Initializes a new instance of the LogoutRequest class.
        /// </summary>
        /// <param name="identityProvider">
        /// IdentityProvider of the LogoutRequest
        /// </param>
        /// <param name="serviceProvider">
        /// ServiceProvider of the LogoutRequest
        /// </param>
        /// <param name="parameters">
        /// NameValueCollection of varying parameters for use in the
        /// construction of the LogoutRequest.
        /// </param>
        /// <param name="saml2Utils">Utilities Class</param>
        public LogoutRequest(
            IIdentityProvider identityProvider,
            IServiceProvider serviceProvider,
            NameValueCollection parameters,
            Saml2Utils saml2Utils)
        {
            try
            {
                xml = new XmlDocument();
                xml.PreserveWhitespace = true;

                nsMgr = new XmlNamespaceManager(xml.NameTable);
                nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
                nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
                nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

                string sessionIndex  = null;
                string subjectNameId = null;
                string binding       = null;
                string destination   = null;

                if (parameters != null)
                {
                    sessionIndex  = parameters[Saml2Constants.SessionIndex];
                    subjectNameId = parameters[Saml2Constants.SubjectNameId];
                    binding       = parameters[Saml2Constants.Binding];
                    destination   = parameters[Saml2Constants.Destination];
                }

                if (String.IsNullOrEmpty(sessionIndex))
                {
                    throw new Saml2Exception(Resources.LogoutRequestSessionIndexNotDefined);
                }
                else if (String.IsNullOrEmpty(subjectNameId))
                {
                    throw new Saml2Exception(Resources.LogoutRequestSubjectNameIdNotDefined);
                }
                else if (serviceProvider == null)
                {
                    throw new Saml2Exception(Resources.LogoutRequestServiceProviderIsNull);
                }
                else if (identityProvider == null)
                {
                    throw new Saml2Exception(Resources.LogoutRequestIdentityProviderIsNull);
                }

                if (string.IsNullOrEmpty(destination))
                {
                    destination = identityProvider.GetSingleLogoutServiceLocation(binding);

                    if (string.IsNullOrEmpty(destination))
                    {
                        // default with HttpRedirect
                        destination = identityProvider.GetSingleLogoutServiceLocation(Saml2Constants.HttpRedirectProtocolBinding);
                    }
                }

                var rawXml = new StringBuilder();
                rawXml.Append("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"");
                rawXml.Append(" ID=\"" + saml2Utils.GenerateId() + "\"");
                rawXml.Append(" Version=\"2.0\"");
                rawXml.Append(" IssueInstant=\"" + saml2Utils.GenerateIssueInstant() + "\"");

                if (!String.IsNullOrEmpty(destination))
                {
                    rawXml.Append(" Destination=\"" + destination + "\"");
                }

                rawXml.Append(" >");
                rawXml.Append(" <saml:NameID xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"");
                rawXml.Append("  Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"");
                rawXml.Append("  NameQualifier=\"" + identityProvider.EntityId + "\">" + subjectNameId + "</saml:NameID> ");
                rawXml.Append(" <saml:SessionIndex xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + sessionIndex +
                              "</saml:SessionIndex>");
                rawXml.Append(" <saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + serviceProvider.EntityId +
                              "</saml:Issuer>");
                rawXml.Append("</samlp:LogoutRequest>");

                xml.LoadXml(rawXml.ToString());
            }
            catch (ArgumentNullException ane)
            {
                throw new Saml2Exception(Resources.LogoutRequestNullArgument, ane);
            }
            catch (XmlException xe)
            {
                throw new Saml2Exception(Resources.LogoutRequestXmlException, xe);
            }
        }
コード例 #2
0
ファイル: LogoutRequest.cs プロジェクト: agascon/Fedlet
        /// <summary>
        /// Initializes a new instance of the LogoutRequest class.
        /// </summary>
        /// <param name="identityProvider">
        /// IdentityProvider of the LogoutRequest
        /// </param>
        /// <param name="serviceProvider">
        /// ServiceProvider of the LogoutRequest
        /// </param>
        /// <param name="parameters">
        /// NameValueCollection of varying parameters for use in the 
        /// construction of the LogoutRequest.
        /// </param>
        /// <param name="saml2Utils">Utilities Class</param>
        public LogoutRequest(
			IIdentityProvider identityProvider,
			IServiceProvider serviceProvider,
			NameValueCollection parameters,
            Saml2Utils saml2Utils)
        {
            try
            {
                xml = new XmlDocument();
                xml.PreserveWhitespace = true;

                nsMgr = new XmlNamespaceManager(xml.NameTable);
                nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
                nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
                nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

                string sessionIndex = null;
                string subjectNameId = null;
                string binding = null;
                string destination = null;

                if (parameters != null)
                {
                    sessionIndex = parameters[Saml2Constants.SessionIndex];
                    subjectNameId = parameters[Saml2Constants.SubjectNameId];
                    binding = parameters[Saml2Constants.Binding];
                    destination = parameters[Saml2Constants.Destination];
                }

                if (String.IsNullOrEmpty(sessionIndex))
                {
                    throw new Saml2Exception(Resources.LogoutRequestSessionIndexNotDefined);
                }
                else if (String.IsNullOrEmpty(subjectNameId))
                {
                    throw new Saml2Exception(Resources.LogoutRequestSubjectNameIdNotDefined);
                }
                else if (serviceProvider == null)
                {
                    throw new Saml2Exception(Resources.LogoutRequestServiceProviderIsNull);
                }
                else if (identityProvider == null)
                {
                    throw new Saml2Exception(Resources.LogoutRequestIdentityProviderIsNull);
                }

                if (string.IsNullOrEmpty(destination))
                {
                    destination = identityProvider.GetSingleLogoutServiceLocation(binding);

                    if (string.IsNullOrEmpty(destination))
                    {
                        // default with HttpRedirect
                        destination = identityProvider.GetSingleLogoutServiceLocation(Saml2Constants.HttpRedirectProtocolBinding);
                    }
                }

                var rawXml = new StringBuilder();
                rawXml.Append("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"");
                rawXml.Append(" ID=\"" + saml2Utils.GenerateId() + "\"");
                rawXml.Append(" Version=\"2.0\"");
                rawXml.Append(" IssueInstant=\"" + saml2Utils.GenerateIssueInstant() + "\"");

                if (!String.IsNullOrEmpty(destination))
                {
                    rawXml.Append(" Destination=\"" + destination + "\"");
                }

                rawXml.Append(" >");
                rawXml.Append(" <saml:NameID xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"");
                rawXml.Append("  Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"");
                rawXml.Append("  NameQualifier=\"" + identityProvider.EntityId + "\">" + subjectNameId + "</saml:NameID> ");
                rawXml.Append(" <saml:SessionIndex xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + sessionIndex +
                              "</saml:SessionIndex>");
                rawXml.Append(" <saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + serviceProvider.EntityId +
                              "</saml:Issuer>");
                rawXml.Append("</samlp:LogoutRequest>");

                xml.LoadXml(rawXml.ToString());
            }
            catch (ArgumentNullException ane)
            {
                throw new Saml2Exception(Resources.LogoutRequestNullArgument, ane);
            }
            catch (XmlException xe)
            {
                throw new Saml2Exception(Resources.LogoutRequestXmlException, xe);
            }
        }