Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringBoot2.0WebFlux自定义身份验证--如何?_Spring_Security_Reactive_Spring Webflux - Fatal编程技术网

SpringBoot2.0WebFlux自定义身份验证--如何?

SpringBoot2.0WebFlux自定义身份验证--如何?,spring,security,reactive,spring-webflux,Spring,Security,Reactive,Spring Webflux,SpringBoot2.0安全性的最低配置有很多例子,编译与否取决于您尝试的里程碑或候选版本 什么是非HTTP基本的最小配置,它将(1)允许我访问HTTP请求(头、cookie等)并调用我自己的身份验证管理器 我希望查看标题和cookie,并根据这些用户来决定用户是谁,以及用户是否经过身份验证。我如何做到这一点对这个答案并不重要——问题是,什么是最小的Spring安全配置,以允许我连接到安全基础设施,从而使我的身份验证在反应端点中 编辑: 这适用于SpringBoot2.0.0.RC2,所以我的

SpringBoot2.0安全性的最低配置有很多例子,编译与否取决于您尝试的里程碑或候选版本

什么是非HTTP基本的最小配置,它将(1)允许我访问HTTP请求(头、cookie等)并调用我自己的身份验证管理器

我希望查看标题和cookie,并根据这些用户来决定用户是谁,以及用户是否经过身份验证。我如何做到这一点对这个答案并不重要——问题是,什么是最小的Spring安全配置,以允许我连接到安全基础设施,从而使我的身份验证在反应端点中

编辑:

这适用于SpringBoot2.0.0.RC2,所以我的问题可能是,这是将自定义身份验证引入SpringSecurity的正确方法吗

@Configuration
@EnableWebFluxSecurity
public class SecurityConfiguration {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {

        AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(authentication -> {
            authentication.setAuthenticated(true);
            return Mono.just(authentication);
        });

        authenticationFilter.setAuthenticationConverter(serverWebExchange ->
                Mono.just(new AbstractAuthenticationToken(new ArrayList<>()) {
                    @Override
                    public Object getCredentials() {
                        return null;
                    }

                    @Override
                    public Object getPrincipal() {
                        return "jim";
                    }
                }));

        return http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.FORM_LOGIN)
                .authorizeExchange()
                .anyExchange()
                .authenticated()
                .and()
                .build();
    }
}
@配置
@启用WebFluxSecurity
公共类安全配置{
@豆子
公共安全WebFilterChain springSecurityFilterChain(ServerHttpSecurity http){
AuthenticationWebFilter authenticationFilter=新建AuthenticationWebFilter(身份验证->{
authentication.setAuthenticated(true);
返回Mono.just(身份验证);
});
authenticationFilter.setAuthenticationConverter(serverWebExchange->
Mono.just(新的AbstractAuthenticationToken(新的ArrayList()){
@凌驾
公共对象getCredentials(){
返回null;
}
@凌驾
公共对象getPrincipal(){
返回“jim”;
}
}));
返回http.addFilterAt(authenticationFilter,SecurityWebFiltersOrder.FORM\u登录)
.授权交易所()
.anyExchange()
.authenticated()
.及()
.build();
}
}
您可以想象,在转换器中,我可以通过serverWebExchange自由地查看请求,并检查我想要的任何头或cookie,稍后在上lambda(代表ReactiveAuthenticationManager)中,我可以实际决定是否应该对其进行身份验证