Я получил HTTP-ОШИБКУ 403, сообщающую, что у меня нет разрешения на просмотр этой страницы.
Вот код в моем SecurityConfig.java
Код: Выделить всё
package com.firstweb.web.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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
public class SecurityConfig {
private final CustomUserDetailsService userDetailsService;
public SecurityConfig(CustomUserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
@Bean
public static PasswordEncoder passwordEncoder () {
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests((authz) -> authz
.requestMatchers("/login", "/register", "/clubs", "/static/**", "/css/**", "/js/**")
.permitAll()
)
.formLogin((form) -> form
.loginPage("/login")
.defaultSuccessUrl("/clubs?success")
.loginProcessingUrl("/login")
.failureUrl("/login?error=true")
.permitAll()
)
.logout((logout) -> logout
.logoutUrl("/logout")
.permitAll())
;
return http.build();
}
public void configure(AuthenticationManagerBuilder builder) throws Exception {
builder.userDetailsService(userDetailsService).passwordEncoder((passwordEncoder()));
}
}
Я пытаюсь вернуться назад, войти снова, и все работает! Я не знаю, почему это всегда терпит неудачу с первого раза.
Подробнее здесь: https://stackoverflow.com/questions/786 ... y-to-login
Мобильная версия