public class JdbcConnectionRepository extends Object implements ConnectionRepository
Constructor and Description |
---|
JdbcConnectionRepository(String userId,
JdbcTemplate jdbcTemplate,
ConnectionFactoryLocator connectionFactoryLocator,
org.springframework.security.crypto.encrypt.TextEncryptor textEncryptor,
String tablePrefix) |
Modifier and Type | Method and Description |
---|---|
void |
addConnection(Connection<?> connection)
Add a new connection to this repository for the current user.
|
MultiValueMap<String,Connection<?>> |
findAllConnections()
Find all connections the current user has across all providers.
|
<A> List<Connection<A>> |
findConnections(Class<A> apiType)
Find the connections the current user has to the provider of the given API e.g.
|
List<Connection<?>> |
findConnections(String providerId)
Find the connections the current user has to the provider registered by the given id e.g.
|
MultiValueMap<String,Connection<?>> |
findConnectionsToUsers(MultiValueMap<String,String> providerUsers)
Find the connections the current user has to the given provider users.
|
<A> Connection<A> |
findPrimaryConnection(Class<A> apiType)
Find the "primary" connection the current user has to the provider of the given API e.g.
|
<A> Connection<A> |
getConnection(Class<A> apiType,
String providerUserId)
Get a connection between the current user and the given provider user.
|
Connection<?> |
getConnection(ConnectionKey connectionKey)
Get a connection for the current user by its key, which consists of the providerId + providerUserId.
|
<A> Connection<A> |
getPrimaryConnection(Class<A> apiType)
Get the "primary" connection the current user has to the provider of the given API e.g.
|
void |
removeConnection(ConnectionKey connectionKey)
Remove a single Connection for the current user from this repository.
|
void |
removeConnections(String providerId)
Remove all Connections between the current user and the provider from this repository.
|
void |
updateConnection(Connection<?> connection)
Update a Connection already added to this repository.
|
public JdbcConnectionRepository(String userId, JdbcTemplate jdbcTemplate, ConnectionFactoryLocator connectionFactoryLocator, org.springframework.security.crypto.encrypt.TextEncryptor textEncryptor, String tablePrefix)
public MultiValueMap<String,Connection<?>> findAllConnections()
ConnectionRepository
Connection
s that exist between the user and that provider.
For example, if the user is connected once to Facebook and twice to Twitter, the returned map would contain two entries with the following structure:
{ "facebook" -> [ Connection("Keith Donald") ] , "github" -> [ ] "twitter" -> [ Connection("kdonald"), Connection("springsource") ] }The returned map is sorted by providerId and entry values are ordered by rank. The method always returns a map with keys representing all registered providers. For providers with no connection, a map contains an empty list as a value.
findAllConnections
in interface ConnectionRepository
public List<Connection<?>> findConnections(String providerId)
ConnectionRepository
findConnections
in interface ConnectionRepository
providerId
- the provider id e.g. "facebook"public <A> List<Connection<A>> findConnections(Class<A> apiType)
ConnectionRepository
ConnectionRepository.findConnections(String)
, but uses the apiType as the provider key instead of the providerId.
Useful for direct use by application code to obtain parameterized Connection instances e.g. List<Connection<Facebook>>
.findConnections
in interface ConnectionRepository
A
- the API parameterized typeapiType
- the API type e.g. Facebook.class or Twitter.classpublic MultiValueMap<String,Connection<?>> findConnectionsToUsers(MultiValueMap<String,String> providerUsers)
ConnectionRepository
findConnectionsToUsers
in interface ConnectionRepository
providerUsers
- the provider users mappublic Connection<?> getConnection(ConnectionKey connectionKey)
ConnectionRepository
getConnection
in interface ConnectionRepository
connectionKey
- the service provider connection keypublic <A> Connection<A> getConnection(Class<A> apiType, String providerUserId)
ConnectionRepository
ConnectionRepository.getConnection(ConnectionKey)
, but uses the apiType as the provider key instead of the providerId.
Useful for direct use by application code to obtain a parameterized Connection instance.getConnection
in interface ConnectionRepository
A
- the API parameterized typeapiType
- the API type e.g. Facebook.class or Twitter.classproviderUserId
- the provider user e.g. "126500".public <A> Connection<A> getPrimaryConnection(Class<A> apiType)
ConnectionRepository
getPrimaryConnection
in interface ConnectionRepository
A
- the API parameterized typeapiType
- the API type e.g. Facebook.class or Twitter.classpublic <A> Connection<A> findPrimaryConnection(Class<A> apiType)
ConnectionRepository
ConnectionRepository.getPrimaryConnection(Class)
but returns null if no connection is found instead of throwing an exception.findPrimaryConnection
in interface ConnectionRepository
A
- the API parameterized typeapiType
- the API type e.g. Facebook.class or Twitter.classnull
if not found@Transactional public void addConnection(Connection<?> connection)
ConnectionRepository
addConnection
in interface ConnectionRepository
connection
- the new connection to add to this repository@Transactional public void updateConnection(Connection<?> connection)
ConnectionRepository
updateConnection
in interface ConnectionRepository
connection
- the existing connection to update in this repository@Transactional public void removeConnections(String providerId)
ConnectionRepository
removeConnections
in interface ConnectionRepository
providerId
- the provider id e.g. 'facebook'@Transactional public void removeConnection(ConnectionKey connectionKey)
ConnectionRepository
removeConnection
in interface ConnectionRepository
connectionKey
- the connection key