Class ConnectionUtils
java.lang.Object
org.craftercms.security.utils.social.ConnectionUtils
Utility methods related with connections with providers.
- Author:
- avasquez
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddConnectionData(Profile profile, org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor) Adds the specifiedConnectionDatato the profile.static voidaddProviderProfileInfo(Profile profile, org.springframework.social.connect.UserProfile providerProfile) Adds the info from the provider profile to the specified profile.connectionDataToMap(org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor) Creates a new map from the specifiedConnectionData.static ProfilecreateProfile(org.springframework.social.connect.Connection<?> connection) Creates a profile from the specified connection.static List<org.springframework.social.connect.ConnectionData>getConnectionData(Profile profile, String providerId, org.craftercms.commons.crypto.TextEncryptor encryptor) Returns the list ofConnectionDataassociated to the provider ID of the specified profilestatic org.springframework.social.connect.ConnectionDatamapToConnectionData(String providerId, Map<String, Object> map, org.craftercms.commons.crypto.TextEncryptor encryptor) Creates a new instance ofConnectionDatafrom the specified map.static voidremoveConnectionData(String providerId, String providerUserId, Profile profile) Remove theConnectionDataassociated to the provider ID and user ID.static voidremoveConnectionData(Profile profile, String providerId) Remove allConnectionDataassociated to the specified provider ID.
-
Field Details
-
CONNECTIONS_ATTRIBUTE_NAME
- See Also:
-
FIRST_NAME_ATTRIBUTE_NAME
- See Also:
-
LAST_NAME_ATTRIBUTE_NAME
- See Also:
-
DISPLAY_NAME_ATTRIBUTE_NAME
- See Also:
-
AVATAR_LINK_ATTRIBUTE_NAME
- See Also:
-
-
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 specifiedConnectionData. Used when connection data needs to be stored in a profile.- Parameters:
connectionData- the connection data to convertencryptor- 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.CryptoExceptionCreates a new instance ofConnectionDatafrom 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 convertencryptor- 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 specifiedConnectionDatato the profile. If a connection data with the same user ID already exists, it will be replaced with the new data.- Parameters:
profile- the profileconnectionData- the connection data to addencryptor- 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 ofConnectionDataassociated to the provider ID of the specified profile- Parameters:
profile- the profile that contains the connection data in its attributesproviderId- the provider ID of the connectionencryptor- 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
Remove allConnectionDataassociated to the specified provider ID.- Parameters:
profile- the profile where to remove the data fromproviderId- the provider ID of the connection
-
removeConnectionData
Remove theConnectionDataassociated to the provider ID and user ID.- Parameters:
providerId- the provider ID of the connectionproviderUserId- the provider user IDprofile- 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 profileproviderProfile- the provider profile where to get the info
-
createProfile
Creates a profile from the specified connection.- Parameters:
connection- the connection where to retrieve the profile info from- Returns:
- the created profile
-