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));
}
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);
}
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);
}
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);
}
Aggregations