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

new: JOSM now supports OAuth

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.