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 Summary
Fields Modifier and Type Field Description static String
AVATAR_LINK_ATTRIBUTE_NAME
static String
CONNECTIONS_ATTRIBUTE_NAME
static String
DISPLAY_NAME_ATTRIBUTE_NAME
static String
FIRST_NAME_ATTRIBUTE_NAME
static String
LAST_NAME_ATTRIBUTE_NAME
-
Constructor Summary
Constructors Constructor Description ConnectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addConnectionData(Profile profile, org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor)
Adds the specifiedConnectionData
to the profile.static void
addProviderProfileInfo(Profile profile, org.springframework.social.connect.UserProfile providerProfile)
Adds the info from the provider profile to the specified profile.static Map<String,Object>
connectionDataToMap(org.springframework.social.connect.ConnectionData connectionData, org.craftercms.commons.crypto.TextEncryptor encryptor)
Creates a new map from the specifiedConnectionData
.static Profile
createProfile(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 ofConnectionData
associated to the provider ID of the specified profilestatic org.springframework.social.connect.ConnectionData
mapToConnectionData(String providerId, Map<String,Object> map, org.craftercms.commons.crypto.TextEncryptor encryptor)
Creates a new instance ofConnectionData
from the specified map.static void
removeConnectionData(String providerId, String providerUserId, Profile profile)
Remove theConnectionData
associated to the provider ID and user ID.static void
removeConnectionData(Profile profile, String providerId)
Remove allConnectionData
associated to the specified provider ID.
-
-
-
Field Detail
-
CONNECTIONS_ATTRIBUTE_NAME
public static final String CONNECTIONS_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
FIRST_NAME_ATTRIBUTE_NAME
public static final String FIRST_NAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
LAST_NAME_ATTRIBUTE_NAME
public static final String LAST_NAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
DISPLAY_NAME_ATTRIBUTE_NAME
public static final String DISPLAY_NAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
AVATAR_LINK_ATTRIBUTE_NAME
public static final String AVATAR_LINK_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
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.CryptoException
Creates a new instance ofConnectionData
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 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 specifiedConnectionData
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 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 ofConnectionData
associated 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
public static void removeConnectionData(Profile profile, String providerId)
Remove allConnectionData
associated to the specified provider ID.- Parameters:
profile
- the profile where to remove the data fromproviderId
- the provider ID of the connection
-
removeConnectionData
public static void removeConnectionData(String providerId, String providerUserId, Profile profile)
Remove theConnectionData
associated 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
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
-
-