protected UserFederationProvider getFederationLink(RealmModel realm, UserModel user) {
   if (user.getFederationLink() == null) return null;
   for (UserFederationProviderModel fed : realm.getUserFederationProviders()) {
     if (fed.getId().equals(user.getFederationLink())) {
       return getFederationProvider(fed);
     }
   }
   return null;
 }
 protected UserModel registerWithFederation(RealmModel realm, UserModel user) {
   for (UserFederationProviderModel federation : realm.getUserFederationProviders()) {
     UserFederationProvider fed = getFederationProvider(federation);
     if (fed.synchronizeRegistrations()) {
       user.setFederationLink(federation.getId());
       UserModel registered = fed.register(realm, user);
       managedUsers.put(registered.getId(), registered);
       return registered;
     }
   }
   return user;
 }
 protected UserFederationProvider getFederationProvider(UserFederationProviderModel model) {
   UserFederationProviderFactory factory =
       (UserFederationProviderFactory)
           session
               .getKeycloakSessionFactory()
               .getProviderFactory(UserFederationProvider.class, model.getProviderName());
   return factory.getInstance(session, model);
 }