Ignore:
Timestamp:
2024-02-21T22:06:26+01:00 (8 months ago)
Author:
taylor.smock
Message:

See #22810: OSM OAuth 1.0a/Basic auth deprecation and removal

Location:
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java

    r34599 r36211  
    4141
    4242import org.netbeans.spi.keyring.KeyringProvider;
    43 import org.openstreetmap.josm.data.oauth.OAuthToken;
    4443import org.openstreetmap.josm.gui.MainApplication;
    4544import org.openstreetmap.josm.gui.util.WindowGeometry;
    4645import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    4746import org.openstreetmap.josm.io.DefaultProxySelector;
    48 import org.openstreetmap.josm.io.OsmApi;
    4947import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    5048import org.openstreetmap.josm.io.auth.CredentialsManager;
     
    5654public class InitializationWizard extends JDialog {
    5755
    58     protected boolean canceled = false;
     56    protected boolean canceled;
    5957    protected JButton btnCancel, btnBack, btnNext;
    6058    protected Action nextAction, finishAction;
     
    6765   
    6866    public InitializationWizard() {
    69         super(JOptionPane.getFrameForComponent(MainApplication.getMainFrame()), tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL);
     67        super(JOptionPane.getFrameForComponent(MainApplication.getMainFrame()),
     68                tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL);
    7069        build();
    7170        NPMType npm = detectNativePasswordManager();
     
    146145        void onOkAction();
    147146    }
    148    
    149     abstract private static class AbstractWizardPanel implements WizardPanel {
     147
     148    private abstract static class AbstractWizardPanel implements WizardPanel {
    150149       
    151150        /**
     
    175174        }
    176175
    177         abstract protected JPanel getContentPanel();
     176        protected abstract JPanel getContentPanel();
    178177    }
    179178   
     
    229228    private static class SelectionPanel extends AbstractWizardPanel implements ActionListener {
    230229       
    231         private NPMType type;
    232         private InitializationWizard wizard;
     230        private final NPMType type;
     231        private final InitializationWizard wizard;
    233232       
    234233        private JRadioButton rbManage, rbPlain;
     
    350349           
    351350            CredentialsManager cm = CredentialsManager.getInstance();
    352            
    353             String server_username = Config.getPref().get("osm-server.username", null);
    354             String server_password = Config.getPref().get("osm-server.password", null);
    355             if (server_username != null || server_password != null) {
     351
     352            String proxyUsername = Config.getPref().get(DefaultProxySelector.PROXY_USER, null);
     353            String proxyPassword = Config.getPref().get(DefaultProxySelector.PROXY_PASS, null);
     354            String proxyHost = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, null);
     355            if (proxyUsername != null || proxyPassword != null) {
    356356                try {
    357                     cm.store(RequestorType.SERVER, OsmApi.getOsmApi().getHost(), new PasswordAuthentication(string(server_username), toCharArray(server_password)));
    358                     if (rbClear.isSelected()) {
    359                         Config.getPref().put("osm-server.username", null);
    360                         Config.getPref().put("osm-server.password", null);
    361                     }
    362                 } catch (CredentialsAgentException ex) {
    363                     Logging.error(ex);
    364                 }
    365             }
    366            
    367             String proxy_username = Config.getPref().get(DefaultProxySelector.PROXY_USER, null);
    368             String proxy_password = Config.getPref().get(DefaultProxySelector.PROXY_PASS, null);
    369             String proxy_host = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, null);
    370             if (proxy_username != null || proxy_password != null) {
    371                 try {
    372                     cm.store(RequestorType.PROXY, proxy_host, new PasswordAuthentication(string(proxy_username), toCharArray(proxy_password)));
     357                    cm.store(RequestorType.PROXY, proxyHost, new PasswordAuthentication(string(proxyUsername), toCharArray(proxyPassword)));
    373358                    if (rbClear.isSelected()) {
    374359                        Config.getPref().put(DefaultProxySelector.PROXY_USER, null);
     
    379364                }
    380365            }
    381            
    382             String oauth_key = Config.getPref().get("oauth.access-token.key", null);
    383             String oauth_secret = Config.getPref().get("oauth.access-token.secret", null);
    384             if (oauth_key != null || oauth_secret != null) {
    385                 try {
    386                     cm.storeOAuthAccessToken(new OAuthToken(string(oauth_key), string(oauth_secret)));
    387                     if (rbClear.isSelected()) {
    388                         Config.getPref().put("oauth.access-token.key", null);
    389                         Config.getPref().put("oauth.access-token.secret", null);
    390                     }
    391                 } catch (CredentialsAgentException ex) {
    392                     Logging.error(ex);
    393                 }
    394             }
    395         }
    396     }
    397 
    398     private final static String NPM = "Native Password Manager Plugin: ";
     366        }
     367    }
     368
     369    private static final String NPM = "Native Password Manager Plugin: ";
    399370
    400371    private static NPMType detectNativePasswordManager() {
     
    445416                    )
    446417            ).applySafe(this);
    447         } else if (!visible && isShowing()){
     418        } else if (isShowing()){
    448419            new WindowGeometry(this).remember(getClass().getName() + ".geometry");
    449420        }
     
    493464        public void actionPerformed(ActionEvent evt) {
    494465            if (panelIndex <= 0)
    495                 throw new RuntimeException();
     466                // Java 9 will let us pass the panelIndex by itself
     467                throw new IndexOutOfBoundsException("Index out of range: " + panelIndex);
    496468            panelIndex--;
    497469            cardLayout.show(cardPanel, panels.get(panelIndex).getId());
  • applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/NPMCredentialsAgent.java

    r36049 r36211  
    2525import org.openstreetmap.josm.data.oauth.OAuth20Parameters;
    2626import org.openstreetmap.josm.data.oauth.OAuth20Token;
    27 import org.openstreetmap.josm.data.oauth.OAuthToken;
    2827import org.openstreetmap.josm.data.oauth.OAuthVersion;
    2928import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     
    5251     */
    5352    private final Map<RequestorType, PasswordAuthentication> credentialsCache = new EnumMap<>(RequestorType.class);
    54     private OAuthToken oauthCache;
     53
    5554
    5655    /**
     
    187186            credentialsCache.put(rt, new PasswordAuthentication(stringNotNull(username), password != null ? password : new char[0]));
    188187        }
    189     }
    190 
    191     @Override
    192     public OAuthToken lookupOAuthAccessToken() {
    193         if (oauthCache != null)
    194             return oauthCache;
    195         String prolog = getOAuthDescriptor();
    196         char[] key = getProvider().read(prolog+".key");
    197         char[] secret = getProvider().read(prolog+".secret");
    198         return new OAuthToken(stringNotNull(key), stringNotNull(secret));
    199188    }
    200189
     
    223212
    224213    @Override
    225     public void storeOAuthAccessToken(OAuthToken oat) {
    226         String key, secret;
    227         if (oat == null) {
    228             key = null;
    229             secret = null;
    230         } else {
    231             key = oat.getKey();
    232             secret = oat.getSecret();
    233         }
    234         String prolog = getOAuthDescriptor();
    235         if (key == null || key.isEmpty() || secret == null || secret.isEmpty()) {
    236             getProvider().delete(prolog+".key");
    237             getProvider().delete(prolog+".secret");
    238             oauthCache = null;
    239         } else {
    240             getProvider().save(prolog+".key", key.toCharArray(), tr("JOSM/OAuth/OSM API/Key"));
    241             getProvider().save(prolog+".secret", secret.toCharArray(), tr("JOSM/OAuth/OSM API/Secret"));
    242             oauthCache = new OAuthToken(key, secret);
    243         }
    244     }
    245 
    246     @Override
    247214    public void storeOAuthAccessToken(String host, IOAuthToken accessToken) {
    248215        String prolog = getOAuthDescriptor();
Note: See TracChangeset for help on using the changeset viewer.