use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class WebPageRendererTest method before.
/**
* Common setup
*/
@Before
public void before() {
provider = mock(IPageProvider.class);
page = mock(IRequestablePage.class);
when(provider.getPageInstance()).thenReturn(page);
handler = new RenderPageRequestHandler(provider);
requestCycle = mock(RequestCycle.class);
urlRenderer = mock(UrlRenderer.class);
when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
request = mock(WebRequest.class);
when(requestCycle.getRequest()).thenReturn(request);
response = mock(WebResponse.class);
when(requestCycle.getResponse()).thenReturn(response);
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket-orientdb by OrienteerBAP.
the class OrientDefaultExceptionsHandlingListener method onException.
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
Throwable th = null;
if ((th = Exceptions.findCause(ex, OSecurityException.class)) != null || (th = Exceptions.findCause(ex, OValidationException.class)) != null || (th = Exceptions.findCause(ex, OSchemaException.class)) != null || (th = Exceptions.findCause(ex, IllegalStateException.class)) != null && Exceptions.findCause(ex, WicketRuntimeException.class) == null) {
Page page = extractCurrentPage(false);
if (page == null) {
return th instanceof OSecurityException ? new UnauthorizedInstantiationHandler(extractCurrentPage(true)) : null;
}
OrientDbWebSession.get().error(th.getMessage());
return new RenderPageRequestHandler(new PageProvider(page), RenderPageRequestHandler.RedirectPolicy.ALWAYS_REDIRECT);
} else if ((th = Exceptions.findCause(ex, UnauthorizedActionException.class)) != null) {
final UnauthorizedActionException unauthorizedActionException = (UnauthorizedActionException) th;
return new UnauthorizedInstantiationHandler(unauthorizedActionException.getComponent());
} else {
return null;
}
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class PageInstanceMapper method mapRequest.
/**
* @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
*/
@Override
public IRequestHandler mapRequest(Request request) {
if (matches(request)) {
Url url = request.getUrl();
PageComponentInfo info = getPageComponentInfo(url);
if (info != null && info.getPageInfo().getPageId() != null) {
Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
if (info.getComponentInfo() == null) {
PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
provider.setPageSource(getContext());
// render page
return new RenderPageRequestHandler(provider);
} else {
ComponentInfo componentInfo = info.getComponentInfo();
PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
provider.setPageSource(getContext());
return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
}
}
}
return null;
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project hale by halestudio.
the class BaseWebApplication method init.
@Override
public void init() {
super.init();
BootstrapSettings settings = new BootstrapSettings();
final ThemeProvider themeProvider = new BootswatchThemeProvider() {
{
add(new MetroTheme());
add(new GoogleTheme());
add(new WicketTheme());
add(new Bootstrap3Theme());
defaultTheme("bootstrap-responsive");
// defaultTheme("bootstrap");
}
};
settings.setThemeProvider(themeProvider);
Bootstrap.install(this, settings);
BootstrapLess.install(this);
configureResourceBundles();
IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
if (packageResourceGuard instanceof SecurePackageResourceGuard) {
SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
}
// enforce mounts so security interceptors based on URLs can't be fooled
getSecuritySettings().setEnforceMounts(true);
getSecuritySettings().setAuthorizationStrategy(new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {
@Override
protected boolean isAuthorized() {
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext != null) {
Authentication authentication = securityContext.getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
for (GrantedAuthority authority : authentication.getAuthorities()) {
if (authority.getAuthority().equals(UserConstants.ROLE_USER) || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {
// allow access only for users/admins
return true;
}
}
}
}
return false;
}
});
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
}
});
// add login page to every application based on this one (if enabled)
Class<? extends BasePage> loginClass = getLoginPageClass();
if (loginClass != null) {
// login page
mountPage("/login", loginClass);
// user settings
mountPage("/settings", UserSettingsPage.class);
// about
mountPage("/about", AboutPage.class);
// contact
mountPage("/contact", ContactPage.class);
if (OpenIdLoginPage.class.equals(loginClass)) {
// for OpenID auth also add page for new users
mountPage("/new", NewUserPage.class);
}
}
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project syncope by apache.
the class SyncopeConsoleRequestCycleListener method onException.
@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
LOG.error("Exception found", e);
PageParameters errorParameters = new PageParameters();
IRequestablePage errorPage = null;
if (instanceOf(e, UnauthorizedInstantiationException.class) != null) {
errorParameters.add("errorMessage", MISSING_AUTHORIZATION);
errorPage = new Login(errorParameters);
} else if (instanceOf(e, AccessControlException.class) != null) {
if (instanceOf(e, AccessControlException.class).getMessage().contains("expired")) {
errorParameters.add("errorMessage", PAGE_EXPIRED);
} else {
errorParameters.add("errorMessage", MISSING_AUTHORIZATION_CORE);
}
errorPage = new Login(errorParameters);
} else if (instanceOf(e, PageExpiredException.class) != null || !SyncopeConsoleSession.get().isSignedIn()) {
errorParameters.add("errorMessage", PAGE_EXPIRED);
errorPage = new Login(errorParameters);
} else if (instanceOf(e, BadRequestException.class) != null || instanceOf(e, WebServiceException.class) != null || instanceOf(e, SyncopeClientException.class) != null) {
errorParameters.add("errorMessage", REST);
errorPage = new Login(errorParameters);
} else {
Throwable cause = instanceOf(e, ForbiddenException.class);
if (cause == null) {
// redirect to default Wicket error page
errorPage = new ExceptionErrorPage(e, null);
} else {
errorParameters.add("errorMessage", cause.getMessage());
errorPage = new Login(errorParameters);
}
}
if (errorPage instanceof Login) {
try {
SyncopeConsoleSession.get().cleanup();
SyncopeConsoleSession.get().invalidateNow();
} catch (Throwable t) {
// ignore
LOG.debug("Unexpected error while forcing logout after error", t);
}
}
return new RenderPageRequestHandler(new PageProvider(errorPage));
}
Aggregations