当我使用.html url调用时,Spring Security没有阻塞

问题描述 投票:-1回答:1

当我尝试使用扩展名为.html的页面调用页面时:localhost:5000 / user.html它不会重定向到403.当我调用localhost:5000 / user时,它会重定向而没有问题。

我怎样才能使它适用于这两种情况?

@GetMapping("/user")
public String user() {
    return "/user";
}

和安全配置

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/", "/index", "/subscribed", "/paypal").permitAll()
            .antMatchers("/user").hasAnyAuthority(ROLE.ADMIN.getName())
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll()
            .and()
            .exceptionHandling().accessDeniedHandler(accessDeniedHandler);
}
java spring authentication spring-security authorization
1个回答
0
投票

如果你想要一个通用的重定向,那么从user和user.html,user.htm等用户开始。然后在最后使用*。

    @GetMapping("/user*")
    public String user() {
        return "/user";
    }

如果您只想专门为user和user.html使用

   @GetMapping(value={"/user", "/user.html"})
    public String user() {
        return "/user";
   }
© www.soinside.com 2019 - 2024. All rights reserved.