我正在向網站添加 spring security 我的目標是向所有用戶顯示所有圖像、home.html 和 index.html(無需登錄)。我已經允許對圖像和主頁和索引頁面的所有請求,但匿名用戶仍然無法在不登錄的情況下進入主頁我的安全配置 Javaprotected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/admin").hasRole("ADMIN") .antMatchers("/", "home", "index").permitAll() .antMatchers("/styles.css", "/css/**", "/js/**", "/fonts/**", "/images/**").permitAll() .anyRequest().hasRole("USER") .and() .formLogin() .loginPage("/login") .failureUrl("/login?login_error=1") .permitAll() .and() .logout() .logoutSuccessUrl("/") .permitAll();}我的 index.html 頁面<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> <body> <a href="login" class="btn btn-outline-danger btn-lg">login page </a> <a href="home" class="btn btn-outline-danger btn-lg">home page</a> </body></html>
1 回答

當年話下
TA貢獻1890條經驗 獲得超9個贊
您是否嘗試過這樣的重構: .antMatchers("/", "home", "index").permitAll()
-> .antMatchers("/", "/home", "/index").permitAll()
?
添加回答
舉報
0/150
提交
取消