|
|
|
@ -16,6 +16,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.security.saml2.provider.service.servlet.filter; |
|
|
|
package org.springframework.security.saml2.provider.service.servlet.filter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
import javax.servlet.FilterChain; |
|
|
|
|
|
|
|
import javax.servlet.ServletException; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.security.saml2.provider.service.authentication.OpenSamlAuthenticationRequestFactory; |
|
|
|
import org.springframework.security.saml2.provider.service.authentication.OpenSamlAuthenticationRequestFactory; |
|
|
|
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationRequestContext; |
|
|
|
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationRequestContext; |
|
|
|
@ -34,12 +41,6 @@ import org.springframework.web.util.HtmlUtils; |
|
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
|
import org.springframework.web.util.UriUtils; |
|
|
|
import org.springframework.web.util.UriUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.FilterChain; |
|
|
|
|
|
|
|
import javax.servlet.ServletException; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.lang.String.format; |
|
|
|
import static java.lang.String.format; |
|
|
|
import static java.nio.charset.StandardCharsets.ISO_8859_1; |
|
|
|
import static java.nio.charset.StandardCharsets.ISO_8859_1; |
|
|
|
import static org.springframework.util.StringUtils.hasText; |
|
|
|
import static org.springframework.util.StringUtils.hasText; |
|
|
|
@ -137,22 +138,20 @@ public class Saml2WebSsoAuthenticationRequestFilter extends OncePerRequestFilter |
|
|
|
private Saml2AuthenticationRequestContext createRedirectAuthenticationRequestContext( |
|
|
|
private Saml2AuthenticationRequestContext createRedirectAuthenticationRequestContext( |
|
|
|
RelyingPartyRegistration relyingParty, |
|
|
|
RelyingPartyRegistration relyingParty, |
|
|
|
HttpServletRequest request) { |
|
|
|
HttpServletRequest request) { |
|
|
|
String localSpEntityId = Saml2ServletUtils.getServiceProviderEntityId(relyingParty, request); |
|
|
|
String applicationUri = Saml2ServletUtils.getApplicationUri(request); |
|
|
|
return Saml2AuthenticationRequestContext |
|
|
|
Function<String, String> resolver = templateResolver(applicationUri, relyingParty); |
|
|
|
.builder() |
|
|
|
String localSpEntityId = resolver.apply(relyingParty.getLocalEntityIdTemplate()); |
|
|
|
|
|
|
|
String assertionConsumerServiceUrl = resolver.apply(relyingParty.getAssertionConsumerServiceUrlTemplate()); |
|
|
|
|
|
|
|
return Saml2AuthenticationRequestContext.builder() |
|
|
|
.issuer(localSpEntityId) |
|
|
|
.issuer(localSpEntityId) |
|
|
|
.relyingPartyRegistration(relyingParty) |
|
|
|
.relyingPartyRegistration(relyingParty) |
|
|
|
.assertionConsumerServiceUrl( |
|
|
|
.assertionConsumerServiceUrl(assertionConsumerServiceUrl) |
|
|
|
Saml2ServletUtils.resolveUrlTemplate( |
|
|
|
|
|
|
|
relyingParty.getAssertionConsumerServiceUrlTemplate(), |
|
|
|
|
|
|
|
Saml2ServletUtils.getApplicationUri(request), |
|
|
|
|
|
|
|
relyingParty.getProviderDetails().getEntityId(), |
|
|
|
|
|
|
|
relyingParty.getRegistrationId() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.relayState(request.getParameter("RelayState")) |
|
|
|
.relayState(request.getParameter("RelayState")) |
|
|
|
.build() |
|
|
|
.build(); |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Function<String, String> templateResolver(String applicationUri, RelyingPartyRegistration relyingParty) { |
|
|
|
|
|
|
|
return template -> Saml2ServletUtils.resolveUrlTemplate(template, applicationUri, relyingParty); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String htmlEscape(String value) { |
|
|
|
private String htmlEscape(String value) { |
|
|
|
|