@FunctionalInterface
public interface ServerAuthenticationConverter {
* Converts a {@link ServerWebExchange} to an {@link Authentication}
* @param exchange The {@link ServerWebExchange}
* @return A {@link Mono} representing an {@link Authentication}
Mono<Authentication> convert(ServerWebExchange exchange);
}
和
ReactiveAuthenticationManager
代码语言:
javascript
复制
@FunctionalInterface
public interface ReactiveAuthenticationManager {
* Attempts to authenticate the provided {@link Authentication}
* @param authentication the {@link Authentication} to test
* @return if authentication is successful an {@link Authentication} is returned. If
* authentication cannot be determined, an empty Mono is returned. If authentication
* fails, a Mono error is returned.
Mono<Authentication> authenticate(Authentication authentication);
}
两者都有一个返回
Mono<Authentication>
的方法。
他们代表什么?
目前,我的实现是:
代码语言:
javascript
复制
@Component
public class GitJwtServerAuthenticationConverter implements ServerAuthenticationConverter {
@Override
public Mono<Authentication> convert(ServerWebExchange exchange) {
return Mono.justOrEmpty(exchange)
.flatMap((it) -> Mono.justOrEmpty(it.getRequest().getHeaders()))
.map((headers) -> headers.get(HttpHeaders.AUTHORIZATION))
.map((header) -> new GitBearerTokenAuthenticationToken(header.get(0)));
}
并真正直截了当地实施:
代码语言:
javascript
复制
public class GitJwtReactiveAuthenticationManager implements ReactiveAuthenticationManager {
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
return Mono.justOrEmpty(authentication);
}