blob: 83594057d1138a6531d362a3ffb61805db44f8db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package com.example.spring.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
@Bean
public PasswordEncoder passwordEncoder() {
// An Argon2 password encoder with a salt length of 16 bytes, a hash length of 32 bytes, parallelism of 1, memory cost of 1 << 14 (i.e. 16MB) and 2 iterations.
return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
}
// @Bean
// public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// http
// //.csrf(csrf -> csrf.disable()) // Disable for stateless REST APIs
// .authorizeHttpRequests(auth -> auth
// .requestMatchers("/somepath/**").permitAll() // Publicly available
// .requestMatchers("/admin/**").hasRole("ADMIN") // Requires ROLE_ADMIN
// .requestMatchers("/contact/**").hasAnyRole("USER", "ADMIN")
// .anyRequest().authenticated()
// );
// return http.build();
// }
}
|