예제 #1
0
        /// <summary>
        /// Creates an artifact for the LogoutRequest and redirects the user to the IdP.
        /// </summary>
        /// <param name="destination">The destination of the request.</param>
        /// <param name="request">The logout request.</param>
        /// <param name="relayState">The query string relay state value to add to the communication</param>
        public void RedirectFromLogout(IdentityProviderEndpointElement destination, Saml20LogoutRequest request, string relayState)
        {
            var config = Saml2Config.GetConfig();
            var index  = (short)config.ServiceProvider.Endpoints.LogoutEndpoint.Index;
            var doc    = request.GetXml();

            XmlSignatureUtils.SignDocument(doc, request.Request.Id);
            ArtifactRedirect(destination, index, doc, relayState);
        }
예제 #2
0
        /// <summary>
        /// Creates an artifact and redirects the user to the IdP
        /// </summary>
        /// <param name="destination">The destination of the request.</param>
        /// <param name="request">The authentication request.</param>
        public void RedirectFromLogin(IdentityProviderEndpointElement destination, Saml20AuthnRequest request)
        {
            var config = Saml2Config.GetConfig();
            var index  = (short)config.ServiceProvider.Endpoints.SignOnEndpoint.Index;
            var doc    = request.GetXml();

            XmlSignatureUtils.SignDocument(doc, request.Request.Id);
            ArtifactRedirect(destination, index, doc, Context.Request.Params["relayState"]);
        }
예제 #3
0
 private IdentityProviderEndpoint ToIdentityProviderEndpoint(IdentityProviderEndpointElement value)
 {
     if (value == null)
     {
         return(null);
     }
     return(new IdentityProviderEndpoint
     {
         Binding = value.Binding,
         ForceProtocolBinding = value.ForceProtocolBinding,
         TokenAccessor = value.TokenAccessor,
         Type = value.Type,
         Url = value.Url
     });
 }
        /// <summary>
        /// Determine which endpoint to use based on the protocol defaults, configuration data and metadata.
        /// </summary>
        /// <param name="defaultBinding">The binding to use if none has been specified in the configuration and the metadata allows all bindings.</param>
        /// <param name="config">The endpoint as described in the configuration. May be null.</param>
        /// <param name="metadata">A list of endpoints of the given type (e.g. SSO or SLO) that the metadata contains.</param>
        /// <returns>The <see cref="IdentityProviderElement"/>.</returns>
        internal static IdentityProviderEndpointElement DetermineEndpointConfiguration(BindingType defaultBinding, IdentityProviderEndpointElement config, List <IdentityProviderEndpointElement> metadata)
        {
            var result = new IdentityProviderEndpointElement {
                Binding = defaultBinding
            };

            // Determine which binding to use.
            if (config != null)
            {
                result.Binding = config.Binding;
            }
            else
            {
                // Verify that the metadata allows the default binding.
                var allowed = metadata.Exists(el => el.Binding == defaultBinding);
                if (!allowed)
                {
                    result.Binding = result.Binding == BindingType.Post
                                         ? BindingType.Redirect
                                         : BindingType.Post;
                }
            }

            if (config != null && !string.IsNullOrEmpty(config.Url))
            {
                result.Url = config.Url;
            }
            else
            {
                var endpoint = metadata.Find(el => el.Binding == result.Binding);
                if (endpoint == null)
                {
                    throw new ConfigurationErrorsException(string.Format("No IdentityProvider supporting SAML binding {0} found in metadata", result.Binding));
                }

                result.Url = endpoint.Url;
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Handles all artifact creations and redirects.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <param name="localEndpointIndex">Index of the local endpoint.</param>
        /// <param name="signedSamlMessage">The signed SAML message.</param>
        /// <param name="relayState">The query string relay state value to add to the communication</param>
        private void ArtifactRedirect(IdentityProviderEndpointElement destination, short localEndpointIndex, XmlDocument signedSamlMessage, string relayState)
        {
            Logger.DebugFormat(TraceMessages.ArtifactRedirectReceived, signedSamlMessage.OuterXml);

            var config        = Saml2Config.GetConfig();
            var sourceId      = config.ServiceProvider.Id;
            var sourceIdHash  = ArtifactUtil.GenerateSourceIdHash(sourceId);
            var messageHandle = ArtifactUtil.GenerateMessageHandle();

            var artifact = ArtifactUtil.CreateArtifact(HttpArtifactBindingConstants.ArtifactTypeCode, localEndpointIndex, sourceIdHash, messageHandle);

            Context.Cache.Insert(artifact, signedSamlMessage, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);

            var destinationUrl = destination.Url + "?" + HttpArtifactBindingConstants.ArtifactQueryStringName + "=" + HttpUtility.UrlEncode(artifact);

            if (!string.IsNullOrEmpty(relayState))
            {
                destinationUrl += "&relayState=" + relayState;
            }

            Logger.DebugFormat(TraceMessages.ArtifactCreated, artifact);

            Context.Response.Redirect(destinationUrl);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpPostBindingBuilder"/> class.
 /// </summary>
 /// <param name="endpoint">The IdP endpoint that messages will be sent to.</param>
 public HttpPostBindingBuilder(IdentityProviderEndpointElement endpoint)
 {
     _destinationEndpoint = endpoint;
     Action     = SamlActionType.SAMLRequest;
     RelayState = string.Empty;
 }
 private IdentityProviderEndpoint ToIdentityProviderEndpoint(IdentityProviderEndpointElement value)
 {
     if (value == null) return null;
     return new IdentityProviderEndpoint
     {
         Binding = value.Binding,
         ForceProtocolBinding = value.ForceProtocolBinding,
         TokenAccessor = value.TokenAccessor,
         Type = value.Type,
         Url = value.Url
     };
 }
예제 #8
0
 /// <summary>
 /// Creates an artifact for the LogoutRequest and redirects the user to the IdP.
 /// </summary>
 /// <param name="destination">The destination of the request.</param>
 /// <param name="request">The logout request.</param>
 public void RedirectFromLogout(IdentityProviderEndpointElement destination, Saml20LogoutRequest request)
 {
     RedirectFromLogout(destination, request, Context.Request.Params["relayState"]);
 }