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

com.github.houbb.current.user.interceptor.CurrentUserMethodArgumentResolver Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.github.houbb.current.user.interceptor;

import com.github.houbb.current.user.annotation.CurrentUser;
import com.github.houbb.current.user.constant.CurrentUserConst;
import com.github.houbb.current.user.dto.CurrentUserInfo;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * @author binbin.hou
 * @since 0.0.12
 */
@Component
public class CurrentUserMethodArgumentResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterType().isAssignableFrom(CurrentUserInfo.class)
                && parameter.hasParameterAnnotation(CurrentUser.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        return webRequest.getAttribute(CurrentUserConst.CURRENT_USER, RequestAttributes.SCOPE_REQUEST);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy