All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.boot.resolver.ReactiveTokenArgumentResolver Maven / Gradle / Ivy

The newest version!
package org.zodiac.boot.resolver;

import org.springframework.core.MethodParameter;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver;
import org.springframework.web.server.ServerWebExchange;
import org.zodiac.security.auth.model.SecurityPlatformUser;
import org.zodiac.security.util.SecurityReactiveAuthUtil;

import reactor.core.publisher.Mono;

/**
 * Token转化SecurityPlatformUser。
 *
 */
public class ReactiveTokenArgumentResolver implements HandlerMethodArgumentResolver {

    public ReactiveTokenArgumentResolver() {
    }

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterType().equals(SecurityPlatformUser.class);
    }

    @Override
    public Mono resolveArgument(MethodParameter parameter, BindingContext bindingContext,
        ServerWebExchange exchange) {
        SecurityPlatformUser user = SecurityReactiveAuthUtil.getUser();
        return null != user ? Mono.just(user) : Mono.empty();
    }

}