Package org.openstreetmap.josm.io.auth
Class CredentialsManager
- java.lang.Object
-
- 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
.- Since:
- 2641
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CredentialsManager.CredentialsAgentFactory
Credentials agent factory.
-
Field Summary
Fields Modifier and Type Field Description private static CredentialsManager.CredentialsAgentFactory
agentFactory
private CredentialsAgent
delegate
The credentials agent doing the real stuffprivate static CredentialsManager
instance
-
Constructor Summary
Constructors Constructor Description CredentialsManager(CredentialsAgent delegate)
Constructs a newCredentialsManager
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 JOSMjava.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 APIjava.lang.String
getUsername(java.lang.String host)
Returns the username for a given hostjava.net.PasswordAuthentication
lookup(java.net.Authenticator.RequestorType requestorType, java.lang.String host)
Looks up the credentials for a given type.IOAuthToken
lookupOAuthAccessToken(java.lang.String host)
Lookup the current OAuth Access Token to access the specified server.void
purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType)
Purges the internal credentials cache for the given requestor type.void
purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType, java.lang.String host)
Purges the internal credentials cache for the given requestor type and host.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 incredentials
for the given service type.void
storeOAuthAccessToken(java.lang.String host, IOAuthToken accessToken)
Stores the OAuth Access TokenaccessToken
.
-
-
-
Field Detail
-
instance
private static volatile CredentialsManager instance
-
agentFactory
private static CredentialsManager.CredentialsAgentFactory agentFactory
-
delegate
private final CredentialsAgent delegate
The credentials agent doing the real stuff
-
-
Constructor Detail
-
CredentialsManager
public CredentialsManager(CredentialsAgent delegate)
Constructs a newCredentialsManager
.- Parameters:
delegate
- The credentials agent backing this credential manager. Must not benull
-
-
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.
-
getCredentialsAgentClass
public final java.lang.Class<? extends CredentialsAgent> getCredentialsAgentClass()
Returns type of credentials agent backing this credentials manager.- Returns:
- The type of credentials agent
-
getUsername
public java.lang.String getUsername()
Returns the username for OSM API- Returns:
- the username for OSM API
-
getUsername
public java.lang.String getUsername(java.lang.String host)
Returns the username for a given host- Parameters:
host
- The host for which username is wanted- Returns:
- The username for
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 interfaceCredentialsAgent
- Parameters:
requestorType
- the type of service.Authenticator.RequestorType.SERVER
for the OSM API server,Authenticator.RequestorType.PROXY
for a proxy serverhost
- the hostname for these credentials- Returns:
- the credentials
- Throws:
CredentialsAgentException
- 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 incredentials
for the given service type.- Specified by:
store
in interfaceCredentialsAgent
- Parameters:
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 credentials- Throws:
CredentialsAgentException
- if a problem occurs in a implementation of this interface
-
getCredentials
public CredentialsAgentResponse getCredentials(java.net.Authenticator.RequestorType requestorType, java.lang.String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException
Description copied from interface:CredentialsAgent
Returns the credentials needed to to access host.- Specified by:
getCredentials
in interfaceCredentialsAgent
- Parameters:
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.- Returns:
- the credentials
- Throws:
CredentialsAgentException
- if a problem occurs in a implementation of this interface
-
lookupOAuthAccessToken
public IOAuthToken lookupOAuthAccessToken(java.lang.String host) throws CredentialsAgentException
Description copied from interface:CredentialsAgent
Lookup the current OAuth Access Token to access the specified server. Replies null, if no Access Token is currently managed by this CredentialAgent.- Specified by:
lookupOAuthAccessToken
in interfaceCredentialsAgent
- Parameters:
host
- The host to get OAuth credentials for- Returns:
- the current OAuth Access Token to access the specified server.
- Throws:
CredentialsAgentException
- if something goes wrong
-
storeOAuthAccessToken
public void storeOAuthAccessToken(java.lang.String host, IOAuthToken accessToken) throws CredentialsAgentException
Description copied from interface:CredentialsAgent
Stores the OAuth Access TokenaccessToken
.- Specified by:
storeOAuthAccessToken
in interfaceCredentialsAgent
- Parameters:
host
- The host the access token is foraccessToken
- the access Token. null, to remove the Access Token. This will remove all IOAuthTokens not managed byCredentialsAgent.storeOAuthAccessToken(String, IOAuthToken)
.- Throws:
CredentialsAgentException
- 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 interfaceCredentialsAgent
- Returns:
- Panel
-
purgeCredentialsCache
public void purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType)
Description copied from interface:CredentialsAgent
Purges the internal credentials cache for the given requestor type.- Specified by:
purgeCredentialsCache
in interfaceCredentialsAgent
- Parameters:
requestorType
- the type of service.Authenticator.RequestorType.PROXY
for a proxy server,Authenticator.RequestorType.SERVER
for other servers.
-
purgeCredentialsCache
public void purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType, java.lang.String host)
Description copied from interface:CredentialsAgent
Purges the internal credentials cache for the given requestor type and host.- Specified by:
purgeCredentialsCache
in interfaceCredentialsAgent
- Parameters:
requestorType
- the type of service.host
- the host.Authenticator.RequestorType.PROXY
for a proxy server,Authenticator.RequestorType.SERVER
for other servers.
-
-