Ignore:
Timestamp:
2010-01-06T20:35:56+01:00 (14 years ago)
Author:
Gubaer
Message:

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r2598 r2748  
    229229
    230230    /**
     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    /**
    231272     * Explains a {@see UnknownHostException} which has caused an {@see OsmTransferException}.
    232273     * This is most likely happening when there is an error in the API URL or when
     
    302343        if (e instanceof OsmApiException) {
    303344            OsmApiException oae = (OsmApiException) e;
    304             if (oae.getResponseCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
     345            switch(oae.getResponseCode()) {
     346            case HttpURLConnection.HTTP_PRECON_FAILED:
    305347                explainPreconditionFailed(oae);
    306348                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;
    307370            }
    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        }
    331373    }
    332374
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r2715 r2748  
    2121
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    2324import org.openstreetmap.josm.io.DefaultProxySelector;
    2425import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
     
    6263
    6364    /**
     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    /**
    64102     * Main application Startup
    65103     */
     
    102140        Main.pref.updateSystemProperties();
    103141
    104         Authenticator.setDefault(
    105                 new DefaultAuthenticator(
    106                         CredentialsManagerFactory.getCredentialManager()
    107                 )
    108         );
     142        DefaultAuthenticator.createInstance(CredentialsManagerFactory.getCredentialManager());
     143        Authenticator.setDefault(DefaultAuthenticator.getInstance());
    109144        ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault()));
    110 
     145        OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManagerFactory.getCredentialManager());
     146
     147        // asking for help? show help and exit
    111148        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();
    142150            System.exit(0);
    143151        }
     
    185193    public static void removeObsoletePreferences() {
    186194        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
    191197        };
    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));
    199202            }
    200203        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/AdvancedChangesetQueryPanel.java

    r2689 r2748  
    66import java.awt.BorderLayout;
    77import java.awt.Color;
    8 import java.awt.Dimension;
    98import java.awt.GridBagConstraints;
    109import java.awt.GridBagLayout;
    1110import java.awt.Insets;
    12 import java.awt.Rectangle;
    1311import java.awt.event.ItemEvent;
    1412import java.awt.event.ItemListener;
     
    2826import javax.swing.JScrollPane;
    2927import javax.swing.JTextField;
    30 import javax.swing.Scrollable;
    3128import javax.swing.text.JTextComponent;
    3229
     
    3936import org.openstreetmap.josm.gui.widgets.BoundingBoxSelectionPanel;
    4037import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
     38import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    4139import org.openstreetmap.josm.io.ChangesetQuery;
    4240import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    5957    protected JPanel buildQueryPanel() {
    6058        ItemListener stateChangeHandler = new RestrictionGroupStateChangeHandler();
    61         JPanel pnl  = new QuerySpecificationPanel();
     59        JPanel pnl  = new VerticallyScrollablePanel();
    6260        pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    6361        pnl.setLayout(new GridBagLayout());
     
    961959    }
    962960
    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 
    985961    /**
    986962     * Validator for user ids entered in in a {@see JTextComponent}.
Note: See TracChangeset for help on using the changeset viewer.