|
Last change
on this file was 5ea00d7, checked in by Malek Alavi <malekalavi7@…>, 7 days ago |
|
Initial project upload
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | package mk.ukim.finki.wp.db.security;
|
|---|
| 2 |
|
|---|
| 3 | import org.springframework.context.annotation.Bean;
|
|---|
| 4 | import org.springframework.context.annotation.Configuration;
|
|---|
| 5 | import org.springframework.security.config.Customizer;
|
|---|
| 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|---|
| 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|---|
| 8 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|---|
| 9 | import org.springframework.security.crypto.password.PasswordEncoder;
|
|---|
| 10 | import org.springframework.security.web.SecurityFilterChain;
|
|---|
| 11 |
|
|---|
| 12 | @Configuration
|
|---|
| 13 | @EnableWebSecurity
|
|---|
| 14 | public class SecurityConfig {
|
|---|
| 15 |
|
|---|
| 16 | @Bean
|
|---|
| 17 | public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|---|
| 18 |
|
|---|
| 19 | http
|
|---|
| 20 | .csrf(Customizer.withDefaults())
|
|---|
| 21 | .authorizeHttpRequests(auth -> auth
|
|---|
| 22 | .requestMatchers("/", "/login", "/register", "/css/**", "/js/**").permitAll()
|
|---|
| 23 | .anyRequest().authenticated()
|
|---|
| 24 | )
|
|---|
| 25 | .formLogin(form -> form
|
|---|
| 26 | .defaultSuccessUrl("/", true)
|
|---|
| 27 | .permitAll()
|
|---|
| 28 | )
|
|---|
| 29 | .logout(logout -> logout
|
|---|
| 30 | .logoutUrl("/logout")
|
|---|
| 31 | .logoutSuccessUrl("/login?logout")
|
|---|
| 32 | .permitAll()
|
|---|
| 33 | );
|
|---|
| 34 |
|
|---|
| 35 | return http.build();
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | @Bean
|
|---|
| 39 | public PasswordEncoder passwordEncoder() {
|
|---|
| 40 | return new BCryptPasswordEncoder();
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.