Я пытаюсь создать веб-приложение с пользовательскими страницами и страницами администратора. Я хочу, чтобы пользователи видели пользовательские страницы без входа в систему через форму входа в систему и доступ к разделу администратора через форму входа в систему. Раздел администратора должен быть доступен через URL-адрес "/ admin_panel". Я закрепил этот URL-адрес с помощью метода configure (HttpSecurity http) , но ничего не произошло - пользовательские страницы и страницы администратора открываются без входа в систему.
WebSecurityConfig.java:
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin_panel/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin().and()
.httpBasic()
;
}
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select name,password,enabled from users where name=?")
.authoritiesByUsernameQuery("select username, role from user_roles where username=?")
.passwordEncoder(new BCryptPasswordEncoder());
}
}
WebController.java:
@Controller
public class WebController {
@GetMapping(value= {"/"})
public String index(){
return "index";
}
@GetMapping(value= {"/admin_panel/admin"})
public String admin(){
return "admin";
}
}
Что не так в моем коде?