/** * Returns true if the gadget is requesting to be on a locked domain. If security token locking * has been enabled via {@link #setLockSecurityTokens(Boolean)}, this method will return true if * the gadget is explicitly or implicitly requesting locked domains; otherwise, this will return * true only if the gadget is explicitly requesting locked domains. * * @param gadget * the gadget * @return true if the gadget is requesting to be on a locked domain */ protected boolean isGadgetReqestingLocking(Gadget gadget) { if (this.lockSecurityTokens) { return gadget.getAllFeatures().contains(LOCKED_DOMAIN_FEATURE); } return gadget.getViewFeatures().keySet().contains(LOCKED_DOMAIN_FEATURE); }
private boolean cajaEnabled(Gadget gadget) { return (gadget.getAllFeatures().contains("caja") || "1".equals(gadget.getContext().getParameter("caja"))); }
private boolean cajaEnabled(Gadget gadget) { return (gadget.getAllFeatures().contains("caja") || "1".equals(gadget.getContext().getParameter("caja"))); }
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); }
private boolean gadgetWantsLockedDomain(Gadget gadget) { if (lockSecurityTokens) { return gadget.getAllFeatures().contains("locked-domain"); } return gadget.getSpec().getModulePrefs().getFeatures().keySet().contains("locked-domain"); }
private boolean gadgetWantsLockedDomain(Gadget gadget) { if (lockSecurityTokens) { return gadget.getAllFeatures().contains("locked-domain"); } return gadget.getSpec().getModulePrefs().getFeatures().keySet().contains("locked-domain"); }
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); }
/** * True if the gadget opts into caja or the container forces caja */ public boolean requiresCaja() { if ("1".equals( getContext().getParameter(UriCommon.Param.CAJOLE.getKey()))) { return true; } if (featureRegistry != null) { return getAllFeatures().contains("caja"); } else { return getViewFeatures().containsKey("caja"); } } }
private Gadget mockGadget(String... features) { Gadget gadget = createMock(Gadget.class); expect(gadget.getAllFeatures()).andReturn(Arrays.asList(features)).once(); replay(gadget); return gadget; }
private Gadget mockGadget(String... features) { Gadget gadget = createMock(Gadget.class); expect(gadget.getAllFeatures()).andReturn(Arrays.asList(features)).once(); replay(gadget); return gadget; }
private Gadget mockGadget(String... features) { Gadget gadget = createMock(Gadget.class); expect(gadget.getAllFeatures()).andReturn(Arrays.asList(features)).once(); replay(gadget); return gadget; }
public void rewrite(Gadget gadget, MutableContent mutableContent) throws RewritingException { // Don't touch sanitized gadgets. if (gadget.sanitizeOutput()) { return; } // Quickly return if opensocial-i18n feature is not needed. if (!gadget.getAllFeatures().contains(I18N_FEATURE_NAME)) { return; } try { Document document = mutableContent.getDocument(); Element head = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head"); injectI18NConstants(gadget, head); mutableContent.documentChanged(); } catch (GadgetException e) { throw new RewritingException(e, e.getHttpStatusCode()); } }
public void rewrite(Gadget gadget, MutableContent mutableContent) throws RewritingException { // Don't touch sanitized gadgets. if (gadget.sanitizeOutput()) { return; } // Quickly return if opensocial-i18n feature is not needed. if (!gadget.getAllFeatures().contains(I18N_FEATURE_NAME)) { return; } try { Document document = mutableContent.getDocument(); Element head = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head"); injectI18NConstants(gadget, head); mutableContent.documentChanged(); } catch (GadgetException e) { throw new RewritingException(e, e.getHttpStatusCode()); } }
public void rewrite(Gadget gadget, MutableContent mutableContent) throws RewritingException { // Don't touch sanitized gadgets. if (gadget.sanitizeOutput()) { return; } // Quickly return if opensocial-i18n feature is not needed. if (!gadget.getAllFeatures().contains(I18N_FEATURE_NAME)) { return; } try { Document document = mutableContent.getDocument(); Element head = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head"); injectI18NConstants(gadget, head); mutableContent.documentChanged(); } catch (GadgetException e) { throw new RewritingException(e, e.getHttpStatusCode()); } }
private Gadget makeGadget() throws GadgetException { Gadget gadget = EasyMock.createNiceMock(Gadget.class); GadgetContext context = EasyMock.createNiceMock(GadgetContext.class); expect(context.getUrl()).andReturn(Uri.parse("http://example.com/gadget.xml")).anyTimes(); expect(context.getContainer()).andReturn("cajaContainer").anyTimes(); expect(context.getDebug()).andReturn(false).anyTimes(); expect(gadget.getContext()).andReturn(context).anyTimes(); expect(gadget.getAllFeatures()).andReturn(ImmutableList.of("caja")).anyTimes(); expect(gadget.requiresCaja()).andReturn(true).anyTimes(); replay(context, gadget); return gadget; }
private Gadget makeGadget() throws GadgetException { Gadget gadget = EasyMock.createNiceMock(Gadget.class); GadgetContext context = EasyMock.createNiceMock(GadgetContext.class); expect(context.getUrl()).andReturn(Uri.parse("http://example.com/gadget.xml")).anyTimes(); expect(context.getContainer()).andReturn("cajaContainer").anyTimes(); expect(context.getDebug()).andReturn(false).anyTimes(); expect(gadget.getContext()).andReturn(context).anyTimes(); expect(gadget.getAllFeatures()).andReturn(ImmutableList.of("caja")).anyTimes(); expect(gadget.requiresCaja()).andReturn(true).anyTimes(); replay(context, gadget); return gadget; }
@Test public void testGetFeatures() throws Exception { String xml = "<Module>" + "<ModulePrefs title=\"hello\">" + "<Require feature=\"required1\"/>" + "</ModulePrefs>" + "<Content type=\"html\"/>" + "</Module>"; FeatureRegistry registry = mock(FeatureRegistry.class, true); Gadget gadget = new Gadget() .setContext(context) .setGadgetFeatureRegistry(registry) .setSpec(new GadgetSpec(Uri.parse(SPEC_URL), xml)); Collection<String> needed = Lists.newArrayList(gadget.getSpec().getModulePrefs().getFeatures().keySet()); List<String> returned = Lists.newArrayList(needed); // Call should only happen once, and be cached from there on out. expect(registry.getFeatures(eq(needed))).andReturn(returned).anyTimes(); replay(); List<String> requiredFeatures1 = gadget.getAllFeatures(); assertEquals(returned, requiredFeatures1); List<String> requiredFeatures2 = gadget.getAllFeatures(); assertSame(returned, requiredFeatures2); verify(); }