use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.
the class AbstractBookmarkableMapper method processListener.
/**
* Creates a {@code IRequestHandler} that notifies an {@link IRequestListener}.
*
* @param pageComponentInfo
* @param pageClass
* @param pageParameters
* @return a {@code IRequestHandler} that notifies an {@link IRequestListener}.
*/
protected IRequestHandler processListener(PageComponentInfo pageComponentInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) {
PageInfo pageInfo = pageComponentInfo.getPageInfo();
ComponentInfo componentInfo = pageComponentInfo.getComponentInfo();
Integer renderCount = null;
if (componentInfo != null) {
renderCount = componentInfo.getRenderCount();
}
PageAndComponentProvider provider = new PageAndComponentProvider(pageInfo.getPageId(), pageClass, pageParameters, renderCount, componentInfo.getComponentPath());
provider.setPageSource(getContext());
checkExpiration(provider, pageInfo);
return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
}
use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.
the class AbstractBookmarkableMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
// eliminate the need for IRequestHandlerDelegate
while (requestHandler instanceof IRequestHandlerDelegate) {
requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
}
if (requestHandler instanceof BookmarkablePageRequestHandler) {
// simple bookmarkable URL with no page instance information
BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else if (requestHandler instanceof RenderPageRequestHandler) {
// possibly hybrid URL - bookmarkable URL with page instance information
// but only allowed if the page was created by bookmarkable URL
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
if (handler.getPageProvider().isNewPageInstance()) {
// no existing page instance available, don't bother creating new page instance
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
}
IRequestablePage page = handler.getPage();
if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
PageInfo info = getPageInfo(handler);
PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else {
return null;
}
} else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
// request listener URL with page class information
BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
Class<? extends IRequestablePage> pageClass = handler.getPageClass();
if (!checkPageClass(pageClass)) {
return null;
}
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = handler.getRenderCount();
}
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
return buildUrl(urlInfo);
}
return null;
}
use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.
the class CryptoMapperTest method mountedPageRequestListenerParameter.
/**
* Tests that PageComponentInfo parameters are encrypted on Mounted pages
*/
@Test
public void mountedPageRequestListenerParameter() {
final String componentPath = "link";
PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, componentPath);
IRequestHandler requestHandler = new ListenerRequestHandler(provider);
Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
assertTrue(plainUrl.toString().startsWith(MOUNTED_URL));
/*
* Do not allow unencrypted request listener urls to mounted pages.
*/
assertNull(mapper.mapRequest(getRequest(plainUrl)));
/*
* Test encryption of request listener parameter.
*/
Url encryptedUrl = mapper.mapHandler(requestHandler);
assertEquals(Url.parse(MOUNTED_URL).getSegments(), encryptedUrl.getSegments());
assertTrue(encryptedUrl.getQueryParameters().size() > 0);
for (Url.QueryParameter qp : encryptedUrl.getQueryParameters()) {
if (Strings.isEmpty(qp.getValue())) {
PageComponentInfo pci = PageComponentInfo.parse(qp.getName());
assertNull("PageComponentInfo query parameter not encrypted", pci);
}
}
requestHandler = mapper.mapRequest(getRequest(encryptedUrl));
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
assertEquals(componentPath, handler.getComponentPath());
assertEquals(Page1.class, handler.getPageClass());
/*
* We anticipate that sometimes multiple cryptomappers will be used. It should still work in these situations.
*/
requestHandler = new CryptoMapper(mapper, tester.getApplication()).mapRequest(getRequest(encryptedUrl));
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
handler = (ListenerRequestHandler) requestHandler;
assertEquals(componentPath, handler.getComponentPath());
assertEquals(Page1.class, handler.getPageClass());
}
use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.
the class BookmarkableMapper method parseRequest.
@Override
protected UrlInfo parseRequest(Request request) {
if (Application.exists()) {
if (Application.get().getSecuritySettings().getEnforceMounts()) {
return null;
}
}
if (matches(request)) {
Url url = request.getUrl();
// try to extract page and component information from URL
PageComponentInfo info = getPageComponentInfo(url);
List<String> segments = url.getSegments();
// load the page class
String className;
if (segments.size() >= 3) {
className = segments.get(2);
} else {
className = segments.get(1);
}
if (Strings.isEmpty(className)) {
return null;
}
Class<? extends IRequestablePage> pageClass = getPageClass(className);
if (pageClass != null && IRequestablePage.class.isAssignableFrom(pageClass)) {
// extract the PageParameters from URL if there are any
PageParameters pageParameters = extractPageParameters(request, 3, pageParametersEncoder);
if (pageParameters != null) {
pageParameters.setLocale(resolveLocale());
}
return new UrlInfo(info, pageClass, pageParameters);
}
}
return null;
}
use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.
the class MountedMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
Url url = super.mapHandler(requestHandler);
if (url == null && requestHandler instanceof ListenerRequestHandler && getRecreateMountedPagesAfterExpiry()) {
ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
IRequestablePage page = handler.getPage();
if (checkPageInstance(page)) {
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = page.getRenderCount();
}
String componentPath = handler.getComponentPath();
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
PageComponentInfo pageComponentInfo = new PageComponentInfo(pageInfo, componentInfo);
PageParameters parameters = newPageParameters();
parameters.mergeWith(page.getPageParameters());
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), parameters.mergeWith(handler.getPageParameters()));
url = buildUrl(urlInfo);
}
}
return url;
}
Aggregations