Skip to content

Instantly share code, notes, and snippets.

@renfei
Created November 30, 2020 13:58
Show Gist options
  • Select an option

  • Save renfei/e40feee87a03a8be2d47687aafb55896 to your computer and use it in GitHub Desktop.

Select an option

Save renfei/e40feee87a03a8be2d47687aafb55896 to your computer and use it in GitHub Desktop.
将authenticationToken填充到安全上下文
Object user = null;
Object password = null;
String[] authorities = null;
// 将用户信息和权限填充 到用户身份token对象中
UsernamePasswordAuthenticationToken authenticationToken
= new UsernamePasswordAuthenticationToken(user, password, AuthorityUtils.createAuthorityList(authorities));
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
// 将authenticationToken填充到安全上下文
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment