小编SRI*_*THY的帖子

为什么 Spring Boot 会因为 URL 未规范化而拒绝 GET 请求?

我正在尝试将 Spring 应用程序迁移到 Spring Boot。在 tomcat 服务器上运行应用程序时,出现以下错误:

由于 URL 未规范化,请求被拒绝。

我尝试在我的入口点类中添加以下 bean 来解决错误。

    @Bean
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver bean = new InternalResourceViewResolver();
        bean.setPrefix("/WEB-INF/ui/");
        bean.setSuffix(".jsp");
        return bean;
    }

    @Bean
    public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
        firewall.setAllowUrlEncodedSlash(true);    
        return firewall;
    }

    @Bean
    public StrictHttpFirewall httpFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
        firewall.setAllowSemicolon(true);
        return firewall;
    }

    @Bean
    public HttpFirewall defaultHttpFirewall() {
        return new DefaultHttpFirewall();
    }

    public void configure(WebSecurity web) throws Exception {
        web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
    }
Run Code Online (Sandbox Code Playgroud)

错误日志:

org.springframework.security.web.firewall.RequestRejectedException: The request was rejected …
Run Code Online (Sandbox Code Playgroud)

java authentication spring-boot

3
推荐指数
1
解决办法
9120
查看次数

标签 统计

authentication ×1

java ×1

spring-boot ×1