protected void verifyProviderCredentialsForUser(WritableSession session, User user) {
    List<UserAuthData> authData = user.getAuthData();
    UserProviderCredentialsMap credentials = session.getUserProviderCredentials();

    if (credentials != null) {

      if (authData != null) {
        Map<AuthProviderType, UserProviderCredentials> validCreds =
            new LinkedHashMap<AuthProviderType, UserProviderCredentials>();
        for (UserAuthData userAuthData : authData) {
          UserProviderCredentials creds = credentials.get(userAuthData.getAuthProviderType());
          if (creds != null) {
            validCreds.put(userAuthData.getAuthProviderType(), creds);
          }
        }

        // Clear and reset
        credentials.removeAll();

        Set<Entry<AuthProviderType, UserProviderCredentials>> entrySet = validCreds.entrySet();

        for (Entry<AuthProviderType, UserProviderCredentials> entry : entrySet) {
          credentials.put(entry.getKey(), entry.getValue());
        }
      } else {
        credentials.removeAll();
      }

      // Set back to session
      session.setUserProviderCredentials(credentials);
    }
  }
 public boolean validateSessionAuthData(SocializeSession loaded, AuthProviderInfo info) {
   UserProviderCredentialsMap userProviderCredentialsMap = loaded.getUserProviderCredentials();
   if (userProviderCredentialsMap != null) {
     UserProviderCredentials userProviderCredentials =
         userProviderCredentialsMap.get(info.getType());
     if (userProviderCredentials != null
         && userProviderCredentials.getAuthProviderInfo().matches(info)) {
       return true;
     }
   }
   return false;
 }