/** * Determines whether whitelisting is enabled for a container. * * @param container * The container to check. * @return true if whitelisting is enabled for the container false otherwise. */ private boolean isWhitelistingEnabled(String container) { return config.getBool(container, WHITELIST_KEY); }
/** * Determines whether feature administration is enabled for a container. * * @param container * The container to check. * @return true if feature administration is enabled for the container false otherwise. */ private boolean isFeatureAdminEnabled(String container) { return config.getBool(container, ENABLE_FEATURE_ADMIN); }
public void containersChanged(ContainerConfig config, Collection<String> changed, Collection<String> removed) { for (String container : changed) { required.put(container, config.getBool(container, LOCKED_DOMAIN_REQUIRED_KEY)); permittedRefererDomains.put(container, config.getList(container, PERMITTED_REFERER_DOMAINS_KEY)); } for (String container : removed) { required.remove(container); permittedRefererDomains.remove(container); } } }
private boolean usingLockedDomain(Gadget gadget, String container) { if (!ldEnabled) { return false; } if (lockedDomainExclusion()) { return false; } if (config.getBool(container, LOCKED_DOMAIN_REQUIRED_KEY)) { return true; } return gadget.getAllFeatures().contains(LOCKED_DOMAIN_FEATURE_NAME); }
private boolean usingLockedDomain(Gadget gadget, String container) { if (!ldEnabled) { return false; } if (lockedDomainExclusion()) { return false; } if (config.getBool(container, LOCKED_DOMAIN_REQUIRED_KEY)) { return true; } return gadget.getAllFeatures().contains(LOCKED_DOMAIN_FEATURE_NAME); }
/** * Create a LockedDomainService * @param config per-container configuration * @param enabled whether this service should do anything at all. */ @Inject public HashLockedDomainService(ContainerConfig config, @Named("shindig.locked-domain.enabled") boolean enabled) { this.enabled = enabled; lockedSuffixes = Maps.newHashMap(); required = Maps.newHashMap(); Collection<String> containers = config.getContainers(); if (enabled) { for (String container : containers) { String suffix = config.getString(container, LOCKED_DOMAIN_SUFFIX_KEY); if (suffix == null) { LOG.warning("No locked domain configuration for " + container); } else { lockedSuffixes.put(container, suffix); } required.put(container, config.getBool(container, LOCKED_DOMAIN_REQUIRED_KEY)); } } }
/** * Create a LockedDomainService * @param config per-container configuration * @param enabled whether this service should do anything at all. */ @Inject public HashLockedDomainService(ContainerConfig config, @Named("shindig.locked-domain.enabled") boolean enabled) { this.enabled = enabled; lockedSuffixes = Maps.newHashMap(); required = Maps.newHashMap(); Collection<String> containers = config.getContainers(); if (enabled) { for (String container : containers) { String suffix = config.getString(container, LOCKED_DOMAIN_SUFFIX_KEY); if (suffix == null) { LOG.warning("No locked domain configuration for " + container); } else { lockedSuffixes.put(container, suffix); } required.put(container, config.getBool(container, LOCKED_DOMAIN_REQUIRED_KEY)); } } }
protected boolean wantsSecurityToken(Gadget gadget) { return gadget.getAllFeatures().contains(SECURITY_TOKEN_FEATURE_NAME) || config.getBool(gadget.getContext().getContainer(), SECURITY_TOKEN_ALWAYS_KEY); }
protected boolean wantsSecurityToken(Gadget gadget) { return gadget.getAllFeatures().contains(SECURITY_TOKEN_FEATURE_NAME) || config.getBool(gadget.getContext().getContainer(), SECURITY_TOKEN_ALWAYS_KEY); }
protected boolean wantsSecurityToken(Gadget gadget) { return gadget.getAllFeatures().contains(SECURITY_TOKEN_FEATURE_NAME) || config.getBool(gadget.getContext().getContainer(), SECURITY_TOKEN_ALWAYS_KEY); }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
private TestDefaultIframeUriManager makeManager(boolean alwaysToken, boolean ldRequired) { ContainerConfig config = createMock(ContainerConfig.class); String altContainer = CONTAINER + "-alt"; Collection<String> containers = Lists.newArrayList(CONTAINER, altContainer); expect(config.getContainers()).andReturn(containers).anyTimes(); expect(config.getString(CONTAINER, IFRAME_BASE_PATH_KEY)).andReturn(IFRAME_PATH).anyTimes(); expect(config.getString(CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY)).andReturn(LD_SUFFIX).anyTimes(); expect(config.getString(altContainer, LOCKED_DOMAIN_SUFFIX_KEY)) .andReturn(LD_SUFFIX_ALT).anyTimes(); expect(config.getString(CONTAINER, UNLOCKED_DOMAIN_KEY)).andReturn(UNLOCKED_DOMAIN).anyTimes(); expect(config.getBool(CONTAINER, SECURITY_TOKEN_ALWAYS_KEY)).andReturn(alwaysToken).anyTimes(); expect(config.getBool(CONTAINER, LOCKED_DOMAIN_REQUIRED_KEY)).andReturn(ldRequired).anyTimes(); replay(config); return new TestDefaultIframeUriManager(config); }
@Before public void setUp() throws Exception { expect(requiredConfig.getString(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY)).andReturn("-a.example.com:8080").anyTimes(); expect(requiredConfig.getBool(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_REQUIRED_KEY)).andReturn(true).anyTimes(); expect(requiredConfig.getContainers()) .andReturn(Arrays.asList(ContainerConfig.DEFAULT_CONTAINER)).anyTimes(); expect(enabledConfig.getString(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY)).andReturn("-a.example.com:8080").anyTimes(); expect(enabledConfig.getContainers()) .andReturn(Arrays.asList(ContainerConfig.DEFAULT_CONTAINER)).anyTimes(); wantsLocked = makeGadget(true, false, "http://somehost.com/somegadget.xml"); notLocked = makeGadget(false, false, "not-locked"); wantsSecurityToken = makeGadget(false, true, "http://somehost.com/securitytoken.xml"); wantsBoth = makeGadget(true, true, "http://somehost.com/tokenandlocked.xml"); }
@Test public void testGetMetadataWithalwaysAppendST() throws Exception { GadgetsHandlerApi.MetadataRequest request = createMetadataRequest(FakeProcessor.SPEC_URL, CONTAINER, "default", createAuthContext(null, null), ImmutableList.of("*")); setupMockGadgetAdminStore(true); setupMockRegistry(ImmutableList.<String> of("")); expect(config.getBool(CONTAINER, DefaultIframeUriManager.SECURITY_TOKEN_ALWAYS_KEY)).andReturn( true).once(); replay(config); GadgetsHandlerApi.MetadataResponse response = gadgetHandler.getMetadata(request); assertTrue(response.getNeedsTokenRefresh()); verify(); }
@Test public void testGetMetadataWithalwaysAppendST() throws Exception { GadgetsHandlerApi.MetadataRequest request = createMetadataRequest(FakeProcessor.SPEC_URL, CONTAINER, "default", createAuthContext(null, null), ImmutableList.of("*")); setupMockGadgetAdminStore(true); setupMockRegistry(ImmutableList.<String> of("")); expect(config.getBool(CONTAINER, DefaultIframeUriManager.SECURITY_TOKEN_ALWAYS_KEY)).andReturn( true).once(); replay(config); GadgetsHandlerApi.MetadataResponse response = gadgetHandler.getMetadata(request); assertTrue(response.getNeedsTokenRefresh()); verify(); }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testMultiContainer() throws Exception { ContainerConfig inheritsConfig = mock(ContainerConfig.class); expect(inheritsConfig.getContainers()) .andReturn(Arrays.asList(ContainerConfig.DEFAULT_CONTAINER, "other")); expect(inheritsConfig.getBool(isA(String.class), eq(LOCKED_DOMAIN_REQUIRED_KEY))) .andReturn(true).anyTimes(); expect(inheritsConfig.getString(isA(String.class), eq(LOCKED_DOMAIN_SUFFIX_KEY))) .andReturn("-a.example.com:8080").anyTimes(); replay(); lockedDomainService = new HashLockedDomainService(inheritsConfig, true); assertFalse(lockedDomainService.gadgetCanRender("www.example.com", wantsLocked, "other")); assertFalse(lockedDomainService.gadgetCanRender("www.example.com", notLocked, "other")); assertTrue(lockedDomainService.gadgetCanRender( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); } }