|
16 | 16 |
|
17 | 17 | package org.springframework.security.saml2.provider.service.servlet.filter;
|
18 | 18 |
|
19 |
| -import javax.servlet.http.HttpServletRequest; |
20 |
| -import javax.servlet.http.HttpServletResponse; |
21 |
| - |
22 |
| -import org.springframework.security.authentication.AbstractAuthenticationToken; |
23 |
| -import org.springframework.security.core.Authentication; |
24 |
| -import org.springframework.security.core.AuthenticationException; |
25 |
| -import org.springframework.security.saml2.core.Saml2Error; |
26 |
| -import org.springframework.security.saml2.core.Saml2ErrorCodes; |
27 |
| -import org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest; |
28 |
| -import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException; |
29 | 19 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
30 |
| -import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver; |
31 |
| -import org.springframework.security.saml2.provider.service.web.HttpSessionSaml2AuthenticationRequestRepository; |
32 |
| -import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver; |
33 |
| -import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository; |
34 |
| -import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter; |
35 |
| -import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; |
36 | 20 | import org.springframework.security.web.authentication.AuthenticationConverter;
|
37 |
| -import org.springframework.security.web.authentication.session.ChangeSessionIdAuthenticationStrategy; |
38 |
| -import org.springframework.util.Assert; |
39 | 21 |
|
40 | 22 | /**
|
41 | 23 | * @since 5.2
|
| 24 | + * @deprecated Use |
| 25 | + * {@link org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter} |
| 26 | + * instead |
42 | 27 | */
|
43 |
| -public class Saml2WebSsoAuthenticationFilter extends AbstractAuthenticationProcessingFilter { |
44 |
| - |
45 |
| - public static final String DEFAULT_FILTER_PROCESSES_URI = "/login/saml2/sso/{registrationId}"; |
46 |
| - |
47 |
| - private final AuthenticationConverter authenticationConverter; |
48 |
| - |
49 |
| - private Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository = new HttpSessionSaml2AuthenticationRequestRepository(); |
| 28 | +@Deprecated |
| 29 | +public class Saml2WebSsoAuthenticationFilter |
| 30 | + extends org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter { |
50 | 31 |
|
51 |
| - /** |
52 |
| - * Creates a {@code Saml2WebSsoAuthenticationFilter} authentication filter that is |
53 |
| - * configured to use the {@link #DEFAULT_FILTER_PROCESSES_URI} processing URL |
54 |
| - * @param relyingPartyRegistrationRepository - repository of configured SAML 2 |
55 |
| - * entities. Required. |
56 |
| - */ |
57 | 32 | public Saml2WebSsoAuthenticationFilter(RelyingPartyRegistrationRepository relyingPartyRegistrationRepository) {
|
58 |
| - this(relyingPartyRegistrationRepository, DEFAULT_FILTER_PROCESSES_URI); |
| 33 | + super(relyingPartyRegistrationRepository); |
59 | 34 | }
|
60 | 35 |
|
61 |
| - /** |
62 |
| - * Creates a {@code Saml2WebSsoAuthenticationFilter} authentication filter |
63 |
| - * @param relyingPartyRegistrationRepository - repository of configured SAML 2 |
64 |
| - * entities. Required. |
65 |
| - * @param filterProcessesUrl the processing URL, must contain a {registrationId} |
66 |
| - * variable. Required. |
67 |
| - */ |
68 | 36 | public Saml2WebSsoAuthenticationFilter(RelyingPartyRegistrationRepository relyingPartyRegistrationRepository,
|
69 | 37 | String filterProcessesUrl) {
|
70 |
| - this(new Saml2AuthenticationTokenConverter( |
71 |
| - (RelyingPartyRegistrationResolver) new DefaultRelyingPartyRegistrationResolver( |
72 |
| - relyingPartyRegistrationRepository)), |
73 |
| - filterProcessesUrl); |
74 |
| - Assert.isTrue(filterProcessesUrl.contains("{registrationId}"), |
75 |
| - "filterProcessesUrl must contain a {registrationId} match variable"); |
| 38 | + super(relyingPartyRegistrationRepository, filterProcessesUrl); |
76 | 39 | }
|
77 | 40 |
|
78 |
| - /** |
79 |
| - * Creates a {@link Saml2WebSsoAuthenticationFilter} given the provided parameters |
80 |
| - * @param authenticationConverter the strategy for converting an |
81 |
| - * {@link HttpServletRequest} into an {@link Authentication} |
82 |
| - * @param filterProcessesUrl the processing URL |
83 |
| - * @since 5.4 |
84 |
| - */ |
85 | 41 | public Saml2WebSsoAuthenticationFilter(AuthenticationConverter authenticationConverter, String filterProcessesUrl) {
|
86 |
| - super(filterProcessesUrl); |
87 |
| - Assert.notNull(authenticationConverter, "authenticationConverter cannot be null"); |
88 |
| - Assert.hasText(filterProcessesUrl, "filterProcessesUrl must contain a URL pattern"); |
89 |
| - this.authenticationConverter = authenticationConverter; |
90 |
| - setAllowSessionCreation(true); |
91 |
| - setSessionAuthenticationStrategy(new ChangeSessionIdAuthenticationStrategy()); |
92 |
| - } |
93 |
| - |
94 |
| - @Override |
95 |
| - protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) { |
96 |
| - return super.requiresAuthentication(request, response); |
97 |
| - } |
98 |
| - |
99 |
| - @Override |
100 |
| - public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) |
101 |
| - throws AuthenticationException { |
102 |
| - Authentication authentication = this.authenticationConverter.convert(request); |
103 |
| - if (authentication == null) { |
104 |
| - Saml2Error saml2Error = new Saml2Error(Saml2ErrorCodes.RELYING_PARTY_REGISTRATION_NOT_FOUND, |
105 |
| - "No relying party registration found"); |
106 |
| - throw new Saml2AuthenticationException(saml2Error); |
107 |
| - } |
108 |
| - setDetails(request, authentication); |
109 |
| - this.authenticationRequestRepository.removeAuthenticationRequest(request, response); |
110 |
| - return getAuthenticationManager().authenticate(authentication); |
111 |
| - } |
112 |
| - |
113 |
| - /** |
114 |
| - * Use the given {@link Saml2AuthenticationRequestRepository} to remove the saved |
115 |
| - * authentication request. If the {@link #authenticationConverter} is of the type |
116 |
| - * {@link Saml2AuthenticationTokenConverter}, the |
117 |
| - * {@link Saml2AuthenticationRequestRepository} will also be set into the |
118 |
| - * {@link #authenticationConverter}. |
119 |
| - * @param authenticationRequestRepository the |
120 |
| - * {@link Saml2AuthenticationRequestRepository} to use |
121 |
| - * @since 5.6 |
122 |
| - */ |
123 |
| - public void setAuthenticationRequestRepository( |
124 |
| - Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository) { |
125 |
| - Assert.notNull(authenticationRequestRepository, "authenticationRequestRepository cannot be null"); |
126 |
| - this.authenticationRequestRepository = authenticationRequestRepository; |
127 |
| - setAuthenticationRequestRepositoryIntoAuthenticationConverter(authenticationRequestRepository); |
128 |
| - } |
129 |
| - |
130 |
| - private void setAuthenticationRequestRepositoryIntoAuthenticationConverter( |
131 |
| - Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository) { |
132 |
| - if (this.authenticationConverter instanceof Saml2AuthenticationTokenConverter) { |
133 |
| - Saml2AuthenticationTokenConverter authenticationTokenConverter = (Saml2AuthenticationTokenConverter) this.authenticationConverter; |
134 |
| - authenticationTokenConverter.setAuthenticationRequestRepository(authenticationRequestRepository); |
135 |
| - } |
136 |
| - } |
137 |
| - |
138 |
| - private void setDetails(HttpServletRequest request, Authentication authentication) { |
139 |
| - if (AbstractAuthenticationToken.class.isAssignableFrom(authentication.getClass())) { |
140 |
| - Object details = this.authenticationDetailsSource.buildDetails(request); |
141 |
| - ((AbstractAuthenticationToken) authentication).setDetails(details); |
142 |
| - } |
| 42 | + super(authenticationConverter, filterProcessesUrl); |
143 | 43 | }
|
144 | 44 |
|
145 | 45 | }
|
0 commit comments