如何使用 Spring WebFlux 获取 "Authentication" 对象?

How to get the "Authentication" Object with Spring WebFlux?

使用 SpringMVC 和 Spring 安全性我可以实现这样的控制器(在 Java 中):

@RestController
@RequestMapping("/auth")
class AuthController {
    private final AuthService authService;

    AuthController(AuthService authService) {
        this.authService = authService;
    }

    @GetMapping("/roles")
    Collection<String> findRoles(Authentication authentication) {
        final Object principal = authentication.getPrincipal();
        ...;
    }
}

但是,我基本上是如何注入 org.springframework.security.core.Authentication 的对象的? 在 handlerclass(或在 serviceclass)中使用 SpringWebFlux 和 Spring 安全(包括。 反应部分)?

有很多例子: https://github.com/spring-projects/spring-security

这个展示了如何在 rest controller 的情况下获取 Principal:

https://github.com/spring-projects/spring-security/blob/b6895e6359e404e4ea101b78eb3135612dfe1769/samples/javaconfig/hellowebflux/src/main/java/sample/HelloUserController.java#L35

这一个展示了在 webflux 的情况下如何获取 Principal:

https://github.com/spring-projects/spring-security/blob/b6895e6359e404e4ea101b78eb3135612dfe1769/samples/javaconfig/hellowebfluxfn/src/main/java/sample/HelloUserController.java#L37