Keycloak spring-security 适配器:antMatchers("/**").authenticated() 不启动身份验证过程

2024-01-31

我正在使用 spring-security 5.2 并在配置中编写以下内容http.csrf().disable().authorizeRequests() .antMatchers("/login*", "/js/**", "/css/**", "/vendors/**", "/images/**").permitAll() .antMatchers("/**").authenticated();

应用程序的网址就像http://localhost:8080/myApp http://localhost:8080/myApp问题是当我调用应用程序 url 时,不会调用身份验证入口点。

仅当我将最后一行修改为 .antMatchers("/main*").authenticated(); 之类的内容时然后打电话http://localhost:8080/myApp/main http://localhost:8080/myApp/main一切正常。

我正在配置 Keycloak SSO 服务器 (7.0.1) + 使用 Keycloak Spring 安全适配器。所以我想知道,为什么在 .antMatchers("/**").authenticated() 的情况下不调用 Keycloak 入口点,并且只有在我编写类似 .antMatchers("/main*").authenticated( 的内容时才会调用 Keycloak 入口点)。

谁能解释我的原始代码有什么问题吗?

Thanks


您的 spring security 配置类扩展了 KeycloakWebSecurityConfigurerAdapter 并且您调用 super.configure(http) ?如果是,那么您的登录页面不是 /login 而是 /sso/login。注销成功页面映射到/。当映射注销成功页面时,Spring会自动将其安全性设置为permitAll。因此,您可以尝试将注销成功页面更改为另一个网址,以检查是否可以解决您的问题 就像是

    http.csrf().disable().authorizeRequests()
    .antMatchers("/js/**", "/css/**", "/vendors/**", "/images/**").permitAll()
    .antMatchers("/**").authenticated()
    .anyRequest().permitAll()
    .and().logout().logoutSuccessUrl("/loggedout");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Keycloak spring-security 适配器:antMatchers("/**").authenticated() 不启动身份验证过程 的相关文章

随机推荐