栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过WebFlux的证书认证?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过WebFlux的证书认证?

我认为没有像Spring的早期版本中那样有X509过滤器,因此您必须实现自己的版本。幸运的是,

org.springframework.security.web.server.authentication.AuthenticationWebFilter
该工具为身份验证流程提供了模式,但是您必须自己从证书/请求中提取主题。

您要做的第一件事是设置身份验证转换器,以从证书中提取主题。

public class X509AuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {    @Override    public Mono<Authentication> apply(ServerWebExchange exchange) {        ServerHttpRequest request = exchange.getRequest();        try {// extract credentials hereAuthentication authentication = ...return Mono.just(authentication);        } catch (Exception e) {// log error herereturn Mono.empty();        }    }}

现在在我们的配置中,我们创建过滤器和转换器bean,并将转换器设置到过滤器中。

@Beanpublic X509AuthenticationConverter x509AuthenticationConverter() {    return new X509AuthenticationConverter();}@Beanpublic AuthenticationWebFilter x509AuthenticationWebFilter(ReactiveAuthenticationManager reactiveAuthenticationManager,   X509AuthenticationConverter x509AuthenticationConverter) {    AuthenticationWebFilter authenticationWebFilter = new AuthenticationWebFilter(reactiveAuthenticationManager);    authenticationWebFilter.setAuthenticationConverter(x509AuthenticationConverter);    return authenticationWebFilter;}

最后配置安全性

@BeanSecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http, AuthenticationWebFilter x509AuthenticationWebFilter) {    return http .addFilterAt(x509AuthenticationWebFilter, SecurityWebFiltersOrder.AUTHENTICATION) //... .build();}

这将与其他身份验证机制一样有效。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375084.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号