java - 仅将 Spring Security 应用于一页

标签 java spring security

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

@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 要求登录除登录页面之外的所有内容...但是我怎样才能以其他方式登录,因此它仅要求 View /索引登录页面?是否仅适用于一组端点? 谢谢!

最佳答案

试试这个:

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

关于java - 仅将 Spring Security 应用于一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61273204/

相关文章:

java - 我有两个几乎相同的方法,如何重构它们?

java - 考虑在您的配置中定义一个类型为 'com.repository.UserRepository' 的 bean

java - JPA多对多关系查询问题

java - JPA 可嵌入物集合

java - 在Java中确定二进制/文本文件类型?

spring - 如何避免将特定版本的 Spring Boot 放入库中

java - 简单的 Mockito 测试(Spring + Dao)

javascript - 如何在 jQuery 选择器中执行 Javascript

security - Zend 形式的随机数

c# - 在 web.config 中包含数据库密码的潜在安全风险是什么