Spring-security配置代码

@Configuration
    public static class WebSecurityConfigurer extends WebSecurityConfigurerAdapter{
        
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .formLogin()
            .and()
                .logout()
                    .invalidateHttpSession(true)
                    .logoutUrl("/logout").logoutSuccessUrl("/")
                    .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .and()
                .sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
            .and()
                .authorizeRequests()
//                    .antMatchers("/test").permitAll()
//                    .antMatchers("/**").authenticated()
                    .anyRequest().authenticated();
        }
    }
原文地址:https://www.cnblogs.com/kingsy/p/6635562.html