public static void addConnectionData(Profile profile, ConnectionData connectionData,
                                         TextEncryptor encryptor) throws CryptoException {
        Map<String, List<Map<String, Object>>> allConnections = profile.getAttribute(CONNECTIONS_ATTRIBUTE_NAME);
        List<Map<String, Object>> connectionsForProvider = null;

        if (allConnections == null) {
            allConnections = new HashMap<>();

            profile.setAttribute(CONNECTIONS_ATTRIBUTE_NAME, allConnections);
        } else {
            connectionsForProvider = allConnections.get(connectionData.getProviderId());
        }

        if (connectionsForProvider == null) {
            connectionsForProvider = new ArrayList<>();

            allConnections.put(connectionData.getProviderId(), connectionsForProvider);
        }

        Map<String, Object> currentConnectionDataMap = null;

        for (Map<String, Object> connectionDataMap : connectionsForProvider) {
            if (connectionData.getProviderUserId().equals(connectionDataMap.get("providerUserId"))) {
                currentConnectionDataMap = connectionDataMap;
                break;
            }
        }

        if (currentConnectionDataMap != null) {
            currentConnectionDataMap.putAll(connectionDataToMap(connectionData, encryptor));
        } else {
            connectionsForProvider.add(connectionDataToMap(connectionData, encryptor));
        }
    }
public static void addConnectionData ( Profile profile , ConnectionData connectionData , TextEncryptor encryptor ) throws CryptoException { Map < String , List < Map < String , Object > > > allConnections = profile . getAttribute ( CONNECTIONS_ATTRIBUTE_NAME ) ; List < Map < String , Object > > connectionsForProvider = null ; if ( allConnections == null ) { allConnections = new HashMap < > ( ) ; profile . setAttribute ( CONNECTIONS_ATTRIBUTE_NAME , allConnections ) ; } else { connectionsForProvider = allConnections . get ( connectionData . getProviderId ( ) ) ; } if ( connectionsForProvider == null ) { connectionsForProvider = new ArrayList < > ( ) ; allConnections . put ( connectionData . getProviderId ( ) , connectionsForProvider ) ; } Map < String , Object > currentConnectionDataMap = null ; for ( Map < String , Object > connectionDataMap : connectionsForProvider ) { if ( connectionData . getProviderUserId ( ) . equals ( connectionDataMap . get ( "providerUserId" ) ) ) { currentConnectionDataMap = connectionDataMap ; break ; } } if ( currentConnectionDataMap != null ) { currentConnectionDataMap . putAll ( connectionDataToMap ( connectionData , encryptor ) ) ; } else { connectionsForProvider . add ( connectionDataToMap ( connectionData , encryptor ) ) ; } }
Adds the specified {@link ConnectionData} to the profile. If a connection
data with the same user ID already exists, it will be replaced with the new data.

@param profile           the profile
@param connectionData    the connection data to add
@param encryptor         the encryptor used to encrypt the accessToken, secret and refreshToken