安全webflux如何设置身份验证(客户登录界面)?

时间:2019-12-27 03:08:57

标签: java spring-security spring-webflux

我已经在安全性webflux中设置了http.formLogin()。disable()。

@Bean
SecurityWebFilterChain webFluxSecurityFilterChain(ServerHttpSecurity http) {
    http
            .securityMatcher(webExchangeMatcher)
            .formLogin()
            .disable()
            .httpBasic()
            .disable()
            .exceptionHandling().accessDeniedHandler(deniedHandler)
            .and().authorizeExchange()
            .pathMatchers("/login/**", "/**/v2/api-docs").permitAll()
            .anyExchange().authenticated()
            .and().csrf().disable();
    return http.build();
}

现在我的问题是如何在自定义登录界面中登录? 下一个代码没用

@RequestMapping(value = "/login/admin/web/login", method = RequestMethod.POST)
public Mono adminLogin(@RequestParam("username") String username, @RequestParam("password") String password) {

    LoginAuthentication loginAuthentication = new LoginAuthentication(username, password);
    UpmsUser upmsUser = upmsUserServiceApi.getByLoginName(loginAuthentication.getUsername());
    return ReactiveSecurityContextHolder.getContext().flatMap(securityContext -> {
        securityContext.setAuthentication(loginAuthentication);
        return Mono.just(Result.success(upmsUser));
    });
}

它不能返回upmsUser并且不运行securityContext.setAuthentication(loginAuthentication)

0 个答案:

没有答案
相关问题