首页 > 解决方案 > Spring 安全保护注销 url

问题描述

我在我的项目中使用弹簧安全。我使用 @PreAuthorize 注释配置安全端点。我希望 spring security 保护我在配置文件中指定的注销 URL。

protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers(LOGOUT_URL).authenticated()
            .anyRequest().permitAll()
        .and()
            .logout()
            .logoutUrl(LOGOUT_URL)
            .invalidateHttpSession(true)
            .logoutSuccessHandler(logoutSuccessHandler);
}

在这里,我允许任何请求,除了注销。我猜这个配置仅适用于 @RestController 端点。但是如何配置它以禁止未经身份验证的用户使用注销。

标签: springspring-bootspring-securitylogout

解决方案


推荐阅读