コード例 #1
0
 /** @see CredentialsAgent#store */
 @Override
 public void store(RequestorType requestorType, String host, PasswordAuthentication credentials)
     throws CredentialsAgentException {
   if (requestorType == null) return;
   switch (requestorType) {
     case SERVER:
       if (Utils.equal(OsmApi.getOsmApi().getHost(), host)) {
         Main.pref.put("osm-server.username", credentials.getUserName());
         if (credentials.getPassword() == null) {
           Main.pref.put("osm-server.password", null);
         } else {
           Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword()));
         }
       } else if (host != null) {
         Main.pref.put("server.username." + host, credentials.getUserName());
         if (credentials.getPassword() == null) {
           Main.pref.put("server.password." + host, null);
         } else {
           Main.pref.put("server.password." + host, String.valueOf(credentials.getPassword()));
         }
       }
       break;
     case PROXY:
       Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName());
       if (credentials.getPassword() == null) {
         Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null);
       } else {
         Main.pref.put(
             ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword()));
       }
       break;
   }
 }
コード例 #2
0
 /** @see CredentialsAgent#lookup */
 @Override
 public PasswordAuthentication lookup(RequestorType requestorType, String host)
     throws CredentialsAgentException {
   if (requestorType == null) return null;
   String user;
   String password;
   switch (requestorType) {
     case SERVER:
       if (Utils.equal(OsmApi.getOsmApi().getHost(), host)) {
         user = Main.pref.get("osm-server.username", null);
         password = Main.pref.get("osm-server.password", null);
       } else if (host != null) {
         user = Main.pref.get("server.username." + host, null);
         password = Main.pref.get("server.password." + host, null);
       } else {
         user = null;
         password = null;
       }
       if (user == null) return null;
       return new PasswordAuthentication(
           user, password == null ? new char[0] : password.toCharArray());
     case PROXY:
       user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null);
       password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null);
       if (user == null) return null;
       return new PasswordAuthentication(
           user, password == null ? new char[0] : password.toCharArray());
   }
   return null;
 }