|
18 | 18 | import java.io.IOException;
|
19 | 19 | import java.io.Writer;
|
20 | 20 |
|
21 |
| -import jakarta.servlet.FilterChain; |
22 |
| -import jakarta.servlet.ServletException; |
23 |
| -import jakarta.servlet.http.HttpServletRequest; |
24 |
| -import jakarta.servlet.http.HttpServletResponse; |
| 21 | +import org.springframework.http.HttpMethod; |
| 22 | +import org.springframework.http.MediaType; |
| 23 | +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
| 24 | +import org.springframework.security.web.util.matcher.RequestMatcher; |
| 25 | +import org.springframework.util.Assert; |
| 26 | +import org.springframework.web.filter.OncePerRequestFilter; |
25 | 27 |
|
26 | 28 | import com.nimbusds.jose.jwk.JWKMatcher;
|
27 | 29 | import com.nimbusds.jose.jwk.JWKSelector;
|
28 | 30 | import com.nimbusds.jose.jwk.JWKSet;
|
29 | 31 | import com.nimbusds.jose.jwk.source.JWKSource;
|
30 | 32 | import com.nimbusds.jose.proc.SecurityContext;
|
31 | 33 |
|
32 |
| -import org.springframework.http.HttpMethod; |
33 |
| -import org.springframework.http.MediaType; |
34 |
| -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
35 |
| -import org.springframework.security.web.util.matcher.RequestMatcher; |
36 |
| -import org.springframework.util.Assert; |
37 |
| -import org.springframework.web.filter.OncePerRequestFilter; |
| 34 | +import jakarta.servlet.FilterChain; |
| 35 | +import jakarta.servlet.ServletException; |
| 36 | +import jakarta.servlet.http.HttpServletRequest; |
| 37 | +import jakarta.servlet.http.HttpServletResponse; |
38 | 38 |
|
39 | 39 | /**
|
40 | 40 | * A {@code Filter} that processes JWK Set requests.
|
@@ -70,11 +70,27 @@ public NimbusJwkSetEndpointFilter(JWKSource<SecurityContext> jwkSource) {
|
70 | 70 | * @param jwkSetEndpointUri the endpoint {@code URI} for JWK Set requests
|
71 | 71 | */
|
72 | 72 | public NimbusJwkSetEndpointFilter(JWKSource<SecurityContext> jwkSource, String jwkSetEndpointUri) {
|
| 73 | + this(jwkSource, createDefaultRequestMatcher(jwkSetEndpointUri)); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Constructs a {@code NimbusJwkSetEndpointFilter} using the provided parameters. |
| 78 | + * |
| 79 | + * @param jwkSource the {@code com.nimbusds.jose.jwk.source.JWKSource} |
| 80 | + * @param requestMatcher the endpoint matcher for JWK Set requests |
| 81 | + */ |
| 82 | + public NimbusJwkSetEndpointFilter(JWKSource<SecurityContext> jwkSource, RequestMatcher requestMatcher) { |
73 | 83 | Assert.notNull(jwkSource, "jwkSource cannot be null");
|
74 |
| - Assert.hasText(jwkSetEndpointUri, "jwkSetEndpointUri cannot be empty"); |
| 84 | + Assert.notNull(requestMatcher, "requestMatcher cannot be null"); |
75 | 85 | this.jwkSource = jwkSource;
|
76 | 86 | this.jwkSelector = new JWKSelector(new JWKMatcher.Builder().build());
|
77 |
| - this.requestMatcher = new AntPathRequestMatcher(jwkSetEndpointUri, HttpMethod.GET.name()); |
| 87 | + this.requestMatcher = requestMatcher; |
| 88 | + } |
| 89 | + |
| 90 | + public static RequestMatcher createDefaultRequestMatcher(String jwkSetEndpointUri) { |
| 91 | + Assert.hasText(jwkSetEndpointUri, "jwkSetEndpointUri cannot be empty"); |
| 92 | + |
| 93 | + return new AntPathRequestMatcher(jwkSetEndpointUri, HttpMethod.GET.name()); |
78 | 94 | }
|
79 | 95 |
|
80 | 96 | @Override
|
|
0 commit comments