Different principals in spring security context when 'in-bean' login method used
spring, spring-3, spring-security, spring-social
Solution
You need to set up SignInAdapter as described at the end of this chapiter. In the `SignInAdapter.signIn(...)` method you can load your user object from DB then prepare authentication object and inject it in security context holder.
Problem
For couple of days I have been working on integrating Facebook with our application. I have successfully made the connection working and now after Facebook Login I copy the user to our database and later on I want to use our internal principal within context. For the Spring security login we overloaded our authentication-manager with our class implemeting `UserDetailsService`. When someone logs in with facebook, he has abstract credentials he can not know. I used this method in my Facebook login controller to log him in: ``` Authentication auth = new UsernamePasswordAuthenticationToken( profile.getId(), new Md5PasswordEncoder().encodePassword( profile.getEmail() + profile.getId(), null), (Collection<? extends GrantedAuthority>) getAuthorities(profile.getId())); ``` PROBLEM: Within 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 login its: `org.springframework.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.springframework.security.web.authentication.WebAuthenticationDetails@21a2c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: A5E9AB9E4AEE7486EC4B4F6133F77320; Granted Authorities: ROLE_ADMIN ` But after login with the method in the controller its: `org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cd4699c5: Principal: 1405308431; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_CLIENT` QUESTION: I really don't want to distinguish between these types in all my controllers. Why it differs?! It obviously is a User (my type) object when we login with normal credentials and its just a String for facebook. How can I change it so facebook login would give me User object in my security context too?