1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.auth;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.net.PasswordAuthentication;
|
---|
6 | import java.net.Authenticator.RequestorType;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.oauth.OAuthToken;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * A CredentialsAgent manages two credentials:
|
---|
12 | * <ul>
|
---|
13 | * <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials
|
---|
14 | * in JOSM</li>
|
---|
15 | * <li>the credential for {@see RequestorType#PROXY} which is equal to the credentials for an
|
---|
16 | * optional HTTP proxy server a user may use</li>
|
---|
17 | * </ul>
|
---|
18 | *
|
---|
19 | * In addition, it manages an OAuth Access Token for accessing the OSM server.
|
---|
20 | */
|
---|
21 | public interface CredentialsAgent {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Looks up the credentials for a given type.
|
---|
25 | *
|
---|
26 | * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
27 | * for a proxy server
|
---|
28 | * @return the credentials
|
---|
29 | * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
|
---|
30 | */
|
---|
31 | PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Saves the credentials in <code>credentials</code> for the given service type.
|
---|
35 | *
|
---|
36 | * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
37 | * for a proxy server
|
---|
38 | * @param credentials the credentials
|
---|
39 | * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
|
---|
40 | */
|
---|
41 | void store(RequestorType requestorType, String host, PasswordAuthentication credentials) throws CredentialsAgentException;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | *
|
---|
45 | * @param requestorType the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
46 | * for a proxy server
|
---|
47 | * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise.
|
---|
48 | * If true, implementations of this interface are advised to prompt the user for new credentials.
|
---|
49 | * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
|
---|
50 |
|
---|
51 | */
|
---|
52 | CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException;
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
|
---|
56 | * Access Token is currently managed by this CredentialAgent.
|
---|
57 | *
|
---|
58 | * @return the current OAuth Access Token to access the OSM server.
|
---|
59 | * @throws CredentialsAgentException thrown if something goes wrong
|
---|
60 | */
|
---|
61 | OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Stores the OAuth Access Token <code>accessToken</code>.
|
---|
65 | *
|
---|
66 | * @param accessToken the access Token. null, to remove the Access Token.
|
---|
67 | * @throws CredentialsAgentException thrown if something goes wrong
|
---|
68 | */
|
---|
69 | void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException;
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Provide a Panel that is shown below the API password / username fields
|
---|
74 | * in the JOSM Preferences. (E.g. a warning that password is saved unencrypted.)
|
---|
75 | */
|
---|
76 | Component getPreferencesDecorationPanel();
|
---|
77 |
|
---|
78 | }
|
---|