public class CredentialsManager extends java.lang.Object implements CredentialsAgent
JosmPreferencesCredentialAgent
.Modifier and Type | Class and Description |
---|---|
static interface |
CredentialsManager.CredentialsAgentFactory |
Modifier and Type | Field and Description |
---|---|
private static CredentialsManager.CredentialsAgentFactory |
agentFactory |
private CredentialsAgent |
delegate
The credentials agent doing the real stuff
|
private static CredentialsManager |
instance |
Constructor and Description |
---|
CredentialsManager(CredentialsAgent delegate)
Constructs a new
CredentialsManager . |
Modifier and Type | Method and Description |
---|---|
CredentialsAgentResponse |
getCredentials(java.net.Authenticator.RequestorType requestorType,
java.lang.String host,
boolean noSuccessWithLastResponse)
Returns the credentials needed to to access host.
|
java.lang.Class<? extends CredentialsAgent> |
getCredentialsAgentClass()
Returns type of credentials agent backing this credentials manager.
|
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()
Returns the username for OSM API
|
java.lang.String |
getUsername(java.lang.String host)
Returns the username for a given 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 . |
private static volatile CredentialsManager instance
private static CredentialsManager.CredentialsAgentFactory agentFactory
private final CredentialsAgent delegate
public CredentialsManager(CredentialsAgent delegate)
CredentialsManager
.delegate
- The credentials agent backing this credential manager. Must not be null
public static CredentialsManager getInstance()
public static void registerCredentialsAgentFactory(CredentialsManager.CredentialsAgentFactory agentFactory)
agentFactory
- The Factory that provides the custom CredentialsAgent.
Can be null to clear the factory and switch back to default behavior.public final java.lang.Class<? extends CredentialsAgent> getCredentialsAgentClass()
public java.lang.String getUsername()
public java.lang.String getUsername(java.lang.String host)
host
- The host for which username is wantedhost
public java.net.PasswordAuthentication lookup(java.net.Authenticator.RequestorType requestorType, java.lang.String host) throws CredentialsAgentException
CredentialsAgent
lookup
in interface CredentialsAgent
requestorType
- the type of service. Authenticator.RequestorType.SERVER
for the OSM API server, Authenticator.RequestorType.PROXY
for a proxy serverhost
- the hostname for these credentialsCredentialsAgentException
- if a problem occurs in a implementation of this interfacepublic void store(java.net.Authenticator.RequestorType requestorType, java.lang.String host, java.net.PasswordAuthentication credentials) throws CredentialsAgentException
CredentialsAgent
credentials
for the given service type.store
in interface CredentialsAgent
requestorType
- the type of service. Authenticator.RequestorType.SERVER
for the OSM API server, Authenticator.RequestorType.PROXY
for a proxy serverhost
- the hostname for these credentialscredentials
- the credentialsCredentialsAgentException
- if a problem occurs in a implementation of this interfacepublic CredentialsAgentResponse getCredentials(java.net.Authenticator.RequestorType requestorType, java.lang.String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException
CredentialsAgent
getCredentials
in interface CredentialsAgent
requestorType
- the type of service. Authenticator.RequestorType.SERVER
for the OSM API server, Authenticator.RequestorType.PROXY
for a proxy serverhost
- the hostname for these credentialsnoSuccessWithLastResponse
- 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.CredentialsAgentException
- if a problem occurs in a implementation of this interfacepublic OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException
CredentialsAgent
lookupOAuthAccessToken
in interface CredentialsAgent
CredentialsAgentException
- if something goes wrongpublic void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException
CredentialsAgent
accessToken
.storeOAuthAccessToken
in interface CredentialsAgent
accessToken
- the access Token. null, to remove the Access Token.CredentialsAgentException
- if something goes wrongpublic java.awt.Component getPreferencesDecorationPanel()
CredentialsAgent
getPreferencesDecorationPanel
in interface CredentialsAgent