private void startExternalContainerImageIconResourceServices(String resourcesPath) { Path iconResourcePath = Paths.get(resourcesPath, ManagementUriParts.CONTAINER_ICONS_RESOURCE_PATH); if (!iconResourcePath.toFile().exists()) { logInfo("Skip loading container icons from user resource path"); return; } else { logInfo("Loading container icons from user resource path"); } List<File> files = FileUtils.findFiles(iconResourcePath, new HashSet<>(), false); for (File f : files) { String subPath = f.getAbsolutePath().replace( iconResourcePath.toAbsolutePath().toString(), ""); Path servicePath = Paths .get(ManagementUriParts.CONTAINER_ICONS_RESOURCE_PATH.substring(1), subPath); String servicePathString = FileUtil.getForwardSlashesPathString(servicePath); Operation post = Operation .createPost(UriUtils.buildUri(getHost(), servicePathString)); RestrictiveFileContentService fcs = new RestrictiveFileContentService(f); getHost().startService(post, fcs); } } }
protected void startUiFileContentServices() throws Throwable { Map<Path, String> pathToURIPath = new HashMap<>(); Path baseResourcePath = Utils.getServiceUiResourcePath(this); try { pathToURIPath = discoverUiResources(baseResourcePath, this); } catch (Throwable e) { log(Level.WARNING, "Error enumerating UI resources for %s: %s", this.getSelfLink(), Utils.toString(e)); } if (pathToURIPath.isEmpty()) { log(Level.WARNING, "No custom UI resources found for %s", this.getClass().getName()); return; } for (Entry<Path, String> e : pathToURIPath.entrySet()) { String value = e.getValue(); if (value.contains("/META-INF/")) { continue; } Operation post = Operation .createPost(UriUtils.buildUri(getHost(), value)); RestrictiveFileContentService fcs = new RestrictiveFileContentService( e.getKey().toFile()); getHost().startService(post, fcs); } }
@Test public void testGetContentWhenNotEmbeddedWithXFrameOptions() throws Exception { URL resource = this.getClass() .getResource("/ui/com/vmware/admiral/UiService/container-icons/vmware/admiral.png"); RestrictiveFileContentService service = new RestrictiveFileContentService( new File(resource.toURI())); service.setSelfLink("/container-icons/vmware/admiral.png"); VerificationHost vh = new VerificationHost() { @Override public void sendRequest(Operation op) { op.fail(Operation.STATUS_CODE_NOT_FOUND); } }; service.setHost(vh); // see comment in RestrictiveFileContentService's isEmbedded assignment ConfigurationState config = new ConfigurationState(); config.key = ConfigurationUtil.EMBEDDED_MODE_PROPERTY; config.value = Boolean.toString(false); ConfigurationUtil.initialize(config); Operation get = new Operation() .setUri(UriUtils.buildUri("/container-icons/vmware/admiral.png")); service.handleGet(get); assertEquals(Operation.STATUS_CODE_OK, get.getStatusCode()); assertEquals("SAMEORIGIN", get.getResponseHeader(ConfigurationUtil.UI_FRAME_OPTIONS_HEADER)); }
.getResource("/ui/com/vmware/admiral/UiService/container-icons/vmware/admiral.png"); RestrictiveFileContentService service = new RestrictiveFileContentService( new File(resource.toURI())); service.setSelfLink("/container-icons/vmware/admiral.png");