Search in sources :

Example 1 with IPageRequestHandler

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler)

Example 2 with IPageRequestHandler

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);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 3 with IPageRequestHandler

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);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 4 with IPageRequestHandler

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);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 5 with IPageRequestHandler

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));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Page(org.apache.wicket.Page) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) LoggerFactory(org.slf4j.LoggerFactory) Feature(org.apache.uima.cas.Feature) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Map(java.util.Map) PageRequestHandlerTracker(org.apache.wicket.request.cycle.PageRequestHandlerTracker) FeatureStructure(org.apache.uima.cas.FeatureStructure) JCas(org.apache.uima.jcas.JCas) WebAnnoCasUtil.getAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr) Comparator.comparingInt(java.util.Comparator.comparingInt) Logger(org.slf4j.Logger) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) CasUtil.selectCovered(org.apache.uima.fit.util.CasUtil.selectCovered) List(java.util.List) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) Set(java.util.Set) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) ArrayList(java.util.ArrayList) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Page(org.apache.wicket.Page) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)13 IRequestHandler (org.apache.wicket.request.IRequestHandler)11 Url (org.apache.wicket.request.Url)9 Test (org.junit.Test)9 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 Request (org.apache.wicket.request.Request)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 Page (org.apache.wicket.Page)2 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)1 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1 VCommentType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType)1 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)1 TypeUtil (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil)1 WebAnnoCasUtil.getAddr (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr)1 WebAnnoCasUtil.selectByAddr (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 ArrayList (java.util.ArrayList)1