Package com.sodius.oslc.client.oauth
Class OAuthStore
- java.lang.Object
-
- com.sodius.oslc.client.oauth.OAuthStore
-
public class OAuthStore extends Object
Stores OAuth tokens approved by a user. One OAuthStore instance is to use for each end-user requesting OAuth connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OAuthStore.OAuthStoreSerializable
Serializable equivalent for OAuth Store to support clustered environments
-
Constructor Summary
Constructors Constructor Description OAuthStore(FriendProvider friendProvider)
Instantiates a store which uses the specified provider to grant access to some friend applications.OAuthStore(String identifier, FriendProvider friendProvider)
Instantiates a store which uses the specified provider to grant access to some friend applications.OAuthStore(String identifier, FriendProvider friendProvider, OAuthStore.OAuthStoreSerializable oAuthStoreSerializable)
Instantiates a store which uses the specified provider to grant access to some friend applications.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearAuthorization(URI resourceUri)
Revokes any authorization obtained for the specified resource.String
getAuthorization(String httpMethod, URI resourceUri, OAuthHandler handler)
Triggers the OAuth connection to the specified target resource.Optional<String>
getExistingAuthorization(String httpMethod, URI resourceUri)
Returns the known Authorization header to use for accessing specified target resource, if any.OAuthStore.OAuthStoreSerializable
getExternalizable()
Get the serializable OAuth Store to support clustered environmentsString
getIdentifier()
Returns the store identifier.static void
setVerifier(String verifierId, String verifier)
Associates a verifier to an ID to approve the OAuth connection.static void
validate(Friend friend, RootServices rootServices)
Verifies an OAuth connection can be realized for the specified friend and root services.
-
-
-
Constructor Detail
-
OAuthStore
public OAuthStore(FriendProvider friendProvider)
Instantiates a store which uses the specified provider to grant access to some friend applications.- Parameters:
friendProvider
- provides access to friend applications.
-
OAuthStore
public OAuthStore(String identifier, FriendProvider friendProvider)
Instantiates a store which uses the specified provider to grant access to some friend applications.- Parameters:
identifier
- the store identifier.friendProvider
- provides access to friend applications.- Since:
- 2.1.0
-
OAuthStore
public OAuthStore(String identifier, FriendProvider friendProvider, OAuthStore.OAuthStoreSerializable oAuthStoreSerializable)
Instantiates a store which uses the specified provider to grant access to some friend applications.- Parameters:
identifier
- the store identifier.friendProvider
- provides access to friend applications.oAuthStoreSerializable
- OAuth Store serializable- Since:
- 2.1.0
-
-
Method Detail
-
setVerifier
public static void setVerifier(String verifierId, String verifier)
Associates a verifier to an ID to approve the OAuth connection. This method is typically to invoke when the OAuth callback URL has been invoked by the target application.- Parameters:
verifierId
- the ID of the verifierverifier
- the verifier value sent within the callback URL- See Also:
OAuthHandler.createCallback(RootServices, String)
-
getAuthorization
public String getAuthorization(String httpMethod, URI resourceUri, OAuthHandler handler)
Triggers the OAuth connection to the specified target resource. Reuses the approved OAuth connection of the target application, if any.- Parameters:
httpMethod
- the HTTP method use to connect to the resource (one of "GET", "PUT", "POST" or "DELETE")resourceUri
- the location of the target resourcehandler
- the handler helping the realization of the OAuth connection, if the connection is not yet approved.- Returns:
- the OAuth message content to set as Authorization header in the HTTP request to access the target resource.
- Throws:
ClientRuntimeException
- if no friend matches the given resource, or an OAuth problem or an I/O exception occurs
-
getExistingAuthorization
public Optional<String> getExistingAuthorization(String httpMethod, URI resourceUri)
Returns the known Authorization header to use for accessing specified target resource, if any.- Parameters:
httpMethod
- the HTTP method use to connect to the resource (one of "GET", "PUT", "POST" or "DELETE")resourceUri
- the location of the target resource- Returns:
- the OAuth message content to set as Authorization header in the HTTP request to access the target resource,
or
null
if the OAuth connection is not yet authorized. - Throws:
ClientRuntimeException
- if no friend matches the given resource, or an OAuth problem or an I/O exception occurs- Since:
- 3.4.0
-
clearAuthorization
public void clearAuthorization(URI resourceUri)
Revokes any authorization obtained for the specified resource. This method shall be called to restart the OAuth connection on the target application.- Parameters:
resourceUri
- the location of a target resource.
-
validate
public static void validate(Friend friend, RootServices rootServices) throws net.oauth.OAuthException, URISyntaxException, IOException
Verifies an OAuth connection can be realized for the specified friend and root services. This method is notably useful to verify the consumer information stored in the friend are valid and recognized by the target application.- Parameters:
friend
- the friend to validate.rootServices
- the root services declaring the application on which the validation shall be performed.- Throws:
net.oauth.OAuthException
- if the OAuth information is invalid.URISyntaxException
- if a URI is invalid.IOException
- if an error occurs when exchanging bytes with the application.
-
getIdentifier
public String getIdentifier()
Returns the store identifier.- Returns:
- the store identifier
- Since:
- 2.1.0
-
getExternalizable
public OAuthStore.OAuthStoreSerializable getExternalizable()
Get the serializable OAuth Store to support clustered environments- Returns:
- OAuth Store Serializable
-
-