Changeset 4249 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-07-15T20:00:28+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r4245 r4249 188 188 Main.pref.updateSystemProperties(); 189 189 190 DefaultAuthenticator.createInstance( CredentialsManager.getInstance());190 DefaultAuthenticator.createInstance(); 191 191 Authenticator.setDefault(DefaultAuthenticator.getInstance()); 192 192 ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault())); -
trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
r4110 r4249 41 41 public class CredentialDialog extends JDialog { 42 42 43 static public CredentialDialog getOsmApiCredentialDialog(String username, String password ) {44 CredentialDialog dialog = new CredentialDialog( );43 static public CredentialDialog getOsmApiCredentialDialog(String username, String password, String saveUsernameAndPasswordCheckboxText) { 44 CredentialDialog dialog = new CredentialDialog(saveUsernameAndPasswordCheckboxText); 45 45 dialog.prepareForOsmApiCredentials(username, password); 46 46 dialog.pack(); … … 48 48 } 49 49 50 static public CredentialDialog getHttpProxyCredentialDialog(String username, String password ) {51 CredentialDialog dialog = new CredentialDialog( );50 static public CredentialDialog getHttpProxyCredentialDialog(String username, String password, String saveUsernameAndPasswordCheckboxText) { 51 CredentialDialog dialog = new CredentialDialog(saveUsernameAndPasswordCheckboxText); 52 52 dialog.prepareForProxyCredentials(username, password); 53 53 dialog.pack(); … … 57 57 private boolean canceled; 58 58 private CredentialPanel pnlCredentials; 59 String saveUsernameAndPasswordCheckboxText; 59 60 60 61 public boolean isCanceled() { … … 93 94 } 94 95 95 public CredentialDialog() { 96 public CredentialDialog(String saveUsernameAndPasswordCheckboxText) { 97 this.saveUsernameAndPasswordCheckboxText = saveUsernameAndPasswordCheckboxText; 96 98 setModalityType(ModalityType.DOCUMENT_MODAL); 97 99 try { … … 147 149 tfUserName.addKeyListener(new TFKeyListener(owner, tfUserName, tfPassword)); 148 150 tfPassword.addKeyListener(new TFKeyListener(owner, tfPassword, tfUserName)); 149 cbSaveCredentials = new JCheckBox( tr("Save user and password (unencrypted)"));151 cbSaveCredentials = new JCheckBox(owner.saveUsernameAndPasswordCheckboxText); 150 152 151 153 setLayout(new GridBagLayout()); … … 301 303 } 302 304 305 @Override 303 306 public void keyPressed(KeyEvent e) { 304 307 if(e.getKeyChar() == KeyEvent.VK_ENTER) { … … 317 320 } 318 321 322 @Override 319 323 public void keyReleased ( KeyEvent e ){ 320 324 } 321 325 326 @Override 322 327 public void keyTyped ( KeyEvent e ){ 323 328 } … … 331 336 } 332 337 338 @Override 333 339 public void actionPerformed(ActionEvent arg0) { 334 340 setCanceled(false); … … 349 355 } 350 356 357 @Override 351 358 public void actionPerformed(ActionEvent arg0) { 352 359 cancel(); -
trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java
r4245 r4249 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BorderLayout; 6 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; … … 15 16 import javax.swing.JPasswordField; 16 17 import javax.swing.JTextField; 17 import javax.swing.text.html.HTMLEditorKit;18 18 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.gui.widgets.HtmlPanel;21 20 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 22 21 import org.openstreetmap.josm.io.auth.CredentialsAgent; … … 37 36 /** the OSM password */ 38 37 private JPasswordField tfOsmPassword; 39 38 /** a panel with further information, e.g. some warnings */ 39 private JPanel decorationPanel; 40 40 41 41 /** … … 81 81 gc.insets = new Insets(5,0,0,0); 82 82 gc.fill = GridBagConstraints.BOTH; 83 HtmlPanel pnlMessage = new HtmlPanel(); 84 HTMLEditorKit kit = (HTMLEditorKit)pnlMessage.getEditorPane().getEditorKit(); 85 kit.getStyleSheet().addRule(".warning-body {background-color:rgb(253,255,221);padding: 10pt; border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}"); 86 pnlMessage.setText( 87 tr( 88 "<html><body>" 89 + "<p class=\"warning-body\">" 90 + "<strong>Warning:</strong> The password is stored in plain text in the JOSM preferences file. " 91 + "Furthermore, it is transferred <strong>unencrypted</strong> in every request sent to the OSM server. " 92 + "<strong>Do not use a valuable password.</strong>" 93 + "</p>" 94 + "</body></html>" 95 ) 96 ); 97 add(pnlMessage, gc); 83 decorationPanel = new JPanel(new BorderLayout()); 84 add(decorationPanel, gc); 98 85 } 99 86 … … 105 92 CredentialsAgent cm = CredentialsManager.getInstance(); 106 93 try { 94 decorationPanel.removeAll(); 95 decorationPanel.add(cm.getPreferencesDecorationPanel(), BorderLayout.CENTER); 107 96 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER); 108 97 if (pa == null) { -
trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
r4246 r4249 47 47 CredentialDialog dialog = null; 48 48 switch(requestorType) { 49 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password ); break;50 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password ); break;49 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, getSaveUsernameAndPasswordCheckboxText()); break; 50 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, getSaveUsernameAndPasswordCheckboxText()); break; 51 51 } 52 52 dialog.setVisible(true); … … 80 80 } 81 81 82 /** 83 * Provide the text for a checkbox that offers to save the 84 * username and password that has been entered by the user. 85 */ 86 public abstract String getSaveUsernameAndPasswordCheckboxText(); 82 87 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java
r4245 r4249 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 import java.awt.Component; 4 5 import java.net.PasswordAuthentication; 5 6 import java.net.Authenticator.RequestorType; … … 28 29 * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface 29 30 */ 30 publicPasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException;31 PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException; 31 32 32 33 /** … … 38 39 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 39 40 */ 40 publicvoid store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException;41 void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException; 41 42 42 43 /** … … 49 50 50 51 */ 51 publicCredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException;52 CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException; 52 53 53 54 /** … … 58 59 * @throws CredentialsAgentException thrown if something goes wrong 59 60 */ 60 publicOAuthToken lookupOAuthAccessToken() throws CredentialsAgentException;61 OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException; 61 62 62 63 /** … … 66 67 * @throws CredentialsAgentException thrown if something goes wrong 67 68 */ 68 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException; 69 void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException; 70 71 72 /** 73 * Provide a Panel that is shown below the API password / username fields 74 * in the JOSM Preferences. (E.g. a warning that password is saved unencrypted.) 75 */ 76 Component getPreferencesDecorationPanel(); 77 69 78 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r4246 r4249 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 import java.awt.Component; 4 5 import java.net.Authenticator.RequestorType; 5 6 import java.net.PasswordAuthentication; … … 44 45 * Plugins can register a CredentialsAgentFactory, thereby overriding 45 46 * JOSM's default credentials agent. 47 * @param agentFactory The Factory that provides the custom CredentialsAgent. 48 * Can be null to clear the factory and switch back to default behavior. 46 49 */ 47 50 public static void registerCredentialsAgentFactory(CredentialsAgentFactory agentFactory) { … … 84 87 delegate.storeOAuthAccessToken(accessToken); 85 88 } 89 90 @Override 91 public Component getPreferencesDecorationPanel() { 92 return delegate.getPreferencesDecorationPanel(); 93 } 86 94 } -
trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
r4245 r4249 22 22 } 23 23 24 public static void createInstance( CredentialsAgent credentialManager) {25 instance = new DefaultAuthenticator( credentialManager);24 public static void createInstance() { 25 instance = new DefaultAuthenticator(); 26 26 } 27 27 28 private CredentialsAgent credentialsAgent;29 28 private final Map<RequestorType, Boolean> credentialsTried = new HashMap<RequestorType, Boolean>(); 30 29 private boolean enabled = true; 31 30 32 /** 33 * 34 * @param credentialsAgent the credential manager 35 */ 36 private DefaultAuthenticator(CredentialsAgent credentialsAgent) { 37 this.credentialsAgent = credentialsAgent; 31 private DefaultAuthenticator() { 38 32 } 39 33 … … 55 49 } 56 50 boolean tried = credentialsTried.get(getRequestorType()) != null; 57 CredentialsAgentResponse response = credentialsAgent.getCredentials(getRequestorType(), tried);51 CredentialsAgentResponse response = CredentialsManager.getInstance().getCredentials(getRequestorType(), tried); 58 52 if (response == null || response.isCanceled()) 59 53 return null; -
trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java
r4246 r4249 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Component; 4 7 import java.net.PasswordAuthentication; 5 8 import java.net.Authenticator.RequestorType; 9 10 import javax.swing.text.html.HTMLEditorKit; 6 11 7 12 import org.openstreetmap.josm.Main; 8 13 import org.openstreetmap.josm.data.oauth.OAuthToken; 9 14 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 15 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 10 16 11 17 /** … … 101 107 } 102 108 } 109 110 @Override 111 public Component getPreferencesDecorationPanel() { 112 HtmlPanel pnlMessage = new HtmlPanel(); 113 HTMLEditorKit kit = (HTMLEditorKit)pnlMessage.getEditorPane().getEditorKit(); 114 kit.getStyleSheet().addRule(".warning-body {background-color:rgb(253,255,221);padding: 10pt; border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}"); 115 pnlMessage.setText( 116 tr( 117 "<html><body>" 118 + "<p class=\"warning-body\">" 119 + "<strong>Warning:</strong> The password is stored in plain text in the JOSM preferences file. " 120 + "Furthermore, it is transferred <strong>unencrypted</strong> in every request sent to the OSM server. " 121 + "<strong>Do not use a valuable password.</strong>" 122 + "</p>" 123 + "</body></html>" 124 ) 125 ); 126 return pnlMessage; 127 } 128 129 @Override 130 public String getSaveUsernameAndPasswordCheckboxText() { 131 return tr("Save user and password (unencrypted)"); 132 } 133 103 134 }
Note:
See TracChangeset
for help on using the changeset viewer.