【问题标题】:Apply spring security only to one page仅对一页应用弹簧安全性
【发布时间】:2023-03-08 22:21:01
【问题描述】:

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

@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 的登录页面?仅适用于一组端点? 谢谢!

【问题讨论】:

    标签: java spring security


    【解决方案1】:

    试试这个:

           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();
    

    【讨论】:

    • 非常感谢!完美工作:)
    猜你喜欢
    • 2013-07-16
    • 2015-04-19
    • 1970-01-01
    • 2019-03-03
    • 2023-01-03
    • 2012-01-07
    • 2017-05-08
    • 2016-06-19
    • 2020-09-19
    相关资源
    最近更新 更多