Changeset 3815 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2011-01-25T10:29:01+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r3795 r3815 645 645 } 646 646 647 /* old style conversion, replace by above call after some transition time */ 648 /* remove this function, when no more old-style preference collections in the code */ 649 @Deprecated 650 synchronized public Collection<String> getCollectionOld(String key, String sep) { 651 putCollectionDefault(key, null); 652 String s = get(key); 653 if (s != null && s.length() != 0) { 654 if(!s.contains("\u001e") && s.contains(sep)) { 655 s = s.replace(sep, "\u001e"); 656 put(key, s); 657 } 658 return Arrays.asList(s.split("\u001e")); 659 } 660 return Collections.emptyList(); 661 } 662 647 663 synchronized public void removeFromCollection(String key, String value) { 648 664 List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList())); -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r3528 r3815 20 20 import java.util.StringTokenizer; 21 21 import java.util.Map.Entry; 22 import java.util.logging.Logger;22 //import java.util.logging.Logger; 23 23 24 24 import javax.swing.JOptionPane; … … 38 38 */ 39 39 public class ServerSidePreferences extends Preferences { 40 static private final Logger logger = Logger.getLogger(ServerSidePreferences.class.getName()); 40 //static private final Logger logger = Logger.getLogger(ServerSidePreferences.class.getName()); 41 42 public class MissingPassword extends Exception{ 43 public String realm; 44 public MissingPassword(String r) { 45 realm = r; 46 } 47 } 41 48 42 49 private final Connection connection; … … 47 54 this.serverUrl = serverUrl; 48 55 } 49 public String download() {56 public String download() throws MissingPassword { 50 57 try { 51 58 System.out.println("reading preferences from "+serverUrl); 52 59 URLConnection con = serverUrl.openConnection(); 53 if (con instanceof HttpURLConnection) { 54 addAuth((HttpURLConnection) con); 60 String username = get("applet.username"); 61 String password = get("applet.password"); 62 if(password.isEmpty() && username.isEmpty()) 63 con.addRequestProperty("Authorization", "Basic "+Base64.encode(username+":"+password)); 64 con.connect(); 65 if(username.isEmpty() && con instanceof HttpURLConnection 66 && ((HttpURLConnection) con).getResponseCode() 67 == HttpURLConnection.HTTP_UNAUTHORIZED) { 68 String t = ((HttpURLConnection) con).getHeaderField("WWW-Authenticate"); 69 t = t.replace("Basic realm=\"","").replace("\"",""); 70 throw new MissingPassword(t); 55 71 } 56 con.connect();57 72 BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); 58 73 StringBuilder b = new StringBuilder(); … … 67 82 } catch (IOException e) { 68 83 e.printStackTrace(); 69 } catch(OsmTransferException e) {70 e.printStackTrace();71 84 } 72 85 return null; … … 77 90 System.out.println("uploading preferences to "+u); 78 91 HttpURLConnection con = (HttpURLConnection)u.openConnection(); 79 // FIXME: 80 // - doesn't work if CredentialManager isn't JosmPreferencesCredentialManager 81 // - doesn't work for OAuth 82 83 con.addRequestProperty("Authorization", "Basic "+Base64.encode(get("osm-server.username")+":"+get("osm-server.password"))); 92 String username = get("applet.username"); 93 String password = get("applet.password"); 94 if(password.isEmpty() && username.isEmpty()) 95 con.addRequestProperty("Authorization", "Basic "+Base64.encode(username+":"+password)); 84 96 con.setRequestMethod("POST"); 85 97 con.setDoOutput(true); … … 146 158 147 159 public void download(String userName, String password) { 148 if (!properties.containsKey("osm-server.username") && userName != null) { 149 properties.put("osm-server.username", userName); 150 } 151 if (!properties.containsKey("osm-server.password") && password != null) { 152 properties.put("osm-server.password", password); 153 } 154 download(); 155 } 156 157 public boolean download() { 160 if (!properties.containsKey("applet.username") && userName != null) { 161 properties.put("applet.username", userName); 162 } 163 if (!properties.containsKey("applet.password") && password != null) { 164 properties.put("applet.password", password); 165 } 166 try { 167 download(); 168 } catch (MissingPassword e) { 169 } 170 } 171 172 public boolean download() throws MissingPassword { 158 173 resetToDefault(); 159 174 String cont = connection.download();
Note:
See TracChangeset
for help on using the changeset viewer.