Search in sources :

Example 1 with IUnauthorizedResourceRequestListener

use of org.apache.wicket.authorization.IUnauthorizedResourceRequestListener in project wicket by apache.

the class ResourceAuthorizationTest method rejectWithException.

/**
 * https://issues.apache.org/jira/browse/WICKET-5012
 */
@Test
public void rejectWithException() {
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new RejectingAuthorizationStrategy());
    tester.getApplication().getSecuritySettings().setUnauthorizedResourceRequestListener(new IUnauthorizedResourceRequestListener() {

        @Override
        public void onUnauthorizedRequest(IResource resource, PageParameters parameters) {
            throw new RuntimeException("Not authorized to request: " + resource);
        }
    });
    TestResource resource = new TestResource();
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Not authorized to request: " + resource);
    tester.startResource(resource);
}
Also used : IUnauthorizedResourceRequestListener(org.apache.wicket.authorization.IUnauthorizedResourceRequestListener) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Aggregations

IUnauthorizedResourceRequestListener (org.apache.wicket.authorization.IUnauthorizedResourceRequestListener)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 IResource (org.apache.wicket.request.resource.IResource)1 Test (org.junit.Test)1