I have a Web Sesrvices protected by spring security OAuth2 and I can get access token using http request oauth/token... I have another requirement: to generate the access token in java and authenticate the user using:
SecurityContextHolder.getContext().setAuthentication(oauthToken);
in order to have access to web services via this token. This is my curent code:
UserDetails user = (UserDetails)userService.getUserByUserName(userName);
if (user == null) {
throw new InvalidAuthorizationException("User " + userName + " was not found");
} else {
//TODO: how to create 'oauthToken' ?
SecurityContextHolder.getContext().setAuthentication(oauthToken);
}
How can I do this?