@Override
public IndexedUserDetails handleLogin(String type, String id,
String credentials, boolean isAnonymous, boolean registerIfNewUser) {
UserIndexKey key = new UserIndexKey(type, id);
UserIndex index = _userService.getUserIndexForId(key);
boolean exists = index != null;
// New user?
if (!exists) {
if (!registerIfNewUser)
return null;
index = _userService.getOrCreateUserForIndexKey(key, credentials, false);
User newUser = index.getUser();
User oldUser = _currentUserStrategy.getCurrentUser(false);
if (oldUser != null && _userService.isAnonymous(oldUser))
_userService.mergeUsers(oldUser, newUser);
}