code as below:
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
grantedAuthorities.add(new GrantedAuthorityImpl("USER"));
UsernamePasswordAuthenticationToken uat = new UsernamePasswordAuthenticationToken(
"john", "admin", grantedAuthorities);
uat.setDetails(user);
SecurityContext context = SecurityContextHolder.getContext();
Authentication userAuth = authenticationManager.authenticate(uat);
context.setAuthentication(userAuth);