java - HttpSecurity 配置 - permitall 仍然需要基本身份验证

标签 java spring spring-mvc spring-security

我正在尝试向我的应用程序添加一个不安全的 Controller 端点 /foo/bar,但每当我尝试调用它时,我都会收到 401 Unauthorized

这是我的 WebSecurityConfigurerAdapter:

http
    .authorizeRequests()
        .antMatchers("/foo/**").permitAll()
    .and()
    .formLogin()
        .loginPage("/login").permitAll()
    .and()
    .requestMatchers()
        .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
    .and()
    .authorizeRequests()
        .anyRequest().authenticated();

有人能指出我遗漏了什么吗?

最佳答案

在一个 authorizeRequests 部分中连接多个 antMatchers:

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

关于java - HttpSecurity 配置 - permitall 仍然需要基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36252941/

相关文章:

java - 检测 PNG 图像在处理中何时为 "wiped transparent"?

java - 将Web项目部署到Tomcat7后出现404错误

java - Spring Security 的特殊登录

java - 如何从易于控制和监视的 JVM 生成 JVM?

java - 特定的java正则表达式

java - SSLEngine 并关闭

java - "No Hibernate Session bound to thread",事务方法中断下一个事务的执行

java - 类加载器错误 - 加载器 org.springframework.boot.devtools.restart.classloader.RestartClassLoader 的未命名模块

java - Spring 3.1.1 MVC @Cacheable 没有被击中

java - Keycloak - antMatcher 与请求的路径 Java 不匹配