Changeset 2748 in josm for trunk/src/org
- Timestamp:
- 2010-01-06T20:35:56+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java
r2323 r2748 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 import java.awt.Dimension;8 import java.awt.GridBagLayout;9 7 import java.awt.event.ActionEvent; 10 8 import java.awt.event.KeyEvent; 11 9 12 import javax.swing.JDialog;13 import javax.swing.JOptionPane;14 import javax.swing.JPanel;15 16 10 import org.openstreetmap.josm.Main; 17 11 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 18 import org.openstreetmap.josm.tools.GBC;19 12 import org.openstreetmap.josm.tools.Shortcut; 20 13 … … 30 23 */ 31 24 public PreferencesAction() { 32 super(tr("Preferences..."), "preference", tr("Open a preferences pagefor global settings."),33 Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.GROUP_DIRECT), true);25 super(tr("Preferences..."), "preference", tr("Open a preferences dialog for global settings."), 26 Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.GROUP_DIRECT), true); 34 27 putValue("help", ht("/Action/Preferences")); 35 28 } … … 43 36 44 37 public void run() { 45 PreferenceDialog prefDlg = new PreferenceDialog(); 46 prefDlg.setMinimumSize(new Dimension(400,300)); 47 JPanel prefPanel = new JPanel(new GridBagLayout()); 48 prefPanel.add(prefDlg, GBC.eol().fill(GBC.BOTH)); 49 50 JOptionPane pane = new JOptionPane(prefPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 51 JDialog dlg = pane.createDialog(Main.parent, tr("Preferences")); 52 dlg.setResizable(true); 53 dlg.setMinimumSize(new Dimension(500,400)); 54 55 // if (dlg.getWidth() > 600) 56 // dlg.setSize(600, dlg.getHeight()); 57 // if (dlg.getHeight() > 600) 58 // dlg.setSize(dlg.getWidth(),600); 59 60 int JOSMWidth = Main.parent.getWidth(); 61 int JOSMHeight = Main.parent.getHeight(); 62 63 if (JOSMWidth > 2000 && JOSMWidth > JOSMHeight * 2) 64 // don't center on horizontal span monitor configurations (yes, can be selfish sometimes) 65 JOSMWidth /= 2; 66 67 int targetWidth = JOSMWidth / 2; 68 if (targetWidth < 600) targetWidth = 600; 69 if (targetWidth > 1200) targetWidth = 1200; 70 int targetHeight = (JOSMHeight * 3) / 4; 71 if (targetHeight < 600) targetHeight = 600; 72 if (targetHeight > 1200) targetHeight = 1200; 73 74 int targetX = Main.parent.getX() + JOSMWidth / 2 - targetWidth / 2; 75 int targetY = Main.parent.getY() + JOSMHeight / 2 - targetHeight / 2; 76 77 dlg.setBounds(targetX, targetY, targetWidth, targetHeight); 78 79 dlg.setModal(true); 80 dlg.setVisible(true); 81 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) 82 prefDlg.ok(); 83 dlg.dispose(); 38 new PreferenceDialog(Main.parent).setVisible(true); 84 39 } 85 40 } -
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r2500 r2748 90 90 91 91 while ((line = input.readLine()) != null) { 92 // Skip potential private information 93 if (line.trim().toLowerCase().startsWith("osm-server.username")) { 92 String toCheck = line.trim().toLowerCase(); 93 if (toCheck.startsWith("osm-server.username") 94 || toCheck.startsWith("osm-server.password") 95 || toCheck.startsWith("marker.show") 96 || toCheck.startsWith("oauth.access-token.key") 97 || toCheck.startsWith("oauth.access-token.secret")) { 94 98 continue; 95 99 } 96 if (line.trim().toLowerCase().startsWith("osm-server.password")) {97 continue;98 }99 if (line.trim().toLowerCase().startsWith("marker.show")) {100 continue;101 }102 103 100 text.append(line); 104 101 text.append("\n"); -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r2589 r2748 90 90 int count = 0; 91 91 for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) { 92 if (!w.isUsable()) 92 if (!w.isUsable()) { 93 93 continue; 94 } 94 95 count++; 95 96 } … … 287 288 if (originalNode == pushNode) { 288 289 // clone the node for all other ways 289 pushNode = new Node(pushNode, true );290 pushNode = new Node(pushNode, true /* clear OSM ID */); 290 291 newNodes.add(pushNode); 291 292 cmds.add(new AddCommand(pushNode)); … … 307 308 HashSet<String> rolesToReAdd = null; 308 309 for (Relation r : OsmPrimitive.getFilteredList(originalNode.getReferrers(), Relation.class)) { 309 if (r.isDeleted()) 310 if (r.isDeleted()) { 310 311 continue; 312 } 311 313 newRel = null; 312 314 rolesToReAdd = null; -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r2641 r2748 77 77 System.out.println("uploading preferences to "+u); 78 78 HttpURLConnection con = (HttpURLConnection)u.openConnection(); 79 // FIXME: 80 // - doesn't work if CredentialManager isn't JosmPreferencesCredentialManager 81 // - doesn't work for OAuth 82 79 83 con.addRequestProperty("Authorization", "Basic "+Base64.encode(get("osm-server.username")+":"+get("osm-server.password"))); 80 84 con.setRequestMethod("POST"); -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r2620 r2748 86 86 */ 87 87 public Node(Node clone, boolean clearId) { 88 super(clone.getUniqueId(), true );88 super(clone.getUniqueId(), true /* allow negative IDs */); 89 89 cloneFrom(clone); 90 90 if (clearId) { -
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r2598 r2748 229 229 230 230 /** 231 * Explains a {@see OsmApiException} which was thrown because the authentication at 232 * the OSM server failed 233 * 234 * @param e the exception 235 */ 236 public static void explainAuthenticationFailed(OsmApiException e) { 237 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 238 String msg; 239 if (authMethod.equals("oauth")) { 240 msg = ExceptionUtil.explainFailedOAuthAuthentication(e); 241 } else { 242 msg = ExceptionUtil.explainFailedBasicAuthentication(e); 243 } 244 245 HelpAwareOptionPane.showOptionDialog( 246 Main.parent, 247 msg, 248 tr("Authentication Failed"), 249 JOptionPane.ERROR_MESSAGE, 250 ht("/ErrorMessages#AuthenticationFailed") 251 ); 252 } 253 254 /** 255 * Explains a {@see OsmApiException} which was thrown because accessing a protected 256 * resource was forbidden. 257 * 258 * @param e the exception 259 */ 260 public static void explainAuthorizationFailed(OsmApiException e) { 261 HelpAwareOptionPane.showOptionDialog( 262 Main.parent, 263 ExceptionUtil.explainFailedOAuthAuthorisation(e), 264 tr("Authorisation Failed"), 265 JOptionPane.ERROR_MESSAGE, 266 ht("/ErrorMessages#AuthenticationFailed") 267 ); 268 } 269 270 271 /** 231 272 * Explains a {@see UnknownHostException} which has caused an {@see OsmTransferException}. 232 273 * This is most likely happening when there is an error in the API URL or when … … 302 343 if (e instanceof OsmApiException) { 303 344 OsmApiException oae = (OsmApiException) e; 304 if (oae.getResponseCode() == HttpURLConnection.HTTP_PRECON_FAILED) { 345 switch(oae.getResponseCode()) { 346 case HttpURLConnection.HTTP_PRECON_FAILED: 305 347 explainPreconditionFailed(oae); 306 348 return; 349 case HttpURLConnection.HTTP_GONE: 350 explainGoneForUnknownPrimitive(oae); 351 return; 352 case HttpURLConnection.HTTP_INTERNAL_ERROR: 353 explainInternalServerError(oae); 354 return; 355 case HttpURLConnection.HTTP_BAD_REQUEST: 356 explainBadRequest(oae); 357 return; 358 case HttpURLConnection.HTTP_NOT_FOUND: 359 explainNotFound(oae); 360 return; 361 case HttpURLConnection.HTTP_CONFLICT: 362 explainConflict(oae); 363 return; 364 case HttpURLConnection.HTTP_UNAUTHORIZED: 365 explainAuthenticationFailed(oae); 366 return; 367 case HttpURLConnection.HTTP_FORBIDDEN: 368 explainAuthorizationFailed(oae); 369 return; 307 370 } 308 if (oae.getResponseCode() == HttpURLConnection.HTTP_GONE) { 309 explainGoneForUnknownPrimitive(oae); 310 return; 311 } 312 if (oae.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { 313 explainInternalServerError(oae); 314 return; 315 } 316 if (oae.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) { 317 explainBadRequest(oae); 318 return; 319 } 320 if (oae.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 321 explainNotFound(oae); 322 return; 323 } 324 if (oae.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { 325 explainConflict(oae); 326 return; 327 } 328 329 } 330 explainGeneric(e); 371 explainGeneric(e); 372 } 331 373 } 332 374 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r2715 r2748 21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 23 24 import org.openstreetmap.josm.io.DefaultProxySelector; 24 25 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory; … … 62 63 63 64 /** 65 * Displays help on the console 66 * 67 */ 68 public static void showHelp() { 69 // TODO: put in a platformHook for system that have no console by default 70 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+ 71 tr("usage")+":\n"+ 72 "\tjava -jar josm.jar <options>...\n\n"+ 73 tr("options")+":\n"+ 74 "\t--help|-?|-h "+tr("Show this help")+"\n"+ 75 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+ 76 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+ 77 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+ 78 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+ 79 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+ 80 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+ 81 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+ 82 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+ 83 "\t--language=<language> "+tr("Set the language.")+"\n\n"+ 84 tr("options provided as Java system properties")+":\n"+ 85 "\t-Djosm.home="+tr("/PATH/TO/JOSM/FOLDER/ ")+tr("Change the folder for all user settings")+"\n\n"+ 86 tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" + 87 " Java option to increase the maximum size of allocated memory")+":\n"+ 88 "\t-Xmx...m\n\n"+ 89 tr("examples")+":\n"+ 90 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+ 91 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+ 92 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+ 93 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+ 94 "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+ 95 "\tjava -Xmx400m -jar josm.jar\n\n"+ 96 tr("Parameters are read in the order they are specified, so make sure you load\n"+ 97 "some data before --selection")+"\n\n"+ 98 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n")); 99 } 100 101 /** 64 102 * Main application Startup 65 103 */ … … 102 140 Main.pref.updateSystemProperties(); 103 141 104 Authenticator.setDefault( 105 new DefaultAuthenticator( 106 CredentialsManagerFactory.getCredentialManager() 107 ) 108 ); 142 DefaultAuthenticator.createInstance(CredentialsManagerFactory.getCredentialManager()); 143 Authenticator.setDefault(DefaultAuthenticator.getInstance()); 109 144 ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault())); 110 145 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManagerFactory.getCredentialManager()); 146 147 // asking for help? show help and exit 111 148 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) { 112 // TODO: put in a platformHook for system that have no console by default 113 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+ 114 tr("usage")+":\n"+ 115 "\tjava -jar josm.jar <options>...\n\n"+ 116 tr("options")+":\n"+ 117 "\t--help|-?|-h "+tr("Show this help")+"\n"+ 118 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+ 119 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+ 120 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+ 121 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+ 122 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+ 123 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+ 124 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+ 125 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+ 126 "\t--language=<language> "+tr("Set the language.")+"\n\n"+ 127 tr("options provided as Java system properties")+":\n"+ 128 "\t-Djosm.home="+tr("/PATH/TO/JOSM/FOLDER/ ")+tr("Change the folder for all user settings")+"\n\n"+ 129 tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" + 130 " Java option to increase the maximum size of allocated memory")+":\n"+ 131 "\t-Xmx...m\n\n"+ 132 tr("examples")+":\n"+ 133 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+ 134 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+ 135 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+ 136 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+ 137 "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+ 138 "\tjava -Xmx400m -jar josm.jar\n\n"+ 139 tr("Parameters are read in the order they are specified, so make sure you load\n"+ 140 "some data before --selection")+"\n\n"+ 141 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n")); 149 showHelp(); 142 150 System.exit(0); 143 151 } … … 185 193 public static void removeObsoletePreferences() { 186 194 String[] obsolete = { 187 "sample.preference.that.does.not.exist", // sample comment, expiry date should go here 188 "osm-server.version", // remove this around 10/2009 189 "osm-server.additional-versions", // remove this around 10/2009 190 null 195 "proxy.anonymous", // 01/2010 - not needed anymore. Can be removed mid 2010 196 "proxy.enable" // 01/2010 - not needed anymore. Can be removed mid 2010 191 197 }; 192 for (String i : obsolete) { 193 if (i == null) { 194 continue; 195 } 196 if (Main.pref.hasKey(i)) { 197 Main.pref.removeFromCollection(i, Main.pref.get(i)); 198 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", i)); 198 for (String key : obsolete) { 199 if (Main.pref.hasKey(key)) { 200 Main.pref.removeFromCollection(key, Main.pref.get(key)); 201 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", key)); 199 202 } 200 203 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/AdvancedChangesetQueryPanel.java
r2689 r2748 6 6 import java.awt.BorderLayout; 7 7 import java.awt.Color; 8 import java.awt.Dimension;9 8 import java.awt.GridBagConstraints; 10 9 import java.awt.GridBagLayout; 11 10 import java.awt.Insets; 12 import java.awt.Rectangle;13 11 import java.awt.event.ItemEvent; 14 12 import java.awt.event.ItemListener; … … 28 26 import javax.swing.JScrollPane; 29 27 import javax.swing.JTextField; 30 import javax.swing.Scrollable;31 28 import javax.swing.text.JTextComponent; 32 29 … … 39 36 import org.openstreetmap.josm.gui.widgets.BoundingBoxSelectionPanel; 40 37 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 38 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 41 39 import org.openstreetmap.josm.io.ChangesetQuery; 42 40 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 59 57 protected JPanel buildQueryPanel() { 60 58 ItemListener stateChangeHandler = new RestrictionGroupStateChangeHandler(); 61 JPanel pnl = new QuerySpecificationPanel();59 JPanel pnl = new VerticallyScrollablePanel(); 62 60 pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 63 61 pnl.setLayout(new GridBagLayout()); … … 961 959 } 962 960 963 static private class QuerySpecificationPanel extends JPanel implements Scrollable {964 public Dimension getPreferredScrollableViewportSize() {965 return getPreferredSize();966 }967 968 public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2) {969 return 20;970 }971 972 public boolean getScrollableTracksViewportHeight() {973 return false;974 }975 976 public boolean getScrollableTracksViewportWidth() {977 return true;978 }979 980 public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2) {981 return 10;982 }983 }984 985 961 /** 986 962 * Validator for user ids entered in in a {@see JTextComponent}. -
trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java
r2733 r2748 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.gui.preferences.ProxyPreferences; 19 import org.openstreetmap.josm.gui.preferences.ProxyPreferences.ProxyPolicy; 18 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 19 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel.ProxyPolicy; 20 20 21 21 22 /** … … 99 100 */ 100 101 public void initFromPreferences() { 101 String value = Main.pref.get(ProxyPreferences .PROXY_POLICY);102 String value = Main.pref.get(ProxyPreferencesPanel.PROXY_POLICY); 102 103 if (value.length() == 0) { 103 System.err.println(tr("Warning: no preference ''{0}'' found.", ProxyPreferences .PROXY_POLICY));104 System.err.println(tr("Warning: no preference ''{0}'' found.", ProxyPreferencesPanel.PROXY_POLICY)); 104 105 System.err.println(tr("The proxy will not be used.")); 105 106 proxyPolicy = ProxyPolicy.NO_PROXY; … … 107 108 proxyPolicy= ProxyPolicy.fromName(value); 108 109 if (proxyPolicy == null) { 109 System.err.println(tr("Warning: unexpected value for preference ''{0}'' found. Got ''{1}''. Will use no proxy.", ProxyPreferences .PROXY_POLICY, value));110 System.err.println(tr("Warning: unexpected value for preference ''{0}'' found. Got ''{1}''. Will use no proxy.", ProxyPreferencesPanel.PROXY_POLICY, value)); 110 111 proxyPolicy = ProxyPolicy.NO_PROXY; 111 112 } 112 113 } 113 String host = Main.pref.get(ProxyPreferences .PROXY_HTTP_HOST, null);114 int port = parseProxyPortValue(ProxyPreferences .PROXY_HTTP_PORT, Main.pref.get(ProxyPreferences.PROXY_HTTP_PORT, null));114 String host = Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_HOST, null); 115 int port = parseProxyPortValue(ProxyPreferencesPanel.PROXY_HTTP_PORT, Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_PORT, null)); 115 116 if (host != null && ! host.trim().equals("") && port > 0) { 116 117 httpProxySocketAddress = new InetSocketAddress(host,port); … … 123 124 } 124 125 125 host = Main.pref.get(ProxyPreferences .PROXY_SOCKS_HOST, null);126 port = parseProxyPortValue(ProxyPreferences .PROXY_SOCKS_PORT, Main.pref.get(ProxyPreferences.PROXY_SOCKS_PORT, null));126 host = Main.pref.get(ProxyPreferencesPanel.PROXY_SOCKS_HOST, null); 127 port = parseProxyPortValue(ProxyPreferencesPanel.PROXY_SOCKS_PORT, Main.pref.get(ProxyPreferencesPanel.PROXY_SOCKS_PORT, null)); 127 128 if (host != null && ! host.trim().equals("") && port > 0) { 128 129 socksProxySocketAddress = new InetSocketAddress(host,port); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2734 r2748 466 466 } 467 467 468 protected boolean isUsingOAuth() { 469 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 470 return authMethod.equals("oauth"); 471 } 472 468 473 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException { 469 474 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true); … … 574 579 case HttpURLConnection.HTTP_GONE: 575 580 throw new OsmApiPrimitiveGoneException(errorHeader, errorBody); 576 case HttpURLConnection.HTTP_UNAUTHORIZED:577 case HttpURLConnection.HTTP_PROXY_AUTH:578 // if we get here with HTTP_UNAUTHORIZED or HTTP_PROXY_AUTH the user canceled the579 // username/password dialog. Throw an OsmTransferCancelledException.580 // 581 throw new OsmTransferCancelledException();581 // case HttpURLConnection.HTTP_UNAUTHORIZED: 582 // throw new OsmApiException(retCode, errorHeader, errorBody); 583 // case HttpURLConnection.HTTP_PROXY_AUTH: 584 // throw new OsmApiException(retCode, errorHeader, errorBody); 585 // case HttpURLConnection.HTTP_FORBIDDEN: 586 // throw new OsmApiException(retCode, errorHeader, errorBody); 582 587 case HttpURLConnection.HTTP_CONFLICT: 583 588 if (ChangesetClosedException.errorHeaderMatchesPattern(errorHeader)) … … 585 590 else 586 591 throw new OsmApiException(retCode, errorHeader, errorBody); 592 case HttpURLConnection.HTTP_FORBIDDEN: 593 OsmApiException e = new OsmApiException(retCode, errorHeader, errorBody); 594 e.setAccessedUrl(activeConnection.getURL().toString()); 595 throw e; 587 596 default: 588 597 throw new OsmApiException(retCode, errorHeader, errorBody); -
trunk/src/org/openstreetmap/josm/io/OsmApiException.java
r2512 r2748 8 8 private String errorHeader; 9 9 private String errorBody; 10 private String accessedUrl; 10 11 11 12 public OsmApiException() { … … 60 61 sb.append("ResponseCode=") 61 62 .append(responseCode); 62 if (errorHeader != null && !errorBody.trim().equals("")) {63 if (errorHeader != null && errorBody != null && !errorBody.trim().equals("")) { 63 64 sb.append(", Error Header=<") 64 65 .append(tr(errorHeader)) … … 95 96 return sb.toString(); 96 97 } 98 99 public void setAccessedUrl(String url) { 100 this.accessedUrl = url; 101 } 102 103 public String getAccessedUrl() { 104 return accessedUrl; 105 } 97 106 } -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r2641 r2748 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.net.HttpURLConnection; … … 11 13 import java.util.logging.Logger; 12 14 15 import oauth.signpost.OAuthConsumer; 16 import oauth.signpost.exception.OAuthException; 17 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.oauth.OAuthParameters; 20 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 13 21 import org.openstreetmap.josm.io.auth.CredentialsManagerException; 14 22 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory; … … 27 35 protected boolean cancel = false; 28 36 protected HttpURLConnection activeConnection; 37 protected OAuthParameters oauthParameters; 29 38 30 39 /** … … 59 68 } 60 69 61 protected void addAuth(HttpURLConnection con) throws OsmTransferException { 70 /** 71 * Adds an authentication header for basic authentication 72 * 73 * @param con the connection 74 * @throws OsmTransferException thrown is something went wrong. Check for nested exceptions 75 */ 76 protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException { 62 77 CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder(); 63 78 CredentialsManagerResponse response; … … 89 104 90 105 /** 106 * Signs the connection with an OAuth authentication header 107 * 108 * @param connection the connection 109 * 110 * @throws OsmTransferException thrown if there is currently no OAuth Access Token configured 111 * @throws OsmTransferException thrown if signing fails 112 */ 113 protected void addOAuthAuthorizationHeader(HttpURLConnection connection) throws OsmTransferException { 114 if (oauthParameters == null) { 115 oauthParameters = OAuthParameters.createFromPreferences(Main.pref); 116 } 117 OAuthConsumer consumer = oauthParameters.buildConsumer(); 118 OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance(); 119 if (! holder.containsAccessToken()) 120 throw new OsmTransferException(tr("Failed to add an OAuth authentication header. There is currently no OAuth Access Token configured.")); 121 122 consumer.setTokenWithSecret(holder.getAccessTokenKey(), holder.getAccessTokenSecret()); 123 try { 124 consumer.sign(connection); 125 } catch(OAuthException e) { 126 throw new OsmTransferException(tr("Failed to sign a HTTP connection with an OAuth Authentication header"), e); 127 } 128 } 129 130 protected void addAuth(HttpURLConnection connection) throws OsmTransferException { 131 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 132 if (authMethod.equals("basic")) { 133 addBasicAuthorizationHeader(connection); 134 } else if (authMethod.equals("oauth")) { 135 addOAuthAuthorizationHeader(connection); 136 } else { 137 String msg = tr("Warning: unexpected value for preference ''{0}''. Got ''{1}''.", "osm-server.auth-method", authMethod); 138 System.err.println(msg); 139 throw new OsmTransferException(msg); 140 } 141 } 142 143 /** 91 144 * Replies true if this connection is canceled 92 145 * -
trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java
r2688 r2748 25 25 public class OsmServerUserInfoReader extends OsmServerReader { 26 26 27 public OsmServerUserInfoReader() { 28 setDoAuthenticate(true); 29 } 30 31 @Override 32 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 33 // not implemented 34 return null; 35 } 36 37 protected String getAttribute(Node node, String name) { 27 static protected String getAttribute(Node node, String name) { 38 28 return node.getAttributes().getNamedItem(name).getNodeValue(); 39 29 } 40 30 41 protectedUserInfo buildFromXML(Document document) throws OsmDataParsingException{31 static public UserInfo buildFromXML(Document document) throws OsmDataParsingException{ 42 32 try { 43 33 XPathFactory factory = XPathFactory.newInstance(); … … 121 111 } 122 112 113 public OsmServerUserInfoReader() { 114 setDoAuthenticate(true); 115 } 116 117 @Override 118 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 119 // not implemented 120 return null; 121 } 122 123 124 123 125 public UserInfo fetchUserInfo(ProgressMonitor monitor) throws OsmTransferException { 124 126 try { 125 monitor.beginTask( "Reading user info ...");127 monitor.beginTask(tr("Reading user info ...")); 126 128 InputStream in = getInputStream("user/details", monitor.createSubTaskMonitor(1, true)); 127 129 return buildFromXML( -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r2711 r2748 4 4 import java.net.PasswordAuthentication; 5 5 import java.net.Authenticator.RequestorType; 6 7 import org.openstreetmap.josm.data.oauth.OAuthToken; 6 8 7 9 /** … … 13 15 * optional HTTP proxy server a user may use</li> 14 16 * </ul> 17 * 18 * In addition, it manages an OAuth Access Token for accessing the OSM server. 15 19 */ 16 20 public interface CredentialsManager { … … 46 50 */ 47 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; 48 70 } -
trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
r2711 r2748 8 8 import java.util.logging.Logger; 9 9 10 import org.openstreetmap.josm.Main; 11 10 12 /** 11 13 * This is the default authenticator used in JOSM. It delegates lookup of credentials … … 16 18 public class DefaultAuthenticator extends Authenticator { 17 19 private static final Logger logger = Logger.getLogger(DefaultAuthenticator.class.getName()); 20 private static DefaultAuthenticator instance; 21 22 public static DefaultAuthenticator getInstance() { 23 return instance; 24 } 25 26 public static void createInstance(CredentialsManager credentialManager) { 27 instance = new DefaultAuthenticator(credentialManager); 28 } 18 29 19 30 private CredentialsManager credentialManager; 20 31 private final Map<RequestorType, Boolean> credentialsTried = new HashMap<RequestorType, Boolean>(); 32 private boolean enabled = true; 21 33 22 34 /** … … 24 36 * @param credentialManager the credential manager 25 37 */ 26 p ublicDefaultAuthenticator(CredentialsManager credentialManager) {38 private DefaultAuthenticator(CredentialsManager credentialManager) { 27 39 this.credentialManager = credentialManager; 28 40 } 41 42 29 43 30 44 /** … … 34 48 */ 35 49 @Override protected PasswordAuthentication getPasswordAuthentication() { 50 if (!enabled) 51 return null; 36 52 try { 53 if (getRequestorType().equals(Authenticator.RequestorType.SERVER)) { 54 // if we are working with OAuth we don't prompt for a password 55 // 56 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 57 if (authMethod.equals("oauth")) 58 return null; 59 } 37 60 boolean tried = credentialsTried.get(getRequestorType()) != null; 38 61 CredentialsManagerResponse response = credentialManager.getCredentials(getRequestorType(), tried); … … 46 69 } 47 70 } 71 72 public boolean isEnabled() { 73 return enabled; 74 } 75 76 public void setEnabled(boolean enabled) { 77 this.enabled = enabled; 78 } 48 79 } -
trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialManager.java
r2711 r2748 6 6 7 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.oauth.OAuthToken; 8 9 import org.openstreetmap.josm.gui.io.CredentialDialog; 9 import org.openstreetmap.josm.gui.preferences. ProxyPreferences;10 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 10 11 11 12 /** … … 32 33 return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray()); 33 34 case PROXY: 34 user = Main.pref.get(ProxyPreferences .PROXY_USER, null);35 password = Main.pref.get(ProxyPreferences .PROXY_PASS, null);35 user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null); 36 password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null); 36 37 if (user == null) 37 38 return null; … … 57 58 break; 58 59 case PROXY: 59 Main.pref.put( "proxy.username", credentials.getUserName());60 Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName()); 60 61 if (credentials.getPassword() == null) { 61 Main.pref.put( "proxy.password", null);62 Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null); 62 63 } else { 63 Main.pref.put( "proxy.password", String.valueOf(credentials.getPassword()));64 Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword())); 64 65 } 65 66 break; … … 104 105 return response; 105 106 } 107 108 109 /** 110 * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no 111 * Access Token is currently managed by this CredentialManager. 112 * 113 * @return the current OAuth Access Token to access the OSM server. 114 * @throws CredentialsManagerException thrown if something goes wrong 115 */ 116 public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException { 117 String accessTokenKey = Main.pref.get("oauth.access-token.key", null); 118 String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null); 119 if (accessTokenKey == null && accessTokenSecret == null) 120 return null; 121 return new OAuthToken(accessTokenKey, accessTokenSecret); 122 } 123 124 /** 125 * Stores the OAuth Access Token <code>accessToken</code>. 126 * 127 * @param accessToken the access Token. null, to remove the Access Token. 128 * @throws CredentialsManagerException thrown if something goes wrong 129 */ 130 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException { 131 if (accessToken == null) { 132 Main.pref.put("oauth.access-token.key", null); 133 Main.pref.put("oauth.access-token.secret", null); 134 } else { 135 Main.pref.put("oauth.access-token.key", accessToken.getKey()); 136 Main.pref.put("oauth.access-token.secret", accessToken.getSecret()); 137 } 138 } 106 139 } -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r2512 r2748 19 19 20 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 21 22 import org.openstreetmap.josm.io.ChangesetClosedException; 22 23 import org.openstreetmap.josm.io.OsmApi; … … 87 88 } 88 89 90 public static String explainFailedBasicAuthentication(OsmApiException e) { 91 e.printStackTrace(); 92 return tr("<html>" 93 + "Authentication at the OSM server with the username ''{0}'' failed.<br>" 94 + "Please check the username and the password in the JOSM preferences." 95 + "</html>", 96 Main.pref.get("osm-server.username") 97 ); 98 } 99 100 public static String explainFailedOAuthAuthentication(OsmApiException e) { 101 e.printStackTrace(); 102 return tr("<html>" 103 + "Authentication at the OSM server with the OAuth token ''{0}'' failed.<br>" 104 + "Please launch the preferences dialog and retrieve another OAuth token." 105 + "</html>", 106 OAuthAccessTokenHolder.getInstance().getAccessTokenKey() 107 ); 108 } 109 110 public static String explainFailedOAuthAuthorisation(OsmApiException e) { 111 e.printStackTrace(); 112 return tr("<html>" 113 + "Authorisation at the OSM server with the OAuth token ''{0}'' failed.<br>" 114 + "The token is not authorised to access the protected resource<br>" 115 + "''{1}''.<br>" 116 + "Please launch the preferences dialog and retrieve another OAuth token." 117 + "</html>", 118 OAuthAccessTokenHolder.getInstance().getAccessTokenKey(), 119 e.getAccessedUrl() == null ? tr("unknown") : e.getAccessedUrl() 120 ); 121 } 89 122 /** 90 123 * Explains an error due to a 409 conflict -
trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java
r1169 r2748 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.tools; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.IOException; … … 21 23 /** 22 24 * @return <code>null</code> for success or a string in case of an error. 25 * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched, 26 * {@see Main#platform} 23 27 */ 24 public static String displayUrl(String url) {28 public static String displayUrl(String url) throws IllegalStateException { 25 29 if (Main.applet) { 26 30 try { … … 33 37 } 34 38 39 if (Main.platform == null) 40 throw new IllegalStateException(tr("Failed to open URL. There is currently no platform set. Please set a platform first.")); 35 41 try { 36 42 Main.platform.openUrl(url);
Note:
See TracChangeset
for help on using the changeset viewer.