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 interfaceCredentialsManager.CredentialsAgentFactoryCredentials agent factory.
-
Field Summary
Fields Modifier and Type Field Description private static CredentialsManager.CredentialsAgentFactoryagentFactoryprivate CredentialsAgentdelegateThe credentials agent doing the real stuffprivate static CredentialsManagerinstance
-
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 CredentialsAgentResponsegetCredentials(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 CredentialsManagergetInstance()Replies the single credential agent used in JOSMjava.awt.ComponentgetPreferencesDecorationPanel()Provide a Panel that is shown below the API password / username fields in the JOSM Preferences.java.lang.StringgetUsername()Returns the username for OSM APIjava.lang.StringgetUsername(java.lang.String host)Returns the username for a given hostjava.net.PasswordAuthenticationlookup(java.net.Authenticator.RequestorType requestorType, java.lang.String host)Looks up the credentials for a given type.IOAuthTokenlookupOAuthAccessToken(java.lang.String host)Lookup the current OAuth Access Token to access the specified server.voidpurgeCredentialsCache(java.net.Authenticator.RequestorType requestorType)Purges the internal credentials cache for the given requestor type.voidpurgeCredentialsCache(java.net.Authenticator.RequestorType requestorType, java.lang.String host)Purges the internal credentials cache for the given requestor type and host.static voidregisterCredentialsAgentFactory(CredentialsManager.CredentialsAgentFactory agentFactory)Plugins can register a CredentialsAgentFactory, thereby overriding JOSM's default credentials agent.voidstore(java.net.Authenticator.RequestorType requestorType, java.lang.String host, java.net.PasswordAuthentication credentials)Saves the credentials incredentialsfor the given service type.voidstoreOAuthAccessToken(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:CredentialsAgentLooks up the credentials for a given type.- Specified by:
lookupin interfaceCredentialsAgent- Parameters:
requestorType- the type of service.Authenticator.RequestorType.SERVERfor the OSM API server,Authenticator.RequestorType.PROXYfor 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:CredentialsAgentSaves the credentials incredentialsfor the given service type.- Specified by:
storein interfaceCredentialsAgent- Parameters:
requestorType- the type of service.Authenticator.RequestorType.SERVERfor the OSM API server,Authenticator.RequestorType.PROXYfor 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:CredentialsAgentReturns the credentials needed to to access host.- Specified by:
getCredentialsin interfaceCredentialsAgent- Parameters:
requestorType- the type of service.Authenticator.RequestorType.SERVERfor the OSM API server,Authenticator.RequestorType.PROXYfor 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:CredentialsAgentLookup the current OAuth Access Token to access the specified server. Replies null, if no Access Token is currently managed by this CredentialAgent.- Specified by:
lookupOAuthAccessTokenin 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:CredentialsAgentStores the OAuth Access TokenaccessToken.- Specified by:
storeOAuthAccessTokenin 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:CredentialsAgentProvide 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:
getPreferencesDecorationPanelin interfaceCredentialsAgent- Returns:
- Panel
-
purgeCredentialsCache
public void purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType)
Description copied from interface:CredentialsAgentPurges the internal credentials cache for the given requestor type.- Specified by:
purgeCredentialsCachein interfaceCredentialsAgent- Parameters:
requestorType- the type of service.Authenticator.RequestorType.PROXYfor a proxy server,Authenticator.RequestorType.SERVERfor other servers.
-
purgeCredentialsCache
public void purgeCredentialsCache(java.net.Authenticator.RequestorType requestorType, java.lang.String host)
Description copied from interface:CredentialsAgentPurges the internal credentials cache for the given requestor type and host.- Specified by:
purgeCredentialsCachein interfaceCredentialsAgent- Parameters:
requestorType- the type of service.host- the host.Authenticator.RequestorType.PROXYfor a proxy server,Authenticator.RequestorType.SERVERfor other servers.
-
-