Search in sources :

Example 1 with HttpClientInfo

use of org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo in project scout.rt by eclipse.

the class HtmlFileLoader method loadResource.

@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
    String pathInfo = cacheKey.getResourcePath();
    BinaryResource content = loadResource(pathInfo);
    if (content == null) {
        return null;
    }
    // no cache-control, only E-Tag checks to make sure that a session with timeout is correctly
    // forwarded to the login using a GET request BEFORE the first json POST request
    HttpCacheObject httpCacheObject = new HttpCacheObject(cacheKey, content);
    // Suppress automatic "compatibility mode" in IE in intranet zone
    httpCacheObject.addHttpResponseInterceptor(new HttpResponseHeaderContributor("X-UA-Compatible", "IE=edge") {

        private static final long serialVersionUID = 1L;

        @Override
        public void intercept(HttpServletRequest req, HttpServletResponse resp) {
            HttpClientInfo httpClientInfo = HttpClientInfo.get(req);
            if (httpClientInfo.isMshtml()) {
                // Send headers only for IE
                super.intercept(req, resp);
            }
        }
    });
    return httpCacheObject;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpResponseHeaderContributor(org.eclipse.scout.rt.server.commons.servlet.cache.HttpResponseHeaderContributor) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) HttpClientInfo(org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo)

Example 2 with HttpClientInfo

use of org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo in project scout.rt by eclipse.

the class BrowserFieldContentHttpResponseInterceptor method intercept.

@Override
public void intercept(HttpServletRequest req, HttpServletResponse resp) {
    ContentSecurityPolicy csp = BEANS.get(ContentSecurityPolicy.class).appendScriptSrc("'unsafe-inline'");
    // Bug in Chrome: CSP 'self' is not interpreted correctly in sandboxed iframes, see https://bugs.chromium.org/p/chromium/issues/detail?id=443444
    // Workaround: Add resolved URI to image and style CSP directive to allow loading of images and styles from same origin as nested iframe in browser field
    HttpClientInfo httpClientInfo = HttpClientInfo.get(req);
    if (httpClientInfo.isWebkit()) {
        String resolvedSelfUri = m_browserUri.toString();
        csp.appendImgSrc(resolvedSelfUri).appendStyleSrc(resolvedSelfUri);
    }
    String cspToken = csp.toToken();
    if (httpClientInfo.isMshtml()) {
        resp.setHeader(HttpServletControl.HTTP_HEADER_CSP_LEGACY, cspToken);
    } else {
        resp.setHeader(HttpServletControl.HTTP_HEADER_CSP, cspToken);
    }
}
Also used : ContentSecurityPolicy(org.eclipse.scout.rt.server.commons.servlet.ContentSecurityPolicy) HttpClientInfo(org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo)

Example 3 with HttpClientInfo

use of org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo in project scout.rt by eclipse.

the class UiSession method createUserAgent.

protected UserAgent createUserAgent(JsonStartupRequest jsonStartupReq) {
    HttpClientInfo httpClientInfo = HttpClientInfo.get(currentHttpRequest());
    UserAgents userAgentBuilder = UserAgents.create().withUiLayer(UiLayer.HTML).withUiDeviceType(UiDeviceType.DESKTOP).withUiEngineType(httpClientInfo.getEngineType()).withUiSystem(httpClientInfo.getSystem()).withDeviceId(httpClientInfo.getUserAgent());
    JSONObject userAgent = jsonStartupReq.getUserAgent();
    if (userAgent != null) {
        // TODO [7.0] cgu: it would be great if UserAgent could be changed dynamically, to switch from mobile to tablet mode on the fly, should be done as event in JsonClientSession
        String uiDeviceTypeStr = userAgent.optString("deviceType", null);
        if (uiDeviceTypeStr != null) {
            userAgentBuilder.withUiDeviceType(UiDeviceType.createByIdentifier(uiDeviceTypeStr));
        }
        String uiLayerStr = userAgent.optString("uiLayer", null);
        if (uiLayerStr != null) {
            userAgentBuilder.withUiLayer(UiLayer.createByIdentifier(uiLayerStr));
        }
        boolean touch = userAgent.optBoolean("touch", false);
        userAgentBuilder.withTouch(touch);
        boolean standalone = userAgent.optBoolean("standalone", false);
        userAgentBuilder.withStandalone(standalone);
    }
    return userAgentBuilder.build();
}
Also used : JSONObject(org.json.JSONObject) UserAgents(org.eclipse.scout.rt.shared.ui.UserAgents) HttpClientInfo(org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo)

Aggregations

HttpClientInfo (org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)1 ContentSecurityPolicy (org.eclipse.scout.rt.server.commons.servlet.ContentSecurityPolicy)1 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)1 HttpResponseHeaderContributor (org.eclipse.scout.rt.server.commons.servlet.cache.HttpResponseHeaderContributor)1 UserAgents (org.eclipse.scout.rt.shared.ui.UserAgents)1 JSONObject (org.json.JSONObject)1