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

com.boot.auth.starter.SessionArgumentResolver Maven / Gradle / Ivy

There is a newer version: 1.0.0.4
Show newest version
package com.boot.auth.starter;

import com.boot.auth.starter.common.AuthConstant;
import com.boot.auth.starter.common.Session;
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 reactor.core.publisher.Mono;

import java.util.Objects;

public class SessionArgumentResolver implements HandlerMethodArgumentResolver {

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

    @Override
    public Mono resolveArgument(MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {
        return Mono.just(Objects.requireNonNull(exchange.getAttribute(AuthConstant.ATTR_SESSION)));
    }
}