Skip to content

Instantly share code, notes, and snippets.

@dannyduc
Created August 16, 2013 21:35
Show Gist options
  • Save dannyduc/6253685 to your computer and use it in GitHub Desktop.
Save dannyduc/6253685 to your computer and use it in GitHub Desktop.
Sample code to set user context
User imsUser = new User();
imsUser.setUserId(1);
imsUser.setUsername("[email protected]");
String password = "1234";
imsUser.setPassword(password);
License license = new License();
GrantedAuthority[] authorities = new GrantedAuthority[]{
new GrantedAuthorityImpl("ROLE_ME")
};
IngUserDetailsImpl principal = new IngUserDetailsImpl(imsUser, license, authorities);
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, password, authorities);
SecurityContext context = new SecurityContextImpl();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
System.out.println(UserContext.getUserDetails());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment