|
64 | 64 | import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher;
|
65 | 65 | import org.springframework.security.web.util.matcher.RequestMatcher;
|
66 | 66 | import org.springframework.util.Assert;
|
| 67 | +import org.springframework.util.ClassUtils; |
67 | 68 | import org.springframework.web.accept.ContentNegotiationStrategy;
|
68 | 69 | import org.springframework.web.accept.HeaderContentNegotiationStrategy;
|
69 | 70 |
|
|
147 | 148 | public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<H>>
|
148 | 149 | extends AbstractHttpConfigurer<OAuth2ResourceServerConfigurer<H>, H> {
|
149 | 150 |
|
| 151 | + private static final boolean dPoPAuthenticationAvailable; |
| 152 | + |
| 153 | + static { |
| 154 | + ClassLoader classLoader = OAuth2ResourceServerConfigurer.class.getClassLoader(); |
| 155 | + dPoPAuthenticationAvailable = ClassUtils |
| 156 | + .isPresent("org.springframework.security.oauth2.jwt.DPoPProofJwtDecoderFactory", classLoader); |
| 157 | + } |
| 158 | + |
150 | 159 | private static final RequestHeaderRequestMatcher X_REQUESTED_WITH = new RequestHeaderRequestMatcher(
|
151 | 160 | "X-Requested-With", "XMLHttpRequest");
|
152 | 161 |
|
153 | 162 | private final ApplicationContext context;
|
154 | 163 |
|
155 |
| - private final DPoPAuthenticationConfigurer<H> dPoPAuthenticationConfigurer = new DPoPAuthenticationConfigurer<>(); |
156 |
| - |
157 | 164 | private AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver;
|
158 | 165 |
|
159 | 166 | private BearerTokenResolver bearerTokenResolver;
|
@@ -285,7 +292,10 @@ public void configure(H http) {
|
285 | 292 | filter.setSecurityContextHolderStrategy(getSecurityContextHolderStrategy());
|
286 | 293 | filter = postProcess(filter);
|
287 | 294 | http.addFilter(filter);
|
288 |
| - this.dPoPAuthenticationConfigurer.configure(http); |
| 295 | + if (dPoPAuthenticationAvailable) { |
| 296 | + DPoPAuthenticationConfigurer<H> dPoPAuthenticationConfigurer = new DPoPAuthenticationConfigurer<>(); |
| 297 | + dPoPAuthenticationConfigurer.configure(http); |
| 298 | + } |
289 | 299 | }
|
290 | 300 |
|
291 | 301 | private void validateConfiguration() {
|
|
0 commit comments