类似于注销时,使会话无效并删除 WebFlux 中的 cookie 的等效方法是什么
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.httpBasic()
.and()
.logout().clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
...
Run Code Online (Sandbox Code Playgroud) 在利用 WebFlux 的最新 Spring Security 中,安全配置的工作方式如下:
\n\nSecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {\nhttp.authorizeExchange().pathMatchers("/**") ....\nRun Code Online (Sandbox Code Playgroud)\n\n之前有一个方法 hasIpAddress("xxx.xxx.xxx.xxx") 可以用来配置IP白名单,现在没有了。
\n\n如何为新的Spring Security Webflux指定IP白名单?
\n\n基于下面@\xc3\xb6zkan pakdil 的想法,这是我的代码,但 IP 过滤器不起作用 - 来自不在白名单上的 IP 的请求仍然可以通过。
\n\nprivate Mono<AuthorizationDecision> isAuthorizedIP(Mono<Authentication> authentication, AuthorizationContext context) {\n String ip = context.getExchange().getRequest().getRemoteAddress().getAddress().toString().replace("/", "");\n\n return authentication.map((a) -> new AuthorizationDecision(\n ipWhiteList.contains(ip))); \n}\nRun Code Online (Sandbox Code Playgroud)\n\nSecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) 抛出异常 {
\n\nhttp.authorizeExchange().anyExchange().access(this::isAuthorizedIP).and().oauth2Login();
\n\n返回 http.build();
\n\n}
\n