Spring Social

org.springframework.social.connect.support
Class OAuth2Connection<A>

java.lang.Object
  extended by org.springframework.social.connect.support.AbstractConnection<A>
      extended by org.springframework.social.connect.support.OAuth2Connection<A>
Type Parameters:
A - the service provider's API type
All Implemented Interfaces:
Connection<A>

public class OAuth2Connection<A>
extends AbstractConnection<A>

An OAuth2-based Connection implementation. In general, this implementation is expected to be suitable for all OAuth2-based providers and should not require subclassing. Subclasses of OAuth2ConnectionFactory should be favored to encapsulate details specific to an OAuth2-based provider.

Author:
Keith Donald
See Also:
OAuth2ConnectionFactory

Constructor Summary
OAuth2Connection(ConnectionData data, OAuth2ServiceProvider<A> serviceProvider, ApiAdapter<A> apiAdapter)
          Creates a new OAuth2Connection from the data provided.
OAuth2Connection(java.lang.String providerId, java.lang.String providerUserId, java.lang.String accessToken, java.lang.String refreshToken, java.lang.Long expireTime, OAuth2ServiceProvider<A> serviceProvider, ApiAdapter<A> apiAdapter)
          Creates a new OAuth2Connection from a access grant response.
 
Method Summary
 ConnectionData createData()
          Creates a data transfer object that can be used to persist the state of this connection.
 A getApi()
          A Java binding to the service provider's native API.
 boolean hasExpired()
          Returns true if this connection has expired.
 void refresh()
          Refresh this connection.
 
Methods inherited from class org.springframework.social.connect.support.AbstractConnection
equals, fetchUserProfile, getDisplayName, getImageUrl, getKey, getMonitor, getProfileUrl, hashCode, initKey, sync, test, updateStatus
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuth2Connection

public OAuth2Connection(java.lang.String providerId,
                        java.lang.String providerUserId,
                        java.lang.String accessToken,
                        java.lang.String refreshToken,
                        java.lang.Long expireTime,
                        OAuth2ServiceProvider<A> serviceProvider,
                        ApiAdapter<A> apiAdapter)
Creates a new OAuth2Connection from a access grant response. Designed to be called to establish a new OAuth2Connection after receiving an access grant successfully. The providerUserId may be null in this case: if so, this constructor will try to resolve it using the service API obtained from the OAuth2ServiceProvider.

Parameters:
providerId - the provider id e.g. "facebook".
providerUserId - the provider user id (may be null if not returned as part of the access grant)
accessToken - the granted access token
refreshToken - the granted refresh token
expireTime - the access token expiration time
serviceProvider - the OAuth2-based ServiceProvider
apiAdapter - the ApiAdapter for the ServiceProvider

OAuth2Connection

public OAuth2Connection(ConnectionData data,
                        OAuth2ServiceProvider<A> serviceProvider,
                        ApiAdapter<A> apiAdapter)
Creates a new OAuth2Connection from the data provided. Designed to be called when re-constituting an existing Connection from ConnectionData.

Parameters:
data - the data holding the state of this connection
serviceProvider - the OAuth2-based ServiceProvider
apiAdapter - the ApiAdapter for the ServiceProvider
Method Detail

hasExpired

public boolean hasExpired()
Description copied from interface: Connection
Returns true if this connection has expired. An expired connection cannot be used; calls to Connection.test() return false, and any service API invocations fail. If expired, you may call Connection.refresh() to renew the connection. Not supported by all Connection implementations; always returns false if not supported.

Specified by:
hasExpired in interface Connection<A>
Overrides:
hasExpired in class AbstractConnection<A>

refresh

public void refresh()
Description copied from interface: Connection
Refresh this connection. Used to renew an expired connection. If the refresh operation is successful, Connection.hasExpired() returns false. Not supported by all connection implementations; if not supported, this method is a no-op.

Specified by:
refresh in interface Connection<A>
Overrides:
refresh in class AbstractConnection<A>

getApi

public A getApi()
Description copied from interface: Connection
A Java binding to the service provider's native API.

Specified by:
getApi in interface Connection<A>
Specified by:
getApi in class AbstractConnection<A>

createData

public ConnectionData createData()
Description copied from interface: Connection
Creates a data transfer object that can be used to persist the state of this connection. Used to support the transfer of connection state between layers of the application, such as to the database layer.

Specified by:
createData in interface Connection<A>
Specified by:
createData in class AbstractConnection<A>

Spring Social