Class ConnectionUtils

java.lang.Object
org.craftercms.security.utils.social.ConnectionUtils

public class ConnectionUtils extends Object
Utility methods related with connections with providers.
Author:
avasquez
  • Field Details

  • Constructor Details

    • ConnectionUtils

      public ConnectionUtils()
  • Method Details

    • connectionDataToMap

      public static Map<String,Object> connectionDataToMap(org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor) throws org.craftercms.commons.crypto.CryptoException
      Creates a new map from the specified ConnectionData. Used when connection data needs to be stored in a profile.
      Parameters:
      connectionData - the connection data to convert
      encryptor - the encryptor used to encrypt the accessToken, secret and refreshToken (optional)
      Returns:
      the connection data as a map
      Throws:
      org.craftercms.commons.crypto.CryptoException
    • mapToConnectionData

      public static org.springframework.social.connect.ConnectionData mapToConnectionData(String providerId, Map<String,Object> map, org.craftercms.commons.crypto.TextEncryptor encryptor) throws org.craftercms.commons.crypto.CryptoException
      Creates a new instance of ConnectionData from the specified map. Used when connection data needs to be retrieved from a profile.
      Parameters:
      providerId - the provider ID of the connection (which is not stored in the map)
      map - the map to convert
      encryptor - the encryptor used to decrypt the accessToken, secret and refreshToken (optional)
      Returns:
      the map as ConnectionData
      Throws:
      org.craftercms.commons.crypto.CryptoException
    • addConnectionData

      public static void addConnectionData(Profile profile, org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor) throws org.craftercms.commons.crypto.CryptoException
      Adds the specified ConnectionData to the profile. If a connection data with the same user ID already exists, it will be replaced with the new data.
      Parameters:
      profile - the profile
      connectionData - the connection data to add
      encryptor - the encryptor used to encrypt the accessToken, secret and refreshToken
      Throws:
      org.craftercms.commons.crypto.CryptoException
    • getConnectionData

      public static List<org.springframework.social.connect.ConnectionData> getConnectionData(Profile profile, String providerId, org.craftercms.commons.crypto.TextEncryptor encryptor) throws org.craftercms.commons.crypto.CryptoException
      Returns the list of ConnectionData associated to the provider ID of the specified profile
      Parameters:
      profile - the profile that contains the connection data in its attributes
      providerId - the provider ID of the connection
      encryptor - the encryptor used to decrypt the accessToken, secret and refreshToken
      Returns:
      the list of connection data for the provider, or empty if no connection data was found
      Throws:
      org.craftercms.commons.crypto.CryptoException
    • removeConnectionData

      public static void removeConnectionData(Profile profile, String providerId)
      Remove all ConnectionData associated to the specified provider ID.
      Parameters:
      profile - the profile where to remove the data from
      providerId - the provider ID of the connection
    • removeConnectionData

      public static void removeConnectionData(String providerId, String providerUserId, Profile profile)
      Remove the ConnectionData associated to the provider ID and user ID.
      Parameters:
      providerId - the provider ID of the connection
      providerUserId - the provider user ID
      profile - the profile where to remove the data from
    • addProviderProfileInfo

      public static void addProviderProfileInfo(Profile profile, org.springframework.social.connect.UserProfile providerProfile)
      Adds the info from the provider profile to the specified profile.
      Parameters:
      profile - the target profile
      providerProfile - the provider profile where to get the info
    • createProfile

      public static Profile createProfile(org.springframework.social.connect.Connection<?> connection)
      Creates a profile from the specified connection.
      Parameters:
      connection - the connection where to retrieve the profile info from
      Returns:
      the created profile