/// <summary> /// Adds an <see cref="ServiceProviderEndpoint"/> to the config. /// </summary> /// <param name="endpoint">The <see cref="ServiceProviderEndpoint"/> to add.</param> /// <returns>The <see cref="ServiceProviderConfigBuilder"/>.</returns> public ServiceProviderConfigBuilder AddEndpoint(ServiceProviderEndpoint endpoint) { _endpoints.Add(endpoint); return(this); }
public new void ProcessRequest(HttpContext context) { try { // ***** RESPONSE ***** if (!String.IsNullOrEmpty(context.Request[HttpBindingConstants.SAMLResponse])) { // Recupera Response string samlresponse = context.Request[HttpBindingConstants.SAMLResponse]; XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml(samlresponse); // Verifica Signature do Response if (XmlSignatureUtils.VerifySignature(doc)) { SAMLResponse = SAMLUtility.DeserializeFromXmlString <ResponseType>(doc.InnerXml); if (SAMLResponse.Items.Length > 0) { for (int i = 0; i < SAMLResponse.Items.Length; i++) { if (SAMLResponse.Items[i] is AssertionType) { NameIDType nameID = null; AssertionType assertion = (AssertionType)SAMLResponse.Items[i]; for (int j = 0; j < assertion.Subject.Items.Length; j++) { if (assertion.Subject.Items[j] is NameIDType) { nameID = (NameIDType)assertion.Subject.Items[j]; } } if (nameID != null) { SignHelper.AutenticarUsuarioDaRespostaDoSaml(nameID.Value); } } // Armazena dados do sistema emissor do Request // em Cookie de sistemas autenticados AddSAMLCookie(context); } } context.Response.Redirect(HttpUtility.UrlDecode(context.Request[HttpBindingConstants.RelayState]), false); } else { throw new ValidationException("Não foi possível encontrar assinatura."); } } // ***** REQUEST ***** else if (!String.IsNullOrEmpty(context.Request[HttpBindingConstants.SAMLRequest])) { throw new NotImplementedException(); } else { // Carrega as configurações do ServiceProvider ServiceProvider config = ServiceProvider.GetConfig(); ServiceProviderEndpoint spend = SAMLUtility.GetServiceProviderEndpoint(config.ServiceEndpoint, SAMLTypeSSO.signon); // Verifica configuração do ServiceProvider para signon if (spend == null) { throw new ValidationException("Não foi possível encontrar as configurações do ServiceProvider para signon."); } // Verifica se usuário está autenticado, caso não envia um Resquest solicitando autenticação if (!UsuarioWebIsValid()) { SAMLRequest = new SAMLAuthnRequest(); SAMLRequest.Issuer = config.id; SAMLRequest.AssertionConsumerServiceURL = context.Request.Url.AbsoluteUri; HttpRedirectBinding binding = new HttpRedirectBinding(SAMLRequest, spend.localpath); binding.SendRequest(context, spend.redirectUrl); } else { HttpContext.Current.Response.Redirect(spend.localpath, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } } } catch (ValidationException ex) { ErrorMessage(ex.Message); } catch (Exception ex) { ApplicationWEB._GravaErro(ex); ErrorMessage("Não foi possível atender a solicitação."); } }