public class OsmOAuthAuthorizationClient extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
OsmOAuthAuthorizationClient.SessionId |
Modifier and Type | Field and Description |
---|---|
private boolean |
canceled |
private java.net.HttpURLConnection |
connection |
private OAuthConsumer |
consumer |
private OAuthParameters |
oauthProviderParameters |
private OAuthProvider |
provider |
Constructor and Description |
---|
OsmOAuthAuthorizationClient()
Creates a new authorisation client with default OAuth parameters
|
OsmOAuthAuthorizationClient(OAuthParameters parameters)
Creates a new authorisation client with the parameters
parameters . |
OsmOAuthAuthorizationClient(OAuthParameters parameters,
OAuthToken requestToken)
Creates a new authorisation client with the parameters
parameters
and an already known Request Token. |
Modifier and Type | Method and Description |
---|---|
protected void |
authenticateOsmSession(OsmOAuthAuthorizationClient.SessionId sessionId,
java.lang.String userName,
java.lang.String password) |
void |
authorise(OAuthToken requestToken,
java.lang.String osmUserName,
java.lang.String osmPassword,
OsmPrivileges privileges,
ProgressMonitor monitor)
Automatically authorises a request token for a set of privileges.
|
java.lang.String |
buildOsmLoginUrl()
Derives the OSM login URL from the OAuth Authorization Website URL
|
protected java.lang.String |
buildOsmLogoutUrl()
Derives the OSM logout URL from the OAuth Authorization Website URL
|
protected java.lang.String |
buildPostRequest(java.util.Map<java.lang.String,java.lang.String> parameters) |
void |
cancel()
Cancels the current OAuth operation.
|
protected OsmOAuthAuthorizationClient.SessionId |
extractOsmSession(java.net.HttpURLConnection connection) |
protected java.lang.String |
extractToken(java.net.HttpURLConnection connection) |
protected void |
fetchOAuthToken(OsmOAuthAuthorizationClient.SessionId sessionId,
OAuthToken requestToken)
Submits a request to the OSM website for a OAuth form.
|
protected OsmOAuthAuthorizationClient.SessionId |
fetchOsmWebsiteSessionId()
Submits a request to the OSM website for a login form.
|
OAuthToken |
getAccessToken(ProgressMonitor monitor)
Submits a request for an Access Token to the Access Token Endpoint Url of the OAuth Service
Provider and replies the request token.
|
java.lang.String |
getAuthoriseUrl(OAuthToken requestToken)
Builds the authorise URL for a given Request Token.
|
OAuthToken |
getRequestToken(ProgressMonitor monitor)
Submits a request for a Request Token to the Request Token Endpoint Url of the OAuth Service
Provider and replies the request token.
|
protected void |
logoutOsmSession(OsmOAuthAuthorizationClient.SessionId sessionId) |
protected void |
sendAuthorisationRequest(OsmOAuthAuthorizationClient.SessionId sessionId,
OAuthToken requestToken,
OsmPrivileges privileges) |
private final OAuthParameters oauthProviderParameters
private final OAuthConsumer consumer
private final OAuthProvider provider
private boolean canceled
private java.net.HttpURLConnection connection
public OsmOAuthAuthorizationClient()
public OsmOAuthAuthorizationClient(OAuthParameters parameters) throws java.lang.IllegalArgumentException
parameters
.parameters
- the OAuth parameters. Must not be null.java.lang.IllegalArgumentException
- if parameters is nullpublic OsmOAuthAuthorizationClient(OAuthParameters parameters, OAuthToken requestToken) throws java.lang.IllegalArgumentException
parameters
and an already known Request Token.parameters
- the OAuth parameters. Must not be null.requestToken
- the request token. Must not be null.java.lang.IllegalArgumentException
- if parameters is nulljava.lang.IllegalArgumentException
- if requestToken is nullpublic void cancel()
public OAuthToken getRequestToken(ProgressMonitor monitor) throws OsmOAuthAuthorizationException, OsmTransferCanceledException
monitor
- a progress monitor. Defaults to NullProgressMonitor.INSTANCE
if nullOsmOAuthAuthorizationException
- if something goes wrong when retrieving the request tokenOsmTransferCanceledException
- if the user canceled the requestpublic OAuthToken getAccessToken(ProgressMonitor monitor) throws OsmOAuthAuthorizationException, OsmTransferCanceledException
getRequestToken(ProgressMonitor)
first.monitor
- a progress monitor. Defaults to NullProgressMonitor.INSTANCE
if nullOsmOAuthAuthorizationException
- if something goes wrong when retrieving the request tokenOsmTransferCanceledException
- if the user canceled the requestgetRequestToken(ProgressMonitor)
public java.lang.String getAuthoriseUrl(OAuthToken requestToken)
requestToken
- the request tokenprotected java.lang.String extractToken(java.net.HttpURLConnection connection)
protected OsmOAuthAuthorizationClient.SessionId extractOsmSession(java.net.HttpURLConnection connection)
protected java.lang.String buildPostRequest(java.util.Map<java.lang.String,java.lang.String> parameters) throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
public java.lang.String buildOsmLoginUrl() throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
- if something went wrong, in particular if the
URLs are malformedprotected java.lang.String buildOsmLogoutUrl() throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
- if something went wrong, in particular if the
URLs are malformedprotected OsmOAuthAuthorizationClient.SessionId fetchOsmWebsiteSessionId() throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
- if something went wrongprotected void fetchOAuthToken(OsmOAuthAuthorizationClient.SessionId sessionId, OAuthToken requestToken) throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
- if something went wrongprotected void authenticateOsmSession(OsmOAuthAuthorizationClient.SessionId sessionId, java.lang.String userName, java.lang.String password) throws OsmLoginFailedException
OsmLoginFailedException
protected void logoutOsmSession(OsmOAuthAuthorizationClient.SessionId sessionId) throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
protected void sendAuthorisationRequest(OsmOAuthAuthorizationClient.SessionId sessionId, OAuthToken requestToken, OsmPrivileges privileges) throws OsmOAuthAuthorizationException
OsmOAuthAuthorizationException
public void authorise(OAuthToken requestToken, java.lang.String osmUserName, java.lang.String osmPassword, OsmPrivileges privileges, ProgressMonitor monitor) throws java.lang.IllegalArgumentException, OsmOAuthAuthorizationException, OsmTransferCanceledException
requestToken
- the request token. Must not be null.osmUserName
- the OSM user name. Must not be null.osmPassword
- the OSM password. Must not be null.privileges
- the set of privileges. Must not be null.monitor
- a progress monitor. Defaults to NullProgressMonitor.INSTANCE
if nulljava.lang.IllegalArgumentException
- if requestToken is nulljava.lang.IllegalArgumentException
- if osmUserName is nulljava.lang.IllegalArgumentException
- if osmPassword is nulljava.lang.IllegalArgumentException
- if privileges is nullOsmOAuthAuthorizationException
- if the authorisation failsOsmTransferCanceledException
- if the task is canceled by the user