コード例 #1
0
 public void saveToPreferences() {
   CredentialsAgent cm = CredentialsManager.getInstance();
   try {
     PasswordAuthentication pa =
         new PasswordAuthentication(tfOsmUserName.getText().trim(), tfOsmPassword.getPassword());
     cm.store(RequestorType.SERVER, pa);
   } catch (CredentialsAgentException e) {
     e.printStackTrace();
     System.err.println(tr("Warning: failed to save OSM credentials to credential manager."));
     System.err.println(
         tr("Current credential manager is of type ''{0}''", cm.getClass().getName()));
   }
 }
コード例 #2
0
 public void initFromPreferences() {
   CredentialsAgent cm = CredentialsManager.getInstance();
   try {
     decorationPanel.removeAll();
     decorationPanel.add(cm.getPreferencesDecorationPanel(), BorderLayout.CENTER);
     PasswordAuthentication pa = cm.lookup(RequestorType.SERVER);
     if (pa == null) {
       tfOsmUserName.setText("");
       tfOsmPassword.setText("");
     } else {
       tfOsmUserName.setText(pa.getUserName() == null ? "" : pa.getUserName());
       tfOsmPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
     }
   } catch (CredentialsAgentException e) {
     e.printStackTrace();
     System.err.println(
         tr("Warning: failed to retrieve OSM credentials from credential manager."));
     System.err.println(
         tr("Current credential manager is of type ''{0}''", cm.getClass().getName()));
     tfOsmUserName.setText("");
     tfOsmPassword.setText("");
   }
 }