我创建了一个使用 Keycloak 12.0.1 作为身份提供程序的应用程序。\n单点登录工作正常,“本地注销”也很好。
\n问题是单点退出。
\n我在网上搜索了文档和问题,但一无所获。\n下面的日志描述了三种失败的情况。
\n最后的问题是:
\nkeycloakCsrfRequestMatcher() 方法将库拥有的端点(如“k_logout”)从 csrf 保护中释放,但不是我自己的 url“/sso/logout”。也许可以编写我自己的匹配器,但这超出了我作为开发人员的经验。
\nimport java.util.Arrays;\nimport java.util.List;\n\nimport javax.annotation.PostConstruct;\n\nimport org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;\nimport org.keycloak.adapters.springsecurity.KeycloakSecurityComponents;\nimport org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;\nimport org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;\nimport org.keycloak.adapters.springsecurity.filter.KeycloakSecurityContextRequestFilter;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.EnvironmentAware;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.ComponentScan;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Profile;\nimport org.springframework.core.env.Environment;\nimport org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;\nimport org.springframework.security.config.annotation.web.builders.HttpSecurity;\nimport org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;\nimport org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;\nimport org.springframework.security.core.session.SessionRegistryImpl;\nimport org.springframework.security.web.authentication.logout.LogoutFilter;\nimport org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;\nimport org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;\nimport org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter;\n\n@Profile("KC")\n@Configuration\n@EnableWebSecurity\n@ComponentScan(basePackageClasses = …Run Code Online (Sandbox Code Playgroud)