use of org.apache.wicket.core.request.handler.IPageRequestHandler in project wicket by apache.
the class CsrfPreventionRequestCycleListener method onRequestHandlerResolved.
@Override
public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler) {
if (!isEnabled()) {
log.trace("CSRF listener is disabled, no checks performed");
return;
}
handler = unwrap(handler);
// check if the request is targeted at a page
if (isChecked(handler)) {
IPageRequestHandler prh = (IPageRequestHandler) handler;
IRequestablePage targetedPage = prh.getPage();
HttpServletRequest containerRequest = (HttpServletRequest) cycle.getRequest().getContainerRequest();
String sourceUri = getSourceUri(containerRequest);
// Check if the page should be CSRF protected
if (isChecked(targetedPage)) {
// if so check the Origin HTTP header
checkRequest(containerRequest, sourceUri, targetedPage);
} else {
if (log.isDebugEnabled()) {
log.debug("Targeted page {} was opted out of the CSRF origin checks, allowed", targetedPage.getClass().getName());
}
allowHandler(containerRequest, sourceUri, targetedPage);
}
} else {
if (log.isTraceEnabled())
log.trace("Resolved handler {} doesn't target an action on a page, no CSRF check performed", handler.getClass().getName());
}
}
use of org.apache.wicket.core.request.handler.IPageRequestHandler in project wicket by apache.
the class BookmarkableMapperTest method decode13.
/**
* WICKET-5071
*
* Decodes a request to
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
* /com.example.MyPage when the current base url is
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()} /
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
*/
@Test
public void decode13() {
final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME);
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
StringBuilder url = new StringBuilder();
url.append(context.getBookmarkableIdentifier()).append('/').append(PAGE_CLASS_NAME);
return Url.parse(url.toString());
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
assertNotNull("A handler should be resolved for relative url to a bookmarkable page url!", handler);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
use of org.apache.wicket.core.request.handler.IPageRequestHandler in project wicket by apache.
the class PageInstanceMapperTest method decode10.
@Test
public void decode10() {
final Url url = Url.parse("page?4");
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
return Url.parse("page");
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
checkPage(page, 4);
}
use of org.apache.wicket.core.request.handler.IPageRequestHandler in project wicket by apache.
the class PageInstanceMapperTest method decode9.
@Test
public void decode9() {
final Url url = Url.parse("page?4");
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
return Url.parse("wicket/page");
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
checkPage(page, 4);
}
use of org.apache.wicket.core.request.handler.IPageRequestHandler in project webanno by webanno.
the class RelationRenderer method render.
@Override
public void render(final JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
ArcAdapter typeAdapter = getTypeAdapter();
Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
Feature dependentFeature = type.getFeatureByBaseName(typeAdapter.getTargetFeatureName());
Feature governorFeature = type.getFeatureByBaseName(typeAdapter.getSourceFeatureName());
Type spanType = getType(aJcas.getCas(), typeAdapter.getAttachTypeName());
Feature arcSpanFeature = spanType.getFeatureByBaseName(typeAdapter.getAttachFeatureName());
FeatureStructure dependentFs;
FeatureStructure governorFs;
Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aJcas, windowBegin, windowEnd, type, dependentFeature, governorFeature, arcSpanFeature);
// if this is a governor for more than one dependent, avoid duplicate yield
List<Integer> yieldDeps = new ArrayList<>();
for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
if (typeAdapter.getAttachFeatureName() != null) {
dependentFs = fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
governorFs = fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
} else {
dependentFs = fs.getFeatureValue(dependentFeature);
governorFs = fs.getFeatureValue(governorFeature);
}
String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
if (dependentFs == null || governorFs == null) {
RequestCycle requestCycle = RequestCycle.get();
IPageRequestHandler handler = PageRequestHandlerTracker.getLastHandler(requestCycle);
Page page = (Page) handler.getPage();
StringBuilder message = new StringBuilder();
message.append("Relation [" + typeAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot render.");
if (typeAdapter.getAttachFeatureName() != null) {
message.append("\nRelation [" + typeAdapter.getLayer().getName() + "] attached to feature [" + typeAdapter.getAttachFeatureName() + "].");
}
message.append("\nDependent: " + dependentFs);
message.append("\nGovernor: " + governorFs);
page.warn(message.toString());
continue;
}
aResponse.add(new VArc(typeAdapter.getLayer(), fs, bratTypeName, governorFs, dependentFs, features));
// Render errors if required features are missing
renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
if (relationLinks.keySet().contains(getAddr(governorFs)) && !yieldDeps.contains(getAddr(governorFs))) {
yieldDeps.add(getAddr(governorFs));
// sort the annotations (begin, end)
List<Integer> sortedDepFs = new ArrayList<>(relationLinks.get(getAddr(governorFs)));
sortedDepFs.sort(comparingInt(arg0 -> selectByAddr(aJcas, arg0).getBegin()));
String cm = getYieldMessage(aJcas, sortedDepFs);
aResponse.add(new VComment(governorFs, VCommentType.YIELD, cm));
}
}
}
Aggregations