blob: da4b088fb6479c162e50a3c3add2d8435c51a696 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package org.berzerkula.builddb.config;
import org.berzerkula.builddb.BuilddbConstants;
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.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
//.requiresChannel(channel -> channel.anyRequest().requiresSecure())
.authorizeHttpRequests( auth -> auth
.requestMatchers("/").permitAll()
.requestMatchers("/actuator/health","/actuator/info").permitAll()
.requestMatchers("/actuator/**").hasRole(BuilddbConstants.ROLE_ADMIN)
.requestMatchers("/contact").permitAll()
.requestMatchers("/pkgs/**").hasRole(BuilddbConstants.ROLE_CLIENT)
.requestMatchers("/register").permitAll()
.requestMatchers("/login").permitAll()
.requestMatchers("/logout").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/login")
.usernameParameter("email")
.passwordParameter("password")
.defaultSuccessUrl("/", true)
)
.logout(config -> config.logoutSuccessUrl("/"))
.headers(headers -> headers
.httpStrictTransportSecurity(hsts -> hsts
.includeSubDomains(true)
.maxAgeInSeconds(40)
.preload(false)))
.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
|