In my Spring Boot application with RESTful webservices I have configured Spring Security together with Spring Social and SpringSocialConfigurer
.
Right now I have two ways of authentication/authorization - via username/password and via social networks for example like Twitter.
In order to implement authentication/authorization via my own RESTful endpoint in my Spring MVC REST controller I have added following method:
@RequestMapping(value = "/login", method = RequestMethod.POST)
public Authentication login(@RequestBody LoginUserRequest userRequest) {
Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(userRequest.getUsername(), userRequest.getPassword()));
boolean isAuthenticated = isAuthenticated(authentication);
if (isAuthenticated) {
SecurityContextHolder.getContext().setAuthentication(authentication);
}
return authentication;
}
private boolean isAuthenticated(Authentication authentication) {
return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.isAuthenticated();
}
but I'm not sure what exactly must be returned to client after successfull /login
endpoint call. I think returning of full authentication object is redundant.
What should be returned to client in case of successfull authentication ?
Could you please tell me how to correctly implement this login method ?
Also, in case of RESTfull login I'll have UsernamePasswordAuthenticationToken
and in case of login through Twitter I'll have SocialAuthenticationToken
Is it okay to have different tokens in a same application ?