【发布时间】:2020-09-17 20:53:33
【问题描述】:
我正在根据其他应用提供的 API 调用从我的应用远程注销。 通常,当用户使用我的应用程序注销时,我使用 Spring .logout().deleteCookies()。
现在我们为许多应用程序使用一个授权服务器,我们需要确保从其中注销也会注销其他应用程序。
所以基本的想法是授权服务器将调用我的 API 比如说 /user/logout 当我接到这个电话时,我想要和 spring .logout().deleteCookies() 一样的东西。我怎样才能做到这一点?
是否可以将新 API 添加到 Spring 配置中?说改变这个配置:
.logout()
.logoutUrl(logoutUrl)
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
类似于:
.logout()
.logoutUrl(logoutUrl || 'api/user/logout)
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
?
我的整个spring配置是:
http
.addFilterBefore(new RedirectUrlFilter(projectDomainPath), OAuth2LoginAuthenticationFilter.class)
.csrf().disable().cors()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and()
.authorizeRequests().antMatchers("/static/**", "/logout", "/api/user/k_push_not_before", "/api/user/k_logout").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JwtAuthorizationFilter(authenticationManager(), secret, clientId, "nblues", tokenVerificationUrl))
.logout()
.logoutUrl(logoutUrl)
.logoutRequestMatcher(new AntPathRequestMatcher("/api/user/k_push_not_before"))
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessHandler(new CustomLogoutSuccessHandler())
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.and()
.oauth2Login()
.loginPage(DEFAULT_AUTHORIZATION_REQUEST_BASE_URI + "/" + realm);
【问题讨论】:
标签: spring cookies spring-security session-cookies