Changeset 5855 for trunk

Show
Ignore:
Timestamp:
11/10/08 14:58:17 (2 months ago)
Author:
marc.englund@…
Message:

Double cookie submit pattern impl; fixes #2198

Location:
trunk/src/com/itmill/toolkit/terminal/gwt
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java

    r5839 r5855  
    2626import com.google.gwt.json.client.JSONValue; 
    2727import com.google.gwt.user.client.Command; 
     28import com.google.gwt.user.client.Cookies; 
    2829import com.google.gwt.user.client.DOM; 
    2930import com.google.gwt.user.client.DeferredCommand; 
     
    6162    public static final String VAR_BURST_SEPARATOR = "\u001d"; 
    6263 
     64    public static final String UIDL_SECURITY_COOKIE_NAME = "com.itmill.toolkit.seckey"; 
     65 
    6366    private final HashMap resourcesMap = new HashMap(); 
    6467 
     
    276279            boolean forceSync) { 
    277280        startRequest(); 
     281 
     282        // cookie double submission pattern 
     283        requestData = Cookies.getCookie(UIDL_SECURITY_COOKIE_NAME) 
     284                + VAR_BURST_SEPARATOR + requestData; 
    278285 
    279286        console.log("Making UIDL Request with params: " + requestData); 
     
    638645 
    639646                if (html.length() != 0) { 
    640                     INotification n = new INotification(1000 * 60 * 45); // 45min 
     647                    INotification n = new INotification(1000 * 60 * 45); //45min 
    641648                    n.addEventListener(new NotificationRedirect(url)); 
    642649                    n.show(html, INotification.CENTERED_TOP, 
  • trunk/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

    r5836 r5855  
    1717import java.net.MalformedURLException; 
    1818import java.net.URL; 
     19import java.security.GeneralSecurityException; 
    1920import java.util.Collection; 
    2021import java.util.Enumeration; 
     
    2728import javax.servlet.ServletException; 
    2829import javax.servlet.ServletOutputStream; 
     30import javax.servlet.http.Cookie; 
    2931import javax.servlet.http.HttpServlet; 
    3032import javax.servlet.http.HttpServletRequest; 
     
    4345import com.itmill.toolkit.terminal.ThemeResource; 
    4446import com.itmill.toolkit.terminal.URIHandler; 
     47import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; 
    4548import com.itmill.toolkit.ui.Window; 
    4649 
     
    527530            } 
    528531 
     532        } catch (final GeneralSecurityException e) { 
     533            // TODO handle differently? 
     534            // Invalid security key, show session expired message for now 
     535            try { 
     536                Application.SystemMessages ci = getSystemMessages(); 
     537                if (!UIDLrequest) { 
     538                    // 'plain' http req - e.g. browser reload; 
     539                    // just go ahead redirect the browser 
     540                    response.sendRedirect(ci.getSessionExpiredURL()); 
     541                } else { 
     542                    // send uidl redirect 
     543                    criticalNotification(request, response, ci 
     544                            .getSessionExpiredCaption(), ci 
     545                            .getSessionExpiredMessage(), ci 
     546                            .getSessionExpiredURL()); 
     547                } 
     548                request.getSession().invalidate(); 
     549            } catch (SystemMessageException ee) { 
     550                throw new ServletException(ee); 
     551            } 
     552 
    529553        } catch (final Throwable e) { 
    530554            // if this was an UIDL request, response UIDL back to client 
     
    748772            HttpServletResponse response, Window window, String themeName, 
    749773            Application application) throws IOException, MalformedURLException { 
     774 
     775        // Security: double cookie submission pattern 
     776        Cookie secCookie = new Cookie( 
     777                ApplicationConnection.UIDL_SECURITY_COOKIE_NAME, request 
     778                        .getSession().getId()); 
     779        response.addCookie(secCookie); 
    750780 
    751781        // e.g portlets only want a html fragment 
  • trunk/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java

    r5807 r5855  
    1515import java.lang.reflect.InvocationTargetException; 
    1616import java.lang.reflect.Method; 
     17import java.security.GeneralSecurityException; 
    1718import java.text.DateFormatSymbols; 
    1819import java.text.SimpleDateFormat; 
     
    217218    public void handleUidlRequest(HttpServletRequest request, 
    218219            HttpServletResponse response, ApplicationServlet applicationServlet) 
    219             throws IOException, ServletException { 
     220            throws IOException, ServletException, 
     221            InvalidUIDLSecurityKeyException { 
    220222 
    221223        // repaint requested or session has timed out and new one is created 
     
    573575    private boolean handleVariables(HttpServletRequest request, 
    574576            HttpServletResponse response, Application application2, 
    575             Window window) throws IOException { 
     577            Window window) throws IOException, InvalidUIDLSecurityKeyException { 
    576578        boolean success = true; 
    577579 
     
    592594            final String[] bursts = changes.split(VAR_BURST_SEPARATOR); 
    593595 
    594             for (int bi = 0; bi < bursts.length; bi++) { 
     596            // check security key (==sessionid, double cookie submission 
     597            if (!request.getSession().getId().equals(bursts[0])) { 
     598                throw new InvalidUIDLSecurityKeyException( 
     599                        "Invalid UIDL security key"); 
     600            } 
     601 
     602            for (int bi = 1; bi < bursts.length; bi++) { 
    595603 
    596604                // extract variables to two dim string array 
     
    615623                                        .equals(nextVariable[VAR_PID])) { 
    616624                            // we have more than one value changes in row for 
    617                             // one 
    618                             // variable owner, collect em in HashMap 
     625                            // one variable owner, collect em in HashMap 
    619626                            m = new HashMap(); 
    620627                            m.put(variable[VAR_NAME], convertVariableValue( 
     
    646653                            owner.changeVariables(request, m); 
    647654 
    648                             // Special-case of closing browser-level 
    649                             // windows: track browser-windows currently open in 
    650                             // client 
     655                            // Special-case of closing browser-level windows: 
     656                            // track browser-windows currently open in client 
    651657                            if (owner instanceof Window 
    652658                                    && ((Window) owner).getParent() == null) { 
     
    695701                // Still we must clear component tree between bursts to ensure 
    696702                // that no removed components are updated. The painting after 
    697                 // the 
    698                 // last burst is handled normally by the calling method. 
     703                // the last burst is handled normally by the calling method. 
    699704                if (bi < bursts.length - 1) { 
    700705 
     
    10151020            logoutUrl = application.getURL().toString(); 
    10161021        } 
    1017         // clients JS app is still running, send a special json file to 
    1018         // tell client that application has quit and where to point browser now 
     1022        // clients JS app is still running, send a special json file to tell 
     1023        // client that application has quit and where to point browser now 
    10191024        // Set the response type 
    10201025        response.setContentType("application/json; charset=UTF-8"); 
     
    10681073 
    10691074        // The following algorithm removes any components that would be painted 
    1070         // as 
    1071         // a direct descendant of other components from the dirty components 
    1072         // list. 
    1073         // The result is that each component should be painted exactly once and 
    1074         // any unmodified components will be painted as "cached=true". 
     1075        // as a direct descendant of other components from the dirty components 
     1076        // list. The result is that each component should be painted exactly 
     1077        // once and any unmodified components will be painted as "cached=true". 
    10751078 
    10761079        for (final Iterator i = dirtyPaintabletSet.iterator(); i.hasNext();) { 
     
    13001303    } 
    13011304 
     1305    private class InvalidUIDLSecurityKeyException extends 
     1306            GeneralSecurityException { 
     1307 
     1308        InvalidUIDLSecurityKeyException(String message) { 
     1309            super(message); 
     1310        } 
     1311 
     1312    } 
    13021313}