Esempio n. 1
0
        public override Saml2Response Unbind(HttpRequestBase request)
        {
            var xml = Encoding.UTF8.GetString(
                Convert.FromBase64String(request.Form["SAMLResponse"]));

            return(Saml2Response.Read(xml));
        }
Esempio n. 2
0
        public override Saml2Response Unbind(HttpRequestBase request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var xml = Encoding.UTF8.GetString(
                Convert.FromBase64String(request.Form["SAMLResponse"]));

            return(Saml2Response.Read(xml));
        }
Esempio n. 3
0
        public CommandResult Run(HttpRequestData request)
        {
            var binding = Saml2Binding.Get(request);

            if (binding != null)
            {
                try
                {
                    var samlResponse = Saml2Response.Read(binding.Unbind(request));

                    samlResponse.Validate(GetSigningKey(samlResponse.Issuer));

                    var principal = new ClaimsPrincipal(samlResponse.GetClaims());
                    FederatedAuthentication.FederationConfiguration.IdentityConfiguration
                    .ClaimsAuthenticationManager.Authenticate(null, principal);

                    return(new CommandResult()
                    {
                        HttpStatusCode = HttpStatusCode.SeeOther,
                        Location = samlResponse.RequestState != null && samlResponse.RequestState.ReturnUri != null ? samlResponse.RequestState.ReturnUri : KentorAuthServicesSection.Current.ReturnUri,
                        Principal = principal
                    });
                }
                catch (FormatException ex)
                {
                    throw new BadFormatSamlResponseException(
                              "The SAML Response did not contain valid BASE64 encoded data.", ex);
                }
                catch (XmlException ex)
                {
                    throw new BadFormatSamlResponseException(
                              "The SAML response contains incorrect XML", ex);
                }
            }

            throw new NoSamlResponseFoundException();
        }