Search in sources :

Example 6 with ContextPathEncoder

use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImpl method createComponentEventLink.

public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) {
    StringBuilder builder = new StringBuilder(BUFFER_SIZE);
    // Build up the absolute URI.
    String activePageName = parameters.getActivePageName();
    String containingPageName = parameters.getContainingPageName();
    String eventType = parameters.getEventType();
    String nestedComponentId = parameters.getNestedComponentId();
    boolean hasComponentId = InternalUtils.isNonBlank(nestedComponentId);
    builder.append(contextPath);
    encodeAppFolderAndLocale(builder);
    builder.append(SLASH);
    builder.append(activePageName.toLowerCase());
    if (hasComponentId) {
        builder.append('.');
        builder.append(nestedComponentId);
    }
    if (!hasComponentId || !eventType.equals(EventConstants.ACTION)) {
        builder.append(':');
        builder.append(encodePageName(eventType));
    }
    appendContext(true, parameters.getEventContext(), builder);
    Link result = new LinkImpl(builder.toString(), forForm, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
    EventContext pageActivationContext = parameters.getPageActivationContext();
    if (pageActivationContext.getCount() != 0) {
        // Reuse the builder
        builder.setLength(0);
        appendContext(true, pageActivationContext, builder);
        // Omit that first slash
        result.addParameter(InternalConstants.PAGE_CONTEXT_NAME, builder.substring(1));
    }
    if (!containingPageName.equalsIgnoreCase(activePageName))
        result.addParameter(InternalConstants.CONTAINER_PAGE_NAME, encodePageName(containingPageName));
    return result;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 7 with ContextPathEncoder

use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method root_index_page_gone.

@Test
public void root_index_page_gone() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("Index", new EmptyEventContext());
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 8 with ContextPathEncoder

use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method page_requires_whitelist_and_client_on_whitelist.

@Test
public void page_requires_whitelist_and_client_on_whitelist() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(false);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = mockMetaDataLocator();
    ClientWhitelist whitelist = newMock(ClientWhitelist.class);
    String path = "/foo/Bar";
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, "foo/bar", boolean.class)).andReturn(true);
    expect(whitelist.isClientRequestOnWhitelist()).andReturn(true);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, whitelist);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertEquals(parameters.getActivationContext().getCount(), 0);
    assertFalse(parameters.isLoopback());
    verify();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 9 with ContextPathEncoder

use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method index_stripped_off.

@Test
public void index_stripped_off() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/admin/abc", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 10 with ContextPathEncoder

use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method illegal_activation_context_leads_to_http_404.

@Test
public // TAP5-2436
void illegal_activation_context_leads_to_http_404() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    train_getPath(request, "/foo/pageid=123");
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/pageid=123", false);
    train_isPageName(resolver, "foo", false);
    train_isPageName(resolver, "", true);
    train_canonicalizePageName(resolver, "", "Index");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)19 Request (org.apache.tapestry5.http.services.Request)18 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)18 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 Response (org.apache.tapestry5.http.services.Response)16 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)13 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)11 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 Link (org.apache.tapestry5.http.Link)6 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)6 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 ContextPathEncoder (org.apache.tapestry5.services.ContextPathEncoder)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)3 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2