openvidu-server: update SecurityConfig.java to be reused

v2
pabloFuente 2025-11-02 17:50:03 +01:00
parent 0f22d6310d
commit 1b4e3f29d8
1 changed files with 38 additions and 20 deletions

View File

@ -49,10 +49,31 @@ public class SecurityConfig {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// Configure CORS and CSRF
configureHttpSecurity(http);
// Configure authorization rules
configureAuthorization(http);
// Configure HTTP Basic authentication
http.httpBasic(httpBasic -> {});
return http.build();
}
/**
* Configure CORS and CSRF settings. Can be overridden by subclasses.
*/
protected void configureHttpSecurity(HttpSecurity http) throws Exception {
http.cors(cors -> cors.disable()) http.cors(cors -> cors.disable())
.csrf(csrf -> csrf.disable()) .csrf(csrf -> csrf.disable());
.authorizeHttpRequests(auth -> { }
/**
* Configure authorization rules for CE. Can be extended by PRO subclass.
*/
protected void configureAuthorization(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> {
auth.requestMatchers(HttpMethod.GET, RequestMappings.API + "/config/openvidu-publicurl").permitAll() auth.requestMatchers(HttpMethod.GET, RequestMappings.API + "/config/openvidu-publicurl").permitAll()
.requestMatchers(HttpMethod.GET, RequestMappings.ACCEPT_CERTIFICATE).permitAll() .requestMatchers(HttpMethod.GET, RequestMappings.ACCEPT_CERTIFICATE).permitAll()
.requestMatchers("/openvidu/**").permitAll() // Allow WebSocket connections .requestMatchers("/openvidu/**").permitAll() // Allow WebSocket connections
@ -67,10 +88,7 @@ public class SecurityConfig {
} else { } else {
auth.requestMatchers(HttpMethod.GET, RequestMappings.RECORDINGS + "/**").hasRole("ADMIN"); auth.requestMatchers(HttpMethod.GET, RequestMappings.RECORDINGS + "/**").hasRole("ADMIN");
} }
}) });
.httpBasic(httpBasic -> {});
return http.build();
} }
@Bean @Bean