Changeset 535


Ignore:
Timestamp:
11/26/13 12:22:37 (10 years ago)
Author:
jts21
Message:

Get proxy config working

Location:
trunk/src/org/expeditee
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/Browser.java

    r513 r535  
    1616import java.awt.event.WindowStateListener;
    1717import java.io.File;
     18import java.net.Authenticator;
    1819import java.net.URL;
    1920import java.util.ArrayList;
     
    3132import org.expeditee.importer.FrameDNDTransferHandler;
    3233import org.expeditee.io.ItemSelection;
     34import org.expeditee.io.ProxyAuth;
    3335import org.expeditee.items.Item;
    3436import org.expeditee.items.widgets.WidgetCacheManager;
     
    6062
    6163        public static Browser _theBrowser = null;
     64       
     65        public static ProxyAuth proxyAuth = new ProxyAuth();
    6266
    6367        private MouseEventRouter _mouseEventRouter;
     
    99103                                                - _theBrowser.getOrigin().y;
    100104                                _initComplete = true;
     105                               
     106                                Authenticator.setDefault(proxyAuth);
    101107                        }
    102108                });
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r529 r535  
    707707                                } else if (attribute.equals("colorwheel")) {
    708708                                        Item.COLOR_WHEEL = getColorWheel(item);
    709                                 } else if (attribute.equals("proxy")) {
    710                                         proxySetup(item);
     709                                } else if (attribute.equals("http_proxy")) {
     710                                        httpProxySetup(item);
     711                                } else if (attribute.equals("https_proxy")) {
     712                                        httpsProxySetup(item);
    711713                                } else if (attribute.equals("fillcolorwheel")) {
    712714                                        Item.FILL_COLOR_WHEEL = getColorWheel(item);
     
    738740
    739741        /**
    740          * Loads proxy config from a frame
    741          * To be used with authentication code to allow web browsers to work through a proxy
     742         * Loads http proxy config from a frame
    742743         * @author jts21
    743744         */
    744         private static void proxySetup(Item item) {
     745        private static void httpProxySetup(Item item) {
    745746                Frame child = item.getChild();
    746                 // FrameUtils.Parse(child);
     747                String host = null, port = null, user = null, pass = null;
    747748                Password passwordWidget = null;
    748749                for(Item config : child.getAllItems()) {
    749                         // System.out.println(config.toString());
    750750                        if(config instanceof Text) {
    751751                                String str = config.getText().trim().toLowerCase();
    752752                                if(str.startsWith("http_host:")) {
    753                                         System.out.println(str.substring(10).trim());
     753                                        if(host != null) {
     754                                                MessageBay.displayMessage("http_host was defined multiple times!", Color.ORANGE);
     755                                        }
     756                                        host = str.substring(10).trim();
    754757                                } else if(str.startsWith("http_port:")) {
    755                                         System.out.println(str.substring(10).trim());
    756                                 } else if(str.startsWith("https_host:")) {
    757                                         System.out.println(str.substring(11).trim());
    758                                 } else if(str.startsWith("https_port:")) {
    759                                         System.out.println(str.substring(11).trim());
    760                                 } else if(str.startsWith("proxy_user:")) {
    761                                         System.out.println(str.substring(11).trim());
    762                                 } else if(str.startsWith("proxy_pass:")) { // unencrypted password
    763                                         System.out.println(str.substring(11).trim());
     758                                        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:")) {
     763                                        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 password
     768                                        if(pass != null) {
     769                                                MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     770                                        }
     771                                        pass = str.substring(11).trim();
    764772                                } else if(str.startsWith("@iw:")) {           // widget
    765773                                        // check if it's a password widget
     
    768776                                                        try {
    769777                                                                passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
    770                                                                 System.out.println(passwordWidget.getPassword());
     778                                                                if(pass != null) {
     779                                                                        MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     780                                                                }
     781                                                                pass = passwordWidget.getPassword();
    771782                                                        } catch (Exception e) {
    772783                                                                e.printStackTrace();
     
    776787                                }
    777788                        } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) {
    778                                 // System.out.println("BLAH");
    779789                                if(passwordWidget == null) {
    780790                                        InteractiveWidget iw;
     
    787797                                                passwordWidget = (Password) iw;
    788798                                        }
    789                                         System.out.println(passwordWidget.getPassword());
    790                                 }
    791                         }
    792                 }
    793         }
     799                                        if(pass != null) {
     800                                                MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     801                                        }
     802                                        pass = passwordWidget.getPassword();
     803                                }
     804                        }
     805                }
     806                System.setProperty("http.proxyHost", host);
     807                System.setProperty("http.proxyPort", port);
     808                Browser.proxyAuth.setupHTTP(user, pass);
     809        }
     810       
     811        /**
     812         * Loads https proxy config from a frame
     813         * @author jts21
     814         */
     815        private static void httpsProxySetup(Item item) {
     816                Frame child = item.getChild();
     817                if(child == null) {
     818                        return;
     819                }
     820                String host = null, port = null, user = null, pass = null;
     821                Password passwordWidget = null;
     822                for(Item config : child.getAllItems()) {
     823                        if(config instanceof Text) {
     824                                String str = config.getText().trim().toLowerCase();
     825                                if(str.startsWith("http_host:")) {
     826                                        if(host != null) {
     827                                                MessageBay.displayMessage("http_host was defined multiple times!", Color.ORANGE);
     828                                        }
     829                                        host = str.substring(10).trim();
     830                                } else if(str.startsWith("http_port:")) {
     831                                        if(port!= null) {
     832                                                MessageBay.displayMessage("http_port was defined multiple times!", Color.ORANGE);
     833                                        }
     834                                        port = str.substring(10).trim();
     835                                } else if(str.startsWith("http_user:")) {
     836                                        if(user != null) {
     837                                                MessageBay.displayMessage("http_user was defined multiple times!", Color.ORANGE);
     838                                        }
     839                                        user = str.substring(11).trim();
     840                                } else if(str.startsWith("http_pass:")) { // unencrypted password
     841                                        if(pass != null) {
     842                                                MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     843                                        }
     844                                        pass = str.substring(11).trim();
     845                                } else if(str.startsWith("@iw:")) {           // widget
     846                                        // check if it's a password widget
     847                                        if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
     848                                                if(passwordWidget == null) {
     849                                                        try {
     850                                                                passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
     851                                                                if(pass != null) {
     852                                                                        MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     853                                                                }
     854                                                                pass = passwordWidget.getPassword();
     855                                                        } catch (Exception e) {
     856                                                                e.printStackTrace();
     857                                                        }
     858                                                }
     859                                        }
     860                                }
     861                        } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) {
     862                                if(passwordWidget == null) {
     863                                        InteractiveWidget iw;
     864                                        if(config instanceof WidgetCorner) {
     865                                                iw = ((WidgetCorner)config).getWidgetSource();
     866                                        } else {
     867                                                iw = ((WidgetEdge)config).getWidgetSource();
     868                                        }
     869                                        if(iw instanceof Password) {
     870                                                passwordWidget = (Password) iw;
     871                                        }
     872                                        if(pass != null) {
     873                                                MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     874                                        }
     875                                        pass = passwordWidget.getPassword();
     876                                }
     877                        }
     878                }
     879                System.setProperty("https.proxyHost", host);
     880                System.setProperty("https.proxyPort", port);
     881                Browser.proxyAuth.setupHTTPS(user, pass);
     882        }
     883       
     884       
    794885
    795886        private static List<Text> getStyle(Frame child) {
Note: See TracChangeset for help on using the changeset viewer.