|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import org.springframework.http.HttpMethod;
|
20 | 20 | import org.springframework.security.core.Authentication;
|
21 | 21 | import org.springframework.security.core.AuthenticationException;
|
| 22 | +import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException; |
22 | 23 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken;
|
| 24 | +import org.springframework.security.saml2.provider.service.authentication.Saml2Error; |
23 | 25 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
24 | 26 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
25 | 27 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
|
32 | 34 | import javax.servlet.http.HttpServletResponse;
|
33 | 35 |
|
34 | 36 | import static java.nio.charset.StandardCharsets.UTF_8;
|
| 37 | +import static org.springframework.security.saml2.provider.service.authentication.Saml2ErrorCodes.RELYING_PARTY_REGISTRATION_NOT_FOUND; |
35 | 38 | import static org.springframework.util.StringUtils.hasText;
|
36 | 39 |
|
37 | 40 | /**
|
@@ -86,8 +89,14 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
|
86 | 89 | byte[] b = Saml2Utils.decode(saml2Response);
|
87 | 90 |
|
88 | 91 | String responseXml = inflateIfRequired(request, b);
|
| 92 | + String registrationId = this.matcher.matcher(request).getVariables().get("registrationId"); |
89 | 93 | RelyingPartyRegistration rp =
|
90 |
| - this.relyingPartyRegistrationRepository.findByRegistrationId(this.matcher.matcher(request).getVariables().get("registrationId")); |
| 94 | + this.relyingPartyRegistrationRepository.findByRegistrationId(registrationId); |
| 95 | + if (rp == null) { |
| 96 | + Saml2Error saml2Error = new Saml2Error(RELYING_PARTY_REGISTRATION_NOT_FOUND, |
| 97 | + "Relying Party Registration not found with ID: " + registrationId); |
| 98 | + throw new Saml2AuthenticationException(saml2Error); |
| 99 | + } |
91 | 100 | String localSpEntityId = Saml2Utils.getServiceProviderEntityId(rp, request);
|
92 | 101 | final Saml2AuthenticationToken authentication = new Saml2AuthenticationToken(
|
93 | 102 | responseXml,
|
|
0 commit comments