For several days I have been working on integrating Facebook with our application. I successfully made a connection, and now, after logging into Facebook, I copy the user to our database, and later I want to use our internal principle in context .
To login to the Spring system, we overloaded our authentication manager using our class that implements UserDetailsService .
When someone logs in with facebook, he has abstract credentials that he cannot know. I used this method in my Facebook login controller to register it:
Authentication auth = new UsernamePasswordAuthenticationToken( profile.getId(), new Md5PasswordEncoder().encodePassword( profile.getEmail() + profile.getId(), null), (Collection<? extends GrantedAuthority>) getAuthorities(profile.getId()));
Problem:
In some controllers I use
public String profile(Locale locale, Model model, HttpSession session, Principal principal) , and then principal actually contains different objects.
For regular Spring security, enter it:
org.springframew ork.security.authentication.UsernamePasswordAuthenticationToken@ 4527d081: Principal: org.springframework.security.core.userdetails.User@586034f : Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin gframework.security.web.authentication.WebAuthenticationDetails@ 21a2c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: A5E9AB9E4AEE7486EC4B4F6133F77320; Granted Authorities: ROLE_ADMIN
But after logging in using the method in the controller it: org.springframew ork.security.authentication.UsernamePasswordAuthenticationToken@ cd4699c5: Principal: 1405308431; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_CLIENT org.springframew ork.security.authentication.UsernamePasswordAuthenticationToken@ cd4699c5: Principal: 1405308431; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_CLIENT
Question: I really do not want to distinguish between these types in all my controllers. Why is he different ?! Obviously, this is a User object (my type) when we log in with the usual credentials and just for String for facebook. How can I change it so that facebook login also gives me a User object in my security context?