2525import org .springframework .security .authentication .AuthenticationManager ;
2626import org .springframework .security .authentication .AuthenticationManagerResolver ;
2727import org .springframework .security .authentication .AuthenticationProvider ;
28+ import org .springframework .security .config .Customizer ;
2829import org .springframework .security .config .annotation .web .HttpSecurityBuilder ;
2930import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
3031import org .springframework .security .config .annotation .web .configurers .CsrfConfigurer ;
6566 * <li>{@link #accessDeniedHandler(AccessDeniedHandler)}</li> - customizes how access denied errors are handled
6667 * <li>{@link #authenticationEntryPoint(AuthenticationEntryPoint)}</li> - customizes how authentication failures are handled
6768 * <li>{@link #bearerTokenResolver(BearerTokenResolver)} - customizes how to resolve a bearer token from the request</li>
68- * <li>{@link #jwt()} - enables Jwt-encoded bearer token support</li>
69+ * <li>{@link #jwt(Customizer)} - enables Jwt-encoded bearer token support</li>
70+ * <li>{@link #opaqueToken(Customizer)} - enables opaque bearer token support</li>
6971 * </ul>
7072 *
7173 * <p>
72- * When using {@link #jwt()}, either
74+ * When using {@link #jwt(Customizer )}, either
7375 *
7476 * <ul>
7577 * <li>
8385 * </li>
8486 * </ul>
8587 *
86- * Also with {@link #jwt()} consider
88+ * Also with {@link #jwt(Customizer )} consider
8789 *
8890 * <ul>
8991 * <li>
9395 * </ul>
9496 *
9597 * <p>
96- * When using {@link #opaque( )}, supply an introspection endpoint and its authentication configuration
98+ * When using {@link #opaqueToken(Customizer )}, supply an introspection endpoint and its authentication configuration
9799 * </p>
98100 *
99101 * <h2>Security Filters</h2>
100102 *
101- * The following {@code Filter}s are populated when {@link #jwt()} is configured:
103+ * The following {@code Filter}s are populated when {@link #jwt(Customizer )} is configured:
102104 *
103105 * <ul>
104106 * <li>{@link BearerTokenAuthenticationFilter}</li>
@@ -180,6 +182,22 @@ public JwtConfigurer jwt() {
180182 return this .jwtConfigurer ;
181183 }
182184
185+ /**
186+ * Enables Jwt-encoded bearer token support.
187+ *
188+ * @param jwtCustomizer the {@link Customizer} to provide more options for
189+ * the {@link JwtConfigurer}
190+ * @return the {@link OAuth2ResourceServerConfigurer} for further customizations
191+ * @throws Exception
192+ */
193+ public OAuth2ResourceServerConfigurer <H > jwt (Customizer <JwtConfigurer > jwtCustomizer ) throws Exception {
194+ if ( this .jwtConfigurer == null ) {
195+ this .jwtConfigurer = new JwtConfigurer (this .context );
196+ }
197+ jwtCustomizer .customize (this .jwtConfigurer );
198+ return this ;
199+ }
200+
183201 public OpaqueTokenConfigurer opaqueToken () {
184202 if (this .opaqueTokenConfigurer == null ) {
185203 this .opaqueTokenConfigurer = new OpaqueTokenConfigurer (this .context );
@@ -188,6 +206,23 @@ public OpaqueTokenConfigurer opaqueToken() {
188206 return this .opaqueTokenConfigurer ;
189207 }
190208
209+ /**
210+ * Enables opaque bearer token support.
211+ *
212+ * @param opaqueTokenCustomizer the {@link Customizer} to provide more options for
213+ * the {@link OpaqueTokenConfigurer}
214+ * @return the {@link OAuth2ResourceServerConfigurer} for further customizations
215+ * @throws Exception
216+ */
217+ public OAuth2ResourceServerConfigurer <H > opaqueToken (Customizer <OpaqueTokenConfigurer > opaqueTokenCustomizer )
218+ throws Exception {
219+ if (this .opaqueTokenConfigurer == null ) {
220+ this .opaqueTokenConfigurer = new OpaqueTokenConfigurer (this .context );
221+ }
222+ opaqueTokenCustomizer .customize (this .opaqueTokenConfigurer );
223+ return this ;
224+ }
225+
191226 @ Override
192227 public void init (H http ) throws Exception {
193228 registerDefaultAccessDeniedHandler (http );
0 commit comments