Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于鉴权,是什么时候存入的? #10

Open
fdjkpoi opened this issue Dec 28, 2019 · 1 comment
Open

关于鉴权,是什么时候存入的? #10

fdjkpoi opened this issue Dec 28, 2019 · 1 comment

Comments

@fdjkpoi
Copy link

fdjkpoi commented Dec 28, 2019

CurrentUserMethodArgumentResolver 这个类,没看到这个值怎么存入的,可以讲解下把。
@OverRide
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出鉴权时存入的登录用户Id
Long currentUserId = (Long) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
if (currentUserId != null) {
//从数据库中查询并返回
return userRepository.findOne(currentUserId);
}
throw new MissingServletRequestPartException(Constants.CURRENT_USER_ID);
}

@fdjkpoi
Copy link
Author

fdjkpoi commented Dec 28, 2019

//如果token验证成功,将token对应的用户id存在request中,便于之后注入
request.setAttribute(Constants.CURRENT_USER_ID, model.getUserId());
找到了。在这里、

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant