首页 > 解决方案 > 仅对一页应用弹簧安全性

问题描述

我有一个典型的安全配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/", "/index").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll();
    //http.authorizeRequests().antMatchers("/resources/**").permitAll().anyRequest().permitAll();
}

现在 spring 要求登录除了登录页面之外的所有内容......但是我怎么能以另一种方式进行登录,所以它只要求视图/index 的登录页面?仅适用于一组端点?谢谢!

标签: javaspringsecurity

解决方案


尝试这个:

       http
        .authorizeRequests()
        .antMatchers("/", "/index").authenticated()//Makes / and /index to be authenthicated
        .anyRequest().permitAll()//Makes any other allow without authentication. Or if you want a group use antMatchers here too.
        .and()
        .formLogin()
        .loginPage("/login")
        .permitAll()
        .and()
        .logout()
        .permitAll();

推荐阅读