Dies ist meine pom.xml-Datei:
Code: Select all
org.springframework.boot
spring-boot-starter-parent
3.4.2
...
org.springdoc
springdoc-openapi-starter-webmvc-ui
2.6.0
Code: Select all
application.propertiesCode: Select all
# OpenApi
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
Code: Select all
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
@Bean
AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception{
return configuration.getAuthenticationManager();
}
@Bean
AuthenticationProvider authenticationProvider(WeavileUserDetailsImpl weavileUserDetailsImpl) {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(weavileUserDetailsImpl);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Bean
SecurityContextRepository securityContextRepository() {
return new NullSecurityContextRepository();
}
@Bean
PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
configuration.setAllowedOrigins(Arrays.asList(dotenv.get("CLIENT_ALLOWED")));
configuration.setAllowedMethods(Arrays.asList("GET","POST","PUT","DELETE"));
configuration.setAllowCredentials(false);
configuration.addAllowedHeader("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
@Bean
SecurityFilterChain filterChain(HttpSecurity http, AuthenticationProvider authenticationProvider,
JwtAuthenticationFilter jwtAuthenticationFilter) throws Exception {
http.headers(headersConfigurer -> headersConfigurer.frameOptions(frameOptions -> frameOptions.sameOrigin()));
http.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
http.sessionManagement(httpSecuritySessionManagementConfigurer ->
httpSecuritySessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http.authorizeHttpRequests(auth -> auth
.requestMatchers(
"/nonLoggedUsers/**","/pokemonData/**","/natureData/**",
"/itemData/allItems","/something_something/**",
"/v3/api-docs/**","/swagger-ui/**"
).permitAll()
.anyRequest().authenticated()
);
http.cors(cors -> cors.configurationSource(corsConfigurationSource()));
http.csrf(csrf -> csrf.disable());
return http.build();
}
}
Mobile version