1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.auth;
|
---|
3 |
|
---|
4 | import java.net.PasswordAuthentication;
|
---|
5 | import java.net.Authenticator.RequestorType;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.oauth.OAuthToken;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * A CredentialManager manages two credentials:
|
---|
11 | * <ul>
|
---|
12 | * <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials
|
---|
13 | * in JOSM</li>
|
---|
14 | * <li>the credential for {@see RequestorType#PROXY} which is equal to the credentials for an
|
---|
15 | * optional HTTP proxy server a user may use</li>
|
---|
16 | * </ul>
|
---|
17 | *
|
---|
18 | * In addition, it manages an OAuth Access Token for accessing the OSM server.
|
---|
19 | */
|
---|
20 | public interface CredentialsManager {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Looks up the credentials for a given type.
|
---|
24 | *
|
---|
25 | * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
26 | * for a proxy server
|
---|
27 | * @return the credentials
|
---|
28 | * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
|
---|
29 | */
|
---|
30 | public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Saves the credentials in <code>credentials</code> for the given service type.
|
---|
34 | *
|
---|
35 | * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
36 | * for a proxy server
|
---|
37 | * @param credentials the credentials
|
---|
38 | * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
|
---|
39 | */
|
---|
40 | public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | *
|
---|
44 | * @param requestorType the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
|
---|
45 | * for a proxy server
|
---|
46 | * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise.
|
---|
47 | * If true, implementations of this interface are adviced prompt user for new credentials.
|
---|
48 | * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
|
---|
49 |
|
---|
50 | */
|
---|
51 | public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException;
|
---|
52 |
|
---|
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 CredentialManager.
|
---|
57 | *
|
---|
58 | * @return the current OAuth Access Token to access the OSM server.
|
---|
59 | * @throws CredentialsManagerException thrown if something goes wrong
|
---|
60 | */
|
---|
61 | public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException;
|
---|
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 CredentialsManagerException thrown if something goes wrong
|
---|
68 | */
|
---|
69 | public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException;
|
---|
70 | }
|
---|