Search in sources :

Example 1 with CryptoMapper

use of org.apache.wicket.core.request.mapper.CryptoMapper in project wicket by apache.

the class ISecuritySettingsTest method enforceMountsWithCryptoMapper.

/**
 * https://issues.apache.org/jira/browse/WICKET-5560
 */
@Test
public void enforceMountsWithCryptoMapper() {
    WebApplication app = tester.getApplication();
    IRequestHandler handler = new BookmarkablePageRequestHandler(new PageProvider(UnknownPage.class));
    String plainTextNonMountedUrl = tester.urlFor(handler).toString();
    assertTrue("Plain text non mounted url should start with wicket/bookmarkable/: " + plainTextNonMountedUrl, plainTextNonMountedUrl.startsWith("wicket/bookmarkable/"));
    tester.executeUrl(plainTextNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.setRootRequestMapper(new CryptoMapper(app.getRootRequestMapper(), app));
    /*
		 * Execute dummy request to get WicketTester to re-initialise with CryptoMapper in place.
		 */
    tester.executeUrl("");
    String encryptedNonMountedUrl = tester.urlFor(handler).toString();
    assertFalse("Encrypted URL should not start with wicket/bookmarkable/" + encryptedNonMountedUrl, encryptedNonMountedUrl.startsWith("wicket/bookmarkable/"));
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.mountPackage("unknown", UnknownPage.class);
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.getSecuritySettings().setEnforceMounts(true);
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) CryptoMapper(org.apache.wicket.core.request.mapper.CryptoMapper) WebApplication(org.apache.wicket.protocol.http.WebApplication) Test(org.junit.Test)

Example 2 with CryptoMapper

use of org.apache.wicket.core.request.mapper.CryptoMapper in project wicket by apache.

the class CryptedUrlWebRequestCodingStrategyTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            // install crypto mapper to encrypt all application urls
            getSecuritySettings().setCryptFactory(new TestCryptFactory());
            CompoundRequestMapper root = new CompoundRequestMapper();
            root.add(new CryptoMapper(getRootRequestMapper(), this));
            setRootRequestMapper(root);
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) CryptoMapper(org.apache.wicket.core.request.mapper.CryptoMapper) CompoundRequestMapper(org.apache.wicket.request.mapper.CompoundRequestMapper)

Aggregations

CryptoMapper (org.apache.wicket.core.request.mapper.CryptoMapper)2 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 MockApplication (org.apache.wicket.mock.MockApplication)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 CompoundRequestMapper (org.apache.wicket.request.mapper.CompoundRequestMapper)1 Test (org.junit.Test)1