org.openstreetmap.josm.io.auth
Class CredentialsManager

java.lang.Object
  extended by org.openstreetmap.josm.io.auth.CredentialsManager
All Implemented Interfaces:
CredentialsAgent

public class CredentialsManager
extends java.lang.Object
implements CredentialsAgent

CredentialManager is a factory for the single credential agent used. Currently, it defaults to replying an instance of JosmPreferencesCredentialAgent.


Nested Class Summary
static interface CredentialsManager.CredentialsAgentFactory
           
 
Field Summary
private static CredentialsManager.CredentialsAgentFactory agentFactory
           
private  CredentialsAgent delegate
          non-static fields and methods
private static CredentialsManager instance
           
 
Constructor Summary
CredentialsManager(CredentialsAgent delegate)
           
 
Method Summary
 CredentialsAgentResponse getCredentials(java.net.Authenticator.RequestorType requestorType, java.lang.String host, boolean noSuccessWithLastResponse)
           
static CredentialsManager getInstance()
          Replies the single credential agent used in JOSM
 java.awt.Component getPreferencesDecorationPanel()
          Provide a Panel that is shown below the API password / username fields in the JOSM Preferences.
 java.lang.String getUsername()
           
 java.lang.String getUsername(java.lang.String host)
           
 java.net.PasswordAuthentication lookup(java.net.Authenticator.RequestorType requestorType, java.lang.String host)
          Looks up the credentials for a given type.
 OAuthToken lookupOAuthAccessToken()
          Lookup the current OAuth Access Token to access the OSM server.
static void registerCredentialsAgentFactory(CredentialsManager.CredentialsAgentFactory agentFactory)
          Plugins can register a CredentialsAgentFactory, thereby overriding JOSM's default credentials agent.
 void store(java.net.Authenticator.RequestorType requestorType, java.lang.String host, java.net.PasswordAuthentication credentials)
          Saves the credentials in credentials for the given service type.
 void storeOAuthAccessToken(OAuthToken accessToken)
          Stores the OAuth Access Token accessToken.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static CredentialsManager instance

agentFactory

private static CredentialsManager.CredentialsAgentFactory agentFactory

delegate

private CredentialsAgent delegate
non-static fields and methods

Constructor Detail

CredentialsManager

public CredentialsManager(CredentialsAgent delegate)
Method Detail

getInstance

public static CredentialsManager getInstance()
Replies the single credential agent used in JOSM

Returns:
the single credential agent used in JOSM

registerCredentialsAgentFactory

public static void registerCredentialsAgentFactory(CredentialsManager.CredentialsAgentFactory agentFactory)
Plugins can register a CredentialsAgentFactory, thereby overriding JOSM's default credentials agent.

Parameters:
agentFactory - The Factory that provides the custom CredentialsAgent. Can be null to clear the factory and switch back to default behavior.

getUsername

public java.lang.String getUsername()

getUsername

public java.lang.String getUsername(java.lang.String host)

lookup

public java.net.PasswordAuthentication lookup(java.net.Authenticator.RequestorType requestorType,
                                              java.lang.String host)
                                       throws CredentialsAgentException
Description copied from interface: CredentialsAgent
Looks up the credentials for a given type.

Specified by:
lookup in interface CredentialsAgent
Returns:
the credentials
Throws:
CredentialsAgentException - thrown if a problem occurs in a implementation of this interface

store

public void store(java.net.Authenticator.RequestorType requestorType,
                  java.lang.String host,
                  java.net.PasswordAuthentication credentials)
           throws CredentialsAgentException
Description copied from interface: CredentialsAgent
Saves the credentials in credentials for the given service type.

Specified by:
store in interface CredentialsAgent
credentials - the credentials
Throws:
CredentialsAgentException

getCredentials

public CredentialsAgentResponse getCredentials(java.net.Authenticator.RequestorType requestorType,
                                               java.lang.String host,
                                               boolean noSuccessWithLastResponse)
                                        throws CredentialsAgentException
Specified by:
getCredentials in interface CredentialsAgent
Parameters:
requestorType - the type of service. Authenticator.RequestorType.SERVER for the OSM API server, Authenticator.RequestorType.PROXY for a proxy server
noSuccessWithLastResponse - true, if the last request with the supplied credentials failed; false otherwise. If true, implementations of this interface are advised to prompt the user for new credentials.
Throws:
CredentialsAgentException - thrown if a problem occurs in a implementation of this interface

lookupOAuthAccessToken

public OAuthToken lookupOAuthAccessToken()
                                  throws CredentialsAgentException
Description copied from interface: CredentialsAgent
Lookup the current OAuth Access Token to access the OSM server. Replies null, if no Access Token is currently managed by this CredentialAgent.

Specified by:
lookupOAuthAccessToken in interface CredentialsAgent
Returns:
the current OAuth Access Token to access the OSM server.
Throws:
CredentialsAgentException - thrown if something goes wrong

storeOAuthAccessToken

public void storeOAuthAccessToken(OAuthToken accessToken)
                           throws CredentialsAgentException
Description copied from interface: CredentialsAgent
Stores the OAuth Access Token accessToken.

Specified by:
storeOAuthAccessToken in interface CredentialsAgent
Parameters:
accessToken - the access Token. null, to remove the Access Token.
Throws:
CredentialsAgentException - thrown if something goes wrong

getPreferencesDecorationPanel

public java.awt.Component getPreferencesDecorationPanel()
Description copied from interface: CredentialsAgent
Provide a Panel that is shown below the API password / username fields in the JOSM Preferences. (E.g. a warning that password is saved unencrypted.)

Specified by:
getPreferencesDecorationPanel in interface CredentialsAgent


JOSM