Changeset 2641 in josm for trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
- Timestamp:
- 2009-12-16T18:58:04+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/auth
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r2628 r2641 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io ;2 package org.openstreetmap.josm.io.auth; 3 3 4 import org.openstreetmap.josm.io.OsmConnection.OsmAuth; 4 import java.net.PasswordAuthentication; 5 import java.net.Authenticator.RequestorType; 5 6 6 7 /** 7 * Manages how username and password are stored. In addition all 8 * username/password-related user interaction is encapsulated here. 8 * A CredentialManager manages two credentials: 9 * <ul> 10 * <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials 11 * in JOSM</li> 12 * <li>the credential for {@see RequestorType#PROXY} which is equal to the credentials for an 13 * optional HTTP proxy server a user may use</li> 14 * </ul> 9 15 */ 10 16 public interface CredentialsManager { 11 enum Key {12 OSM_SERVER_URL("url"),13 USERNAME("username"),14 PASSWORD("password");15 final private String pname;16 private Key(String name) {17 pname = name;18 }19 @Override public String toString() {20 return pname;21 }22 };23 17 24 18 /** 25 * Should throw or return non-null, possibly empty String. 19 * Looks up the credentials for a given type. 20 * 21 * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY} 22 * for a proxy server 23 * @return the credentials 24 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 26 25 */ 27 public String lookup(Key key) throws CMException;26 public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException; 28 27 29 28 /** 30 * May silently fail to store. 29 * Saves the credentials in <code>credentials</code> for the given service type. 30 * 31 * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY} 32 * for a proxy server 33 * @param credentials the credentials 34 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 31 35 */ 32 public void store( Key key, String secret) throws CMException;36 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException; 33 37 34 38 /** 35 * If authentication using the stored credentials fails, this method is 36 * called to promt for new username/password. 39 * 40 * @param requestorType the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY} 41 * for a proxy server 42 * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise. 43 * If true, implementations of this interface are adviced prompt user for new credentials. 44 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 45 37 46 */ 38 public java.net.PasswordAuthentication getPasswordAuthentication(OsmAuth caller); 39 40 /** 41 * Credentials-related preference gui. 42 */ 43 public interface PreferenceAdditions { 44 public void addPreferenceOptions(javax.swing.JPanel panel); 45 public void preferencesChanged(); 46 } 47 public PreferenceAdditions newPreferenceAdditions(); 48 49 public class CMException extends Exception { 50 public CMException() {super();} 51 public CMException(String message, Throwable cause) {super(message, cause);} 52 public CMException(String message) {super(message);} 53 public CMException(Throwable cause) {super(cause);} 54 } 55 public class NoContentException extends CMException { 56 public NoContentException() {super();} 57 public NoContentException(String message, Throwable cause) {super(message, cause);} 58 public NoContentException(String message) {super(message);} 59 public NoContentException(Throwable cause) {super(cause);} 60 } 47 public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException; 61 48 }
Note:
See TracChangeset
for help on using the changeset viewer.