亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么添加 spring security 后無法訪問主頁

為什么添加 spring security 后無法訪問主頁

拉風的咖菲貓 2022-12-28 16:14:22
我正在向網站添加 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()?



查看完整回答
反對 回復 2022-12-28
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號