Exemplo n.º 1
0
        private static Scoping GetScoping(ServiceProvider serviceProvider)
        {
            Scoping scoping = null;

            if (serviceProvider.ScopingProxyCount > 0)
            {
                scoping = new Scoping();
                ArrayList idpEntry = new ArrayList();
                idpEntry.AddRange(serviceProvider.ScopingIDPList);
                scoping.SetIDPEntry(idpEntry);
            }

            return(scoping);
        }
Exemplo n.º 2
0
        private static Scoping GetScoping(ServiceProvider serviceProvider)
        {
            Scoping scoping = null;

            if (serviceProvider.IDPProxyEnabled)
            {
                scoping = new Scoping();
                int proxyCount = serviceProvider.IDPProxyCount;
                if (serviceProvider.IDPProxyCount != 0)
                {
                    scoping.ProxyCount = serviceProvider.IDPProxyCount;
                }
                ArrayList idpEntries = serviceProvider.ScopingIDPList;
                if (idpEntries.Count != 0)
                {
                    scoping.SetIDPEntry(idpEntries);
                }
            }

            return(scoping);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the AuthnRequest class.
        /// </summary>
        /// <param name="identityProvider">
        /// IdentityProvider to receive the AuthnRequest
        /// </param>
        /// <param name="serviceProvider">
        /// ServiceProvider to issue the AuthnRequest
        /// </param>
        /// <param name="parameters">
        /// NameValueCollection of varying parameters for use in the
        /// construction of the AuthnRequest.
        /// </param>
        public AuthnRequest(IdentityProvider identityProvider, ServiceProvider serviceProvider, NameValueCollection parameters)
        {
            this.xml = new XmlDocument();
            this.xml.PreserveWhitespace = true;

            this.nsMgr = new XmlNamespaceManager(this.xml.NameTable);
            this.nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
            this.nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

            this.Id           = Saml2Utils.GenerateId();
            this.IssueInstant = Saml2Utils.GenerateIssueInstant();
            this.Issuer       = serviceProvider.EntityId;

            if (parameters != null)
            {
                this.AllowCreate = Saml2Utils.GetBoolean(parameters[Saml2Constants.AllowCreate]);
                this.AssertionConsumerServiceIndex = parameters[Saml2Constants.AssertionConsumerServiceIndex];
                this.Binding     = parameters[Saml2Constants.Binding];
                this.Consent     = parameters[Saml2Constants.Consent];
                this.Destination = parameters[Saml2Constants.Destination];
                this.ForceAuthn  = Saml2Utils.GetBoolean(parameters[Saml2Constants.ForceAuthn]);
                this.IsPassive   = Saml2Utils.GetBoolean(parameters[Saml2Constants.IsPassive]);
            }

            string assertionConsumerSvcUrl = null;

            if (!String.IsNullOrEmpty(this.Binding))
            {
                if (!String.IsNullOrEmpty(this.AssertionConsumerServiceIndex))
                {
                    // find assertion consumer service location by binding and index.
                    assertionConsumerSvcUrl = serviceProvider.GetAssertionConsumerServiceLocation(this.Binding, this.AssertionConsumerServiceIndex);
                }
                else
                {
                    // find assertion consumer service location by binding only, using first found.
                    assertionConsumerSvcUrl = serviceProvider.GetAssertionConsumerServiceLocation(this.Binding);
                }
            }

            // neither index nor binding, throw exception
            if (String.IsNullOrEmpty(this.AssertionConsumerServiceIndex) && String.IsNullOrEmpty(assertionConsumerSvcUrl))
            {
                throw new Saml2Exception(Resources.AuthnRequestAssertionConsumerServiceNotDefined);
            }

            // If destination not specified, use SSO location by binding
            if (string.IsNullOrEmpty(this.Destination))
            {
                this.Destination
                    = identityProvider.GetSingleSignOnServiceLocation(parameters[Saml2Constants.RequestBinding]);

                if (string.IsNullOrEmpty(this.Destination))
                {
                    // default to HttpRedirect
                    this.Destination = identityProvider.GetSingleSignOnServiceLocation(Saml2Constants.HttpRedirectProtocolBinding);
                }
            }

            // Get RequestedAuthnContext if parameters are available...
            RequestedAuthnContext reqAuthnContext = GetRequestedAuthnContext(serviceProvider, parameters);

            // Get Scoping if available...
            Scoping scoping = GetScoping(serviceProvider);

            // Generate the XML for the AuthnRequest...
            StringBuilder rawXml = new StringBuilder();

            rawXml.Append("<samlp:AuthnRequest");
            rawXml.Append(" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"");
            rawXml.Append(" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"");
            rawXml.Append(" ID=\"" + this.Id + "\"");
            rawXml.Append(" Version=\"2.0\"");
            rawXml.Append(" IssueInstant=\"" + this.IssueInstant + "\"");
            rawXml.Append(" IsPassive=\"" + (this.IsPassive ? "true" : "false") + "\"");
            rawXml.Append(" ForceAuthn=\"" + (this.ForceAuthn ? "true" : "false") + "\"");

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

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

            if (!String.IsNullOrEmpty(assertionConsumerSvcUrl))
            {
                rawXml.Append(" ProtocolBinding=\"" + this.Binding + "\"");
                rawXml.Append(" AssertionConsumerServiceURL=\"" + assertionConsumerSvcUrl + "\"");
            }
            else
            {
                rawXml.Append(" AssertionConsumerIndex=\"" + this.AssertionConsumerServiceIndex + "\"");
            }

            rawXml.Append(">");
            rawXml.Append("<saml:Issuer>" + serviceProvider.EntityId + "</saml:Issuer>");
            rawXml.Append("<samlp:NameIDPolicy AllowCreate=\"" + (this.AllowCreate ? "true" : "false") + "\" />");

            if (reqAuthnContext != null)
            {
                rawXml.Append(reqAuthnContext.GenerateXmlString());
            }

            if (scoping != null)
            {
                rawXml.Append(scoping.GenerateXmlString());
            }

            rawXml.Append("</samlp:AuthnRequest>");

            this.xml.LoadXml(rawXml.ToString());
        }
Exemplo n.º 4
0
        private static Scoping GetScoping(ServiceProvider serviceProvider)
        {
            Scoping scoping = null;

            if (serviceProvider.ScopingProxyCount > 0)
            {
                scoping = new Scoping();
                ArrayList idpEntry = new ArrayList();
                idpEntry.AddRange(serviceProvider.ScopingIDPList);
                scoping.SetIDPEntry(idpEntry);
            }

            return scoping;
        }