小编Han*_*ans的帖子

Spring Security WebFlux 注销

类似于注销时,使会话无效并删除 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)

spring-security spring-boot spring-webflux

5
推荐指数
1
解决办法
2746
查看次数

Spring Security WebFlux IP 白名单

在利用 WebFlux 的最新 Spring Security 中,安全配置的工作方式如下:

\n\n
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {\nhttp.authorizeExchange().pathMatchers("/**") ....\n
Run 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\n
private 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}\n
Run Code Online (Sandbox Code Playgroud)\n\n

SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) 抛出异常 {

\n\n

http.authorizeExchange().anyExchange().access(this::isAuthorizedIP).and().oauth2Login();

\n\n

返回 http.build();

\n\n

}

\n

spring spring-security spring-boot

3
推荐指数
1
解决办法
2378
查看次数