source: trunk/src/org/expeditee/io/ProxyAuth.java@ 570

Last change on this file since 570 was 570, checked in by jts21, 11 years ago

Add settings package which uses reflection to allow changing settings without hard coding the code to change every setting.

  • Currently only works for String/Int/Boolean/Double values
  • Supports default values by looking for fields with the prefix 'default', and will reset unset values to their default if a default exists.
  • For more complex settings (e.g. proxy settings), there is a "onParsed()" callback which can be used to run additional code, and (in the case of the password widget) parse abnormal items.
  • Some of the settings code in FrameUtils.ParseProfile has already been commented out since it's handled by default with the new Settings package. The rest could be moved over to UserSettings.onParsed(). Given the number of settings that remain to be moved, it may be a good idea to add the possibility for setting-specific onParsed() callbacks (could be done quite easily, similarly to how default values are handled).
File size: 1.1 KB
Line 
1package org.expeditee.io;
2
3import java.net.Authenticator;
4import java.net.PasswordAuthentication;
5
6public class ProxyAuth extends Authenticator {
7
8 private String httpUser = null, httpPass = null, httpsUser = null, httpsPass = null;
9 private int attempts = 0;
10
11 public ProxyAuth() {
12 }
13
14 @Override
15 public PasswordAuthentication getPasswordAuthentication() {
16 // TODO: differentiate between HTTP and HTTPS proxies somehow
17 // currently just chooses whichever one is set, preferentially http
18 System.out.println("Authenticating");
19 // stop it from breaking from a redirect loop
20 attempts++;
21 if(attempts > 5) {
22 return null;
23 }
24 String user = httpUser != null ? httpUser : httpsUser;
25 char[] pass = httpPass != null ? httpPass.toCharArray() : (httpsPass != null ? httpsPass.toCharArray() : null);
26 if(user == null || user.length() == 0 || pass == null || pass.length == 0) {
27 return null;
28 }
29 return new PasswordAuthentication(user, pass);
30 }
31
32 public void setup(String user, String pass) {
33 // System.out.println("setup proxy");
34 this.httpUser = user;
35 this.httpPass = pass;
36 this.httpsUser = user;
37 this.httpsPass = pass;
38 attempts = 0;
39 }
40}
Note: See TracBrowser for help on using the repository browser.