Search in sources :

Example 21 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class AnnotationsRoleAuthorizationStrategyTest method allowsUnprotectedResourceWithRole.

@Test
public void allowsUnprotectedResourceWithRole() throws Exception {
    AnnotationsRoleAuthorizationStrategy strategy = new AnnotationsRoleAuthorizationStrategy(roles("role2"));
    IResource resource = Mockito.mock(UnrestrictedResource.class);
    assertTrue(strategy.isResourceAuthorized(resource, null));
}
Also used : IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Example 22 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class RequestCycleUrlForTest method urlForResourceReferenceWithNonStaticResource.

/**
 * ResourceReference with non-IStaticCacheableResource should not have the jsessionid encoded in the url
 *
 * @throws Exception
 */
@Test
public void urlForResourceReferenceWithNonStaticResource() throws Exception {
    final IResource resource = mock(IResource.class);
    ResourceReference reference = new ResourceReference("dummy") {

        @Override
        public IResource getResource() {
            return resource;
        }
    };
    ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference);
    CharSequence url = requestCycle.urlFor(handler);
    assertEquals("./" + RES_REF_URL + JSESSIONID, url);
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) ResourceReference(org.apache.wicket.request.resource.ResourceReference) IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Example 23 with IResource

use of org.apache.wicket.request.resource.IResource 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)

Example 24 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class WebSocketMessageBroadcastHandler method respond.

@Override
public void respond(IRequestCycle requestCycle) {
    final Application application = Application.get();
    final Runnable action = new Runnable() {

        @Override
        public void run() {
            if (pageId != AbstractWebSocketProcessor.NO_PAGE_ID) {
                Page page = (Page) Session.get().getPageManager().getPage(pageId);
                page.send(application, Broadcast.BREADTH, payload);
            } else {
                ResourceReference reference = new SharedResourceReference(resourceName);
                IResource resource = reference.getResource();
                if (resource instanceof WebSocketResource) {
                    WebSocketResource wsResource = (WebSocketResource) resource;
                    wsResource.onPayload(payload);
                } else {
                    throw new IllegalStateException(String.format("Shared resource with name '%s' is not a %s but %s", resourceName, WebSocketResource.class.getSimpleName(), Classes.name(resource.getClass())));
                }
            }
        }
    };
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    webSocketSettings.getSendPayloadExecutor().run(action);
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) Page(org.apache.wicket.Page) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Application(org.apache.wicket.Application) IResource(org.apache.wicket.request.resource.IResource)

Aggregations

IResource (org.apache.wicket.request.resource.IResource)24 ResourceReference (org.apache.wicket.request.resource.ResourceReference)10 Test (org.junit.Test)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 AjaxDownloadBehavior (org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)4 Application (org.apache.wicket.Application)3 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)3 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)2 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BootstrapSettings (de.agilecoders.wicket.core.settings.BootstrapSettings)1 IBootstrapSettings (de.agilecoders.wicket.core.settings.IBootstrapSettings)1 SingleThemeProvider (de.agilecoders.wicket.core.settings.SingleThemeProvider)1