Created
August 16, 2013 21:35
-
-
Save dannyduc/6253685 to your computer and use it in GitHub Desktop.
Sample code to set user context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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