springSecurity5 重定向登錄頁面后 報錯:嘗試清除 Cookie.net::ERR_TOO_MANY_REDIRECTS status:200


springSecurity5 使用:

http.formLogin().loginPage("/login");
報錯如下圖:

 

springsucurity5 中 需要給 自己定義的請求加權限:

失敗代碼如下:

public class MySecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
//定制請求的授權規則
        http.authorizeRequests().antMatchers("/").permitAll()
                .antMatchers("/manage/**").hasRole("manage")
                .antMatchers("/view/**").hasRole("view")
                .antMatchers("/db/**").hasRole("db").anyRequest().authenticated();
        http.formLogin().loginPage("/login");

修正后代碼如下:

public class MySecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/").permitAll()
                .antMatchers("/login").permitAll()
                .antMatchers("/manage/**").hasRole("manage")
                .antMatchers("/view/**").hasRole("view")
                .antMatchers("/db/**").hasRole("db").anyRequest().authenticated();
//http.formLogin();
        http.formLogin().loginPage("/login");

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM