feature: enable CORS configuration (#1771)
This commit is contained in:
parent
c18430752a
commit
62931a1836
@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.webgoat.container;
|
package org.owasp.webgoat.container;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.owasp.webgoat.container.users.UserService;
|
import org.owasp.webgoat.container.users.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -43,6 +44,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
|||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
|
||||||
/** Security configuration for WebGoat. */
|
/** Security configuration for WebGoat. */
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -83,6 +87,7 @@ public class WebSecurityConfig {
|
|||||||
oidc.loginPage("/login");
|
oidc.loginPage("/login");
|
||||||
})
|
})
|
||||||
.logout(logout -> logout.deleteCookies("JSESSIONID").invalidateHttpSession(true))
|
.logout(logout -> logout.deleteCookies("JSESSIONID").invalidateHttpSession(true))
|
||||||
|
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||||
.csrf(csrf -> csrf.disable())
|
.csrf(csrf -> csrf.disable())
|
||||||
.headers(headers -> headers.disable())
|
.headers(headers -> headers.disable())
|
||||||
.exceptionHandling(
|
.exceptionHandling(
|
||||||
@ -91,6 +96,17 @@ public class WebSecurityConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
|
configuration.addAllowedOriginPattern(CorsConfiguration.ALL);
|
||||||
|
configuration.setAllowedMethods(List.of(CorsConfiguration.ALL));
|
||||||
|
configuration.setAllowedHeaders(List.of(CorsConfiguration.ALL));
|
||||||
|
configuration.setAllowCredentials(true);
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.userDetailsService(userDetailsService);
|
auth.userDetailsService(userDetailsService);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user