com.ruijc.shiro.annotation.SessionUserArgumentResolver Maven / Gradle / Ivy
package com.ruijc.shiro.annotation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
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;
/**
* {@link SessionUser}注解解析
*
* @author Storezhang
*/
public class SessionUserArgumentResolver implements HandlerMethodArgumentResolver {
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(SessionUser.class);
}
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
Object user = null;
Subject subject = SecurityUtils.getSubject();
if (supportsParameter(parameter) && subject.isAuthenticated()) {
user = subject.getPrincipal();
}
return user;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy