List of usage examples for org.apache.wicket.authorization UnauthorizedInstantiationException UnauthorizedInstantiationException
public <T extends IRequestableComponent> UnauthorizedInstantiationException(final Class<T> componentClass)
From source file:com.madalla.webapp.authorization.AppAuthorizationStrategy.java
License:Apache License
/** * Construct.//from ww w .ja v a 2 s .co m * * @param signInPageClass * The sign in page class * @param pageAuthorizations * Collection of PageAuthorization that need to be authorized */ public AppAuthorizationStrategy(final Class<? extends Page> signInPageClass, Collection<PageAuthorization> pageAuthorizations) { this.pageAuthorizations = pageAuthorizations; // Handle unauthorized access to pages Application.get().getSecuritySettings() .setUnauthorizedComponentInstantiationListener(new IUnauthorizedComponentInstantiationListener() { public void onUnauthorizedInstantiation(final Component component) { // If there is a sign in page class declared, and the // unauthorized component is a page, but it's not the // sign in page if (component instanceof Page) { // Redirect to page to let the user sign in throw new RestartResponseAtInterceptPageException(signInPageClass); } else { // The component was not a page, so throw exception throw new UnauthorizedInstantiationException(component.getClass()); } } }); }
From source file:com.mastfrog.acteur.wicket.borrowed.SourcesPage.java
License:Apache License
private Class<? extends Page> getPageTargetClass() { if (page == null) { String pageParam = getPageParameters().get(PAGE_CLASS).toOptionalString(); if (pageParam == null) { if (log.isErrorEnabled()) { log.error("key: " + PAGE_CLASS + " is null."); }/* ww w . j a v a 2 s .com*/ getRequestCycle().replaceAllRequestHandlers( new ErrorCodeRequestHandler(404, "Could not find sources for the page you requested")); } else if (!pageParam.startsWith("org.apache.wicket.examples")) { if (log.isErrorEnabled()) { log.error("user is trying to access class: " + pageParam + " which is not in the scope of org.apache.wicket.examples"); } throw new UnauthorizedInstantiationException(getClass()); } page = WicketObjects.resolveClass(pageParam); if (page == null) { getRequestCycle().replaceAllRequestHandlers( new ErrorCodeRequestHandler(404, "Could not find sources for the page you requested")); } } return page; }
From source file:fiftyfive.wicket.shiro.ShiroWicketPlugin.java
License:Apache License
/** * Determine what caused the unauthorized instantiation of the given * component. If access was denied due to being unauthenticated, and * the login page specified in the constructor was not {@code null}, * call {@link #onLoginRequired} and redirect to the login page. * <p>/* ww w . j a v a2 s .co m*/ * Otherwise, access was denied due to authorization failure (e.g. insufficient privileges), * call {@link #onUnauthorized} and render the unauthorized page (which is the home page by * default). * * @param component The component that failed to initialize due to * authorization or authentication failure * * @throws {@link ResetResponseException} to render the login page or unauthorized page * * @throws UnauthorizedInstantiationException the login page * has not been configured (i.e. is {@code null}) */ public void onUnauthorizedInstantiation(Component component) { AuthorizationException cause; RequestCycle rc = RequestCycle.get(); cause = rc.getMetaData(EXCEPTION_KEY); // Show appropriate login or error page if possible IRequestHandler handler = onException(rc, cause); if (handler != null) { throw new ResetResponseException(handler) { }; } // Otherwise bubble up the error UnauthorizedInstantiationException ex; ex = new UnauthorizedInstantiationException(component.getClass()); ex.initCause(cause); throw ex; }
From source file:lt.inventi.wicket.shiro.ShiroWicketPlugin.java
License:Apache License
/** * Determine what caused the unauthorized instantiation of the given * component. If access was denied due to being unauthenticated, and * the login page specified in the constructor was not {@code null}, * call {@link #onLoginRequired} and redirect to the login page. * <p>// w ww. j av a2 s . co m * Otherwise, access was denied due to authorization failure (e.g. insufficient privileges), * call {@link #onUnauthorized} and render the unauthorized page (which is the home page by * default). * * @param component The component that failed to initialize due to * authorization or authentication failure * * @throws {@link ResetResponseException} to render the login page or unauthorized page * * @throws UnauthorizedInstantiationException the login page * has not been configured (i.e. is {@code null}) */ @Override public void onUnauthorizedInstantiation(Component component) { AuthorizationException cause; RequestCycle rc = RequestCycle.get(); cause = rc.getMetaData(EXCEPTION_KEY); // Show appropriate login or error page if possible IRequestHandler handler = onException(rc, cause); if (handler != null) { throw new ResetResponseException(handler) { }; } // Otherwise bubble up the error UnauthorizedInstantiationException ex; ex = new UnauthorizedInstantiationException(component.getClass()); ex.initCause(cause); throw ex; }
From source file:net.databinder.auth.components.DataSignInPageBase.java
License:Open Source License
public DataSignInPageBase(PageParameters params, ReturnPage returnPage) { AuthApplication<T> app = null; try {//w w w . j a v a 2 s . c o m app = ((AuthApplication<T>) Application.get()); } catch (ClassCastException e) { } // make sure the user is not trying to sign in or register with the wrong page if (app == null || !app.getSignInPageClass().isInstance(this)) throw new UnauthorizedInstantiationException(DataSignInPageBase.class); if (params != null) { String username = params.get("username").toString(); String token = params.get("token").toString(); // e-mail auth, for example if (username != null && token != null) { T user = app.getUser(username); if (user != null && app.getToken(user).equals(token)) getAuthSession().signIn(user, true); setResponsePage(((Application) app).getHomePage()); RequestCycle.get() .scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler( new PageProvider(((Application) app).getHomePage(), params), RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT)); return; } } add(new Label("title", new ResourceModel("data.auth.title.sign_in", "Please sign in"))); sourceList = new SourceList(); add(profileSocket = profileSocket("profileSocket", returnPage)); add(new WebMarkupContainer("profileLinkWrapper") { public boolean isVisible() { return profileLink.isEnabled(); } }.add((profileLink = sourceList.new SourceLink("profileLink", profileSocket)) .add(new Label("text", getString("data.auth.register_link", null, "Register now")))) .add(new Label("text", getString("data.auth.pre_register_link", null, "Don't have an account?")))); add(signinSocket = signinSocket("signinSocket", returnPage)); add(new WebMarkupContainer("signinLinkWrapper") { @Override public boolean isVisible() { return signinLink.isEnabled(); } }.add(new Label("text", getString("data.auth.pre_sign_in_link", null, "Already have an account?"))) .add((signinLink = sourceList.new SourceLink("signinLink", signinSocket)) .add(new Label("text", getString("data.auth.sign_in_link", null, "Sign in"))))); signinLink.onClick(); // show sign in first }
From source file:net.databinder.auth.hib.AuthDataApplication.java
License:Open Source License
/** * Sends to sign in page if not signed in, otherwise throws UnauthorizedInstantiationException. *///from w ww.j ava 2 s .c o m public void onUnauthorizedInstantiation(Component component) { if (((AuthSession) Session.get()).isSignedIn()) { throw new UnauthorizedInstantiationException(component.getClass()); } else { throw new RestartResponseAtInterceptPageException(getSignInPageClass()); } }
From source file:net.rrm.ehour.ui.EhourWebApplication.java
License:Open Source License
protected void setupSecurity() { getApplicationSettings().setPageExpiredErrorPage(SessionExpiredPage.class); authorizationStrategy = getAuthorizationStrategy(); getSecuritySettings().setAuthorizationStrategy(authorizationStrategy); getSecuritySettings()//from w w w . j a va2 s. c o m .setUnauthorizedComponentInstantiationListener(new IUnauthorizedComponentInstantiationListener() { public void onUnauthorizedInstantiation(final Component component) { if (component instanceof Page) { throw new RestartResponseAtInterceptPageException(Login.class); } else { throw new UnauthorizedInstantiationException(component.getClass()); } } }); }
From source file:org.apache.syncope.client.console.SyncopeApplication.java
License:Apache License
@Override public void onUnauthorizedInstantiation(final Component component) { SyncopeSession.get().invalidate();//from w w w . ja va 2 s . c o m if (component instanceof Page) { throw new UnauthorizedInstantiationException(component.getClass()); } throw new RestartResponseAtInterceptPageException(Login.class); }
From source file:org.artifactory.webapp.wicket.page.admin.AdminPage.java
License:Open Source License
public AdminPage() { if (authService.isAdmin()) { // for now redirect all valid admin requests to the general configuration tab throw new RestartResponseException(GeneralConfigPage.class); } else if (authService.hasPermission(ArtifactoryPermission.MANAGE)) { throw new RestartResponseException(AclsPage.class); }//from www . ja v a2s .com // In this special condition when no license is installed we allow non-admin to visit the license page addonsWebManager.onNoInstalledLicense(false, new NoInstalledLicenseAction() { @Override public void act() { throw new RestartResponseException(LicensePage.class); } }); // If non of the above is applicable, then the user is unauthorized! throw new UnauthorizedInstantiationException(getClass()); }
From source file:org.artifactory.webapp.wicket.page.config.license.LicensePage.java
License:Open Source License
public LicensePage() { Form form = new SecureForm("form"); add(form);/*from w ww . ja v a 2s . com*/ LicensePanel licensePanel = new LicensePanel("licensePanel"); form.add(licensePanel); form.add(licensePanel.createSaveButton(form)); form.add(createCancelButton()); if (addonsManager.isLicenseInstalled() && !authService.isAdmin()) { throw new UnauthorizedInstantiationException(getClass()); } CookieUtils.setCookie(LicensePage.COOKIE_LICENSE_PAGE_VISITED, "true"); }