Я настроил пружинную защиту.Я создал форму входа, чтобы войти в свое приложение.Но получение запрещенной ошибки для любого авторизованного URL-адреса "USER" или "ADMIN".Но все разрешения Все разрешения URL работают нормально.
В файле конфигурации ...
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/bootstrap/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/home").hasRole("user")
.antMatchers("/admin").hasRole("admin")
.antMatchers("/**").denyAll()
.and()
.formLogin()
.loginPage("/")
.permitAll()
.and()
.logout()
.permitAll()
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(new BCryptPasswordEncoder());
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
}
В классе контроллера
@Controller
public class HomeController {
@RequestMapping(value= {"/", "/index"}, method=RequestMethod.GET)
public String showHome() {
return "index";
}
@RequestMapping(value="/home")
public String login() {
return "home";
}
@RequestMapping(value="/admin")
public String showDashboard() {
return "dashboard";
}
}
В форме входа,
<form class="form-signin" th:action="@{/}" method="post">
...
...
...
</form>
В pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
NB Приложение скомпилировано и успешно запущено, трассировка стека не указана.Просто дай мне запрещенную ошибку.
Не могу найти, где я допустил ошибку.Пожалуйста, вы можете мне помочь?
Заранее спасибо.