File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
java/com/helper/vavahelper/Config Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 44
55import org .springframework .context .annotation .Bean ;
66import org .springframework .context .annotation .Configuration ;
7+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
78import org .springframework .security .core .userdetails .UserDetailsService ;
89import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
910import org .springframework .security .crypto .password .PasswordEncoder ;
11+ import org .springframework .security .web .SecurityFilterChain ;
1012
1113@ Configuration
1214public class SecurityConfig {
@@ -27,4 +29,19 @@ public UserDetailsService userDetailsService(UserRepository userRepository) {
2729 public PasswordEncoder passwordEncoder () {
2830 return new BCryptPasswordEncoder ();
2931 }
32+
33+ //Filtro de configuração para utilizar o H2
34+ @ Bean
35+ public SecurityFilterChain securityFilterChain (HttpSecurity http ) throws Exception {
36+ http
37+ .authorizeHttpRequests (auth -> auth
38+ .requestMatchers ("/h2/*" ).hasRole ("ADMIN" ) // Apenas ADMIN pode acessar o H2.
39+ .anyRequest ().authenticated ()
40+ )
41+ .csrf (csrf -> csrf .ignoringRequestMatchers ("/h2/*" )) // Desativa CSRF ao H2.
42+ .headers (headers -> headers .frameOptions ().disable ())
43+ .formLogin (); // Tela de login do Spring Security.
44+
45+ return http .build ();
46+ }
3047}
Original file line number Diff line number Diff line change 1- # Configuração do banco de dados para o ambiente de desenvolvimento (DSV)
2- spring.datasource.url =jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=FALSE
1+ # Configuração do banco de dados para o ambiente de desenvolvimento (DSV)
2+ spring.datasource.url =jdbc:h2:mem:apidsv
33spring.datasource.driver-class-name =org.h2.Driver
44spring.datasource.username =sa
55spring.datasource.password =123
66
7- # Configuração do Hibernate (JPA)
7+ # Configuração do Hibernate (JPA)
88spring.jpa.database-platform =org.hibernate.dialect.H2Dialect
99spring.jpa.hibernate.ddl-auto =update
1010spring.jpa.show-sql =true
1111
12- # Habilitar o console web do H2 para visualizar os dados do banco
13- spring.h2.console.path =/h2
12+ # Habilitar o console web do H2 para visualizar os dados do banco
13+ spring.h2.console.path =/h2
14+ spring.jpa.defer-datasource-initialization =true
You can’t perform that action at this time.
0 commit comments