Skip to content

Commit 567ec9c

Browse files
committed
2916 Document SecurityFilterChain configuration methods and related classes in SecurityConfiguration.
1 parent 478c790 commit 567ec9c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

server/libs/config/security-config/src/main/java/com/bytechef/security/config/SecurityConfiguration.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import jakarta.servlet.http.HttpServletRequest;
3535
import jakarta.servlet.http.HttpServletResponse;
3636
import java.util.List;
37+
import java.util.Objects;
3738
import java.util.function.Supplier;
3839
import org.apache.commons.lang3.StringUtils;
3940
import org.springframework.context.annotation.Bean;
@@ -98,6 +99,15 @@ public SecurityConfiguration(
9899
this.security = applicationProperties.getSecurity();
99100
}
100101

102+
/**
103+
* Configures the security filter chain for the actuator endpoints, specifying authorization rules, authentication
104+
* mechanisms, and exception handling.
105+
*
106+
* @param http the {@link HttpSecurity} object used to customize security settings for the actuator endpoints
107+
* @param mvc a {@link PathPatternRequestMatcher.Builder} used to create matchers for specific URI patterns
108+
* @return a configured {@link SecurityFilterChain} to handle security for actuator endpoints
109+
* @throws Exception if an error occurs while configuring the security filter chain
110+
*/
101111
@Bean
102112
@Order(2)
103113
public SecurityFilterChain actuatorFilterChain(
@@ -135,6 +145,32 @@ public SecurityFilterChain actuatorFilterChain(
135145
return http.build();
136146
}
137147

148+
/**
149+
* Configures the security filter chain for API endpoints and GraphQL requests, defining authorization,
150+
* authentication, CSRF settings, and headers for securing requests.
151+
*
152+
* @param http the {@link HttpSecurity} object used to customize the security settings
153+
* for the application.
154+
* @param mvc a {@link PathPatternRequestMatcher.Builder} used to build request
155+
* matchers.
156+
* @param authenticationProviderContributors a list of {@link AuthenticationProviderContributor} instances
157+
* contributing custom {@link AuthenticationProvider}s to handle
158+
* authentication.
159+
* @param authorizeHttpRequestContributors a list of {@link AuthorizeHttpRequestContributor} instances providing
160+
* paths to be configured as permit-all in the API security configuration.
161+
* @param csrfContributors a list of {@link CsrfContributor} instances contributing request
162+
* matchers to be ignored for CSRF protection.
163+
* @param environment the {@link Environment} object used to retrieve profiles and
164+
* environment properties.
165+
* @param filterAfterContributors a list of {@link FilterAfterContributor} instances allowing additional
166+
* filters to be added after default filters in the chain.
167+
* @param filterBeforeContributors a list of {@link FilterBeforeContributor} instances allowing additional
168+
* filters to be added before default filters in the chain.
169+
* @param spaWebFilterContributors a list of {@link SpaWebFilterContributor} instances contributing to the
170+
* customization of SPA-specific filters.
171+
* @return a configured {@link SecurityFilterChain} for securing API and GraphQL endpoints.
172+
* @throws Exception if an error occurs while configuring the security filter chain.
173+
*/
138174
@Bean
139175
@Order(3)
140176
public SecurityFilterChain apiFilterChain(
@@ -224,6 +260,22 @@ public SecurityFilterChain apiFilterChain(
224260
return http.build();
225261
}
226262

263+
/**
264+
* Configures the security filter chain for the web application, defining authorization, authentication, and the
265+
* integration of SPA-specific and permit-all contributors.
266+
*
267+
* @param http the {@link HttpSecurity} object used to customize security settings for
268+
* the application
269+
* @param mvc a {@link PathPatternRequestMatcher.Builder} used to create request
270+
* matchers for specific URI patterns
271+
* @param authorizeHttpRequestContributors a list of {@link AuthorizeHttpRequestContributor} instances providing
272+
* paths to be configured as permit-all in the security configuration
273+
*
274+
* @param spaWebFilterContributors a list of {@link SpaWebFilterContributor} instances contributing to the
275+
* customization of SPA-specific filters
276+
* @return a configured {@link SecurityFilterChain} for managing security in the application
277+
* @throws Exception if an error occurs while configuring the security filter chain
278+
*/
227279
@Bean
228280
@Order(4)
229281
public SecurityFilterChain filterChain(
@@ -268,6 +320,15 @@ public SecurityFilterChain filterChain(
268320
return http.build();
269321
}
270322

323+
/**
324+
* Configures the security filter chain for GraphQL and GraphiQL endpoints in the development profile, defining
325+
* authorization rules, authentication mechanisms, and exception handling.
326+
*
327+
* @param http the {@link HttpSecurity} object used to customize security settings for the GraphQL endpoints
328+
* @param mvc a {@link PathPatternRequestMatcher.Builder} used to create request matchers for specific URI patterns
329+
* @return a configured {@link SecurityFilterChain} for securing GraphQL and GraphiQL endpoints
330+
* @throws Exception if an error occurs while configuring the security filter chain
331+
*/
271332
@Bean
272333
@Profile("dev")
273334
@Order(1)
@@ -328,6 +389,12 @@ private String getRememberMeKey() {
328389
return rememberMe.getKey();
329390
}
330391

392+
/**
393+
* A configuration class for adding custom filters to the security filter chain after specified filters. This class
394+
* allows customization of the filter chain by applying a list of {@link FilterAfterContributor} instances.
395+
*
396+
* @param <H> the type of {@link HttpSecurityBuilder} used for configuring the security filter chain
397+
*/
331398
private static class FilterAfterContributorConfigurer<H extends HttpSecurityBuilder<HttpSecurity>>
332399
extends AbstractHttpConfigurer<FilterBeforeContributorConfigurer<H>, HttpSecurity> {
333400

@@ -347,6 +414,13 @@ public void configure(HttpSecurity http) {
347414
}
348415
}
349416

417+
/**
418+
* A private configuration class for adding and positioning filters in the web security filter chain before a
419+
* specific set of filters. This configurer uses a list of {@link FilterBeforeContributor} instances to determine
420+
* which filters should be introduced into the chain and their corresponding positions.
421+
*
422+
* @param <H> the type of {@link HttpSecurityBuilder} used to configure the web security filter chain.
423+
*/
350424
private static class FilterBeforeContributorConfigurer<H extends HttpSecurityBuilder<HttpSecurity>>
351425
extends AbstractHttpConfigurer<FilterBeforeContributorConfigurer<H>, HttpSecurity> {
352426

@@ -410,6 +484,21 @@ public String resolveCsrfTokenValue(HttpServletRequest request, CsrfToken csrfTo
410484
}
411485
}
412486

487+
/**
488+
* A custom implementation of {@link BasicAuthenticationEntryPoint} used to handle unauthorized access attempts when
489+
* basic authentication is required.
490+
*
491+
* This class extends the default functionality of {@link BasicAuthenticationEntryPoint} to customize the behavior
492+
* for responding to unauthorized requests. It specifically defines the response headers and status code returned to
493+
* the client upon an authentication failure.
494+
*
495+
* Key functionality: - Sets the "WWW-Authenticate" response header to indicate the required basic authentication
496+
* with a realm. - Responds with the HTTP 401 (Unauthorized) status code to indicate that the request requires
497+
* authentication.
498+
*
499+
* Method: {@link #commence(HttpServletRequest, HttpServletResponse, AuthenticationException)}: - Handles the
500+
* response when an {@link AuthenticationException} occurs, customizing the headers and status code.
501+
*/
413502
private static class UnauthorizedBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
414503

415504
@Override

0 commit comments

Comments
 (0)