package sgc.portal.com.sym.user;

import sgc.portal.SgcPortalAttributes;
import sgc.portal.base.util.SessionUtil;
import sgc.portal.com.sym.user.model.UserDetails;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * 로그인 유저 데이터를 획득하는 MethodArgumentResolver
 *
 * @author YongSang
 */
public class UserDetailsMethodArgumentResolver implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return UserDetails.class.isAssignableFrom(parameter.getParameterType());
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
            NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
        return SessionUtil.getAttribute(SgcPortalAttributes.AUTHENTICATION);
    }
}