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 Object implements CredentialsAgent
CredentialManager is a factory for the single credential agent used. Currently, it defaults to replying an instance ofJosmPreferencesCredentialAgent
.- 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(Authenticator.RequestorType requestorType, String host, boolean noSuccessWithLastResponse)
Returns the credentials needed to to access host.Class<? extends CredentialsAgent>
getCredentialsAgentClass()
Returns type of credentials agent backing this credentials manager.static CredentialsManager
getInstance()
Replies the single credential agent used in JOSMComponent
getPreferencesDecorationPanel()
Provide a Panel that is shown below the API password / username fields in the JOSM Preferences.String
getUsername()
Returns the username for OSM APIString
getUsername(String host)
Returns the username for a given hostPasswordAuthentication
lookup(Authenticator.RequestorType requestorType, String host)
Looks up the credentials for a given type.OAuthToken
lookupOAuthAccessToken()
Lookup the current OAuth Access Token to access the OSM server.void
purgeCredentialsCache(Authenticator.RequestorType requestorType)
Purges the internal credentials cache for the given requestor type.static void
registerCredentialsAgentFactory(CredentialsManager.CredentialsAgentFactory agentFactory)
Plugins can register a CredentialsAgentFactory, thereby overriding JOSM's default credentials agent.void
store(Authenticator.RequestorType requestorType, String host, PasswordAuthentication credentials)
Saves the credentials incredentials
for the given service type.void
storeOAuthAccessToken(OAuthToken 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 Class<? extends CredentialsAgent> getCredentialsAgentClass()
Returns type of credentials agent backing this credentials manager.- Returns:
- The type of credentials agent
-
getUsername
public String getUsername()
Returns the username for OSM API- Returns:
- the username for OSM API
-
getUsername
public String getUsername(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 PasswordAuthentication lookup(Authenticator.RequestorType requestorType, 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(Authenticator.RequestorType requestorType, String host, 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(Authenticator.RequestorType requestorType, 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 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 interfaceCredentialsAgent
- Returns:
- the current OAuth Access Token to access the OSM server.
- Throws:
CredentialsAgentException
- if something goes wrong
-
storeOAuthAccessToken
public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException
Description copied from interface:CredentialsAgent
Stores the OAuth Access TokenaccessToken
.- Specified by:
storeOAuthAccessToken
in interfaceCredentialsAgent
- Parameters:
accessToken
- the access Token. null, to remove the Access Token.- Throws:
CredentialsAgentException
- if something goes wrong
-
getPreferencesDecorationPanel
public 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(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.SERVER
for the OSM API server,Authenticator.RequestorType.PROXY
for a proxy server
-
-