Changeset 538
- Timestamp:
- 11/27/13 10:31:19 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/FrameUtils.java
r536 r538 744 744 */ 745 745 private static void httpProxySetup(Item item) { 746 try { 747 String[] data = proxyParse(item); 748 System.setProperty("http.proxyHost", data[0]); 749 System.setProperty("http.proxyPort", data[1]); 750 Browser.proxyAuth.setupHTTP(data[2], data[3]); 751 } catch(Exception e) { 752 System.err.println("Failed to setup HTTP proxy"); 753 e.printStackTrace(); 754 } 755 } 756 757 /** 758 * Loads https proxy config from a frame 759 * @author jts21 760 */ 761 private static void httpsProxySetup(Item item) { 762 String[] data = proxyParse(item); 763 try { 764 System.setProperty("https.proxyHost", data[0]); 765 System.setProperty("https.proxyPort", data[1]); 766 Browser.proxyAuth.setupHTTPS(data[2], data[3]); 767 } catch(Exception e) { 768 System.err.println("Failed to setup HTTPS proxy"); 769 e.printStackTrace(); 770 } 771 } 772 773 /** 774 * Loads proxy config from a frame, 775 * @see httpProxySetup 776 * @see httpsProxySetup 777 * @param item 778 * @return array of 4 strings, containing in order: 779 * host 780 * port 781 * user 782 * pass 783 */ 784 private static String[] proxyParse(Item item) { 746 785 Frame child = item.getChild(); 747 786 String host = null, port = null, user = null, pass = null; … … 750 789 if(config instanceof Text) { 751 790 String str = config.getText().trim().toLowerCase(); 752 if(str.startsWith("h ttp_host:")) {791 if(str.startsWith("host:")) { 753 792 if(host != null) { 754 MessageBay.displayMessage("h ttp_host was defined multiple times!", Color.ORANGE);755 } 756 host = str.substring( 10).trim();757 } else if(str.startsWith(" http_port:")) {793 MessageBay.displayMessage("host was defined multiple times!", Color.ORANGE); 794 } 795 host = str.substring(5).trim(); 796 } else if(str.startsWith("port:")) { 758 797 if(port!= null) { 759 MessageBay.displayMessage(" http_port was defined multiple times!", Color.ORANGE);760 } 761 port = str.substring( 10).trim();762 } else if(str.startsWith(" http_user:")) {798 MessageBay.displayMessage("port was defined multiple times!", Color.ORANGE); 799 } 800 port = str.substring(5).trim(); 801 } else if(str.startsWith("user:")) { 763 802 if(user != null) { 764 MessageBay.displayMessage(" http_user was defined multiple times!", Color.ORANGE);765 } 766 user = str.substring( 11).trim();767 } else if(str.startsWith(" http_pass:")) { // unencrypted password803 MessageBay.displayMessage("user was defined multiple times!", Color.ORANGE); 804 } 805 user = str.substring(6).trim(); 806 } else if(str.startsWith("pass:")) { // unencrypted password 768 807 if(pass != null) { 769 MessageBay.displayMessage(" http_pass was defined multiple times!", Color.ORANGE);770 } 771 pass = str.substring( 11).trim();808 MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE); 809 } 810 pass = str.substring(6).trim(); 772 811 } else if(str.startsWith("@iw:")) { // widget 773 812 // check if it's a password widget … … 777 816 passwordWidget = (Password) InteractiveWidget.createWidget((Text)config); 778 817 if(pass != null) { 779 MessageBay.displayMessage(" http_pass was defined multiple times!", Color.ORANGE);818 MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE); 780 819 } 781 820 pass = passwordWidget.getPassword(); … … 798 837 } 799 838 if(pass != null) { 800 MessageBay.displayMessage(" http_pass was defined multiple times!", Color.ORANGE);839 MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE); 801 840 } 802 841 pass = passwordWidget.getPassword(); … … 805 844 } 806 845 if(host == null) { 807 MessageBay.displayMessage("h ttp_host was not defined!", Color.ORANGE);846 MessageBay.displayMessage("host was not defined!", Color.ORANGE); 808 847 } 809 848 if(port == null) { 810 MessageBay.displayMessage(" http_port was not defined! (defaulted to 80)", Color.ORANGE);849 MessageBay.displayMessage("port was not defined! (defaulted to 80)", Color.ORANGE); 811 850 port = "80"; 812 851 } 813 852 if(user == null) { 814 MessageBay.displayMessage(" http_user was not defined!", Color.ORANGE);853 MessageBay.displayMessage("user was not defined!", Color.ORANGE); 815 854 } 816 855 if(pass == null) { 817 MessageBay.displayMessage("http_pass was not defined!", Color.ORANGE); 818 } 819 System.setProperty("http.proxyHost", host); 820 System.setProperty("http.proxyPort", port); 821 Browser.proxyAuth.setupHTTP(user, pass); 822 } 823 824 /** 825 * Loads https proxy config from a frame 826 * @author jts21 827 */ 828 private static void httpsProxySetup(Item item) { 829 Frame child = item.getChild(); 830 if(child == null) { 831 return; 832 } 833 String host = null, port = null, user = null, pass = null; 834 Password passwordWidget = null; 835 for(Item config : child.getAllItems()) { 836 if(config instanceof Text) { 837 String str = config.getText().trim().toLowerCase(); 838 if(str.startsWith("http_host:")) { 839 if(host != null) { 840 MessageBay.displayMessage("https_host was defined multiple times!", Color.ORANGE); 841 } 842 host = str.substring(10).trim(); 843 } else if(str.startsWith("https_port:")) { 844 if(port!= null) { 845 MessageBay.displayMessage("https_port was defined multiple times!", Color.ORANGE); 846 } 847 port = str.substring(10).trim(); 848 } else if(str.startsWith("https_user:")) { 849 if(user != null) { 850 MessageBay.displayMessage("https_user was defined multiple times!", Color.ORANGE); 851 } 852 user = str.substring(11).trim(); 853 } else if(str.startsWith("https_pass:")) { // unencrypted password 854 if(pass != null) { 855 MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE); 856 } 857 pass = str.substring(11).trim(); 858 } else if(str.startsWith("@iw:")) { // widget 859 // check if it's a password widget 860 if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) { 861 if(passwordWidget == null) { 862 try { 863 passwordWidget = (Password) InteractiveWidget.createWidget((Text)config); 864 if(pass != null) { 865 MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE); 866 } 867 pass = passwordWidget.getPassword(); 868 } catch (Exception e) { 869 e.printStackTrace(); 870 } 871 } 872 } 873 } 874 } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) { 875 if(passwordWidget == null) { 876 InteractiveWidget iw; 877 if(config instanceof WidgetCorner) { 878 iw = ((WidgetCorner)config).getWidgetSource(); 879 } else { 880 iw = ((WidgetEdge)config).getWidgetSource(); 881 } 882 if(iw instanceof Password) { 883 passwordWidget = (Password) iw; 884 } 885 if(pass != null) { 886 MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE); 887 } 888 pass = passwordWidget.getPassword(); 889 } 890 } 891 } 892 if(host == null) { 893 MessageBay.displayMessage("https_host was not defined!", Color.ORANGE); 894 } 895 if(port == null) { 896 MessageBay.displayMessage("https_port was not defined! (defaulted to 80)", Color.ORANGE); 897 port = "80"; 898 } 899 if(user == null) { 900 MessageBay.displayMessage("https_user was not defined!", Color.ORANGE); 901 } 902 if(pass == null) { 903 MessageBay.displayMessage("https_pass was not defined!", Color.ORANGE); 904 } 905 System.setProperty("https.proxyHost", host); 906 System.setProperty("https.proxyPort", port); 907 Browser.proxyAuth.setupHTTPS(user, pass); 908 } 909 910 856 MessageBay.displayMessage("pass was not defined!", Color.ORANGE); 857 } 858 return new String[] { host, port, user, pass }; 859 } 911 860 912 861 private static List<Text> getStyle(Frame child) { -
trunk/src/org/expeditee/io/ProxyAuth.java
r536 r538 7 7 8 8 private String httpUser = null, httpPass = null, httpsUser = null, httpsPass = null; 9 private int attempts = 0; 9 10 10 11 public ProxyAuth() { … … 16 17 // currently just chooses whichever one is set, preferentially http 17 18 System.out.println("Authenticating"); 18 return new PasswordAuthentication(httpUser != null ? httpUser : httpsUser, httpPass != null ? httpPass.toCharArray() : httpsPass.toCharArray()); 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); 19 30 } 20 31 … … 23 34 this.httpUser = user; 24 35 this.httpPass = pass; 36 attempts = 0; 25 37 } 26 38 … … 29 41 this.httpsUser = user; 30 42 this.httpsPass = pass; 43 attempts = 0; 31 44 } 32 45 }
Note:
See TracChangeset
for help on using the changeset viewer.