List of usage examples for org.apache.wicket RestartResponseAtInterceptPageException RestartResponseAtInterceptPageException
public RestartResponseAtInterceptPageException(Class<? extends Page> interceptPageClass)
From source file:dk.teachus.frontend.pages.HomePage.java
License:Apache License
public HomePage() { Person person = TeachUsSession.get().getPerson(); Class<? extends Page> page = null; if (person != null) { if (person instanceof Admin) { page = TeachersPage.class; } else if (person instanceof Teacher) { page = PupilsPage.class; } else if (person instanceof Pupil) { page = PupilCalendarPage.class; }// w w w .j av a 2 s. com } else { page = InfoPage.class; } throw new RestartResponseAtInterceptPageException(page); }
From source file:dk.teachus.frontend.pages.PaymentPage.java
License:Apache License
private void init() { List<FunctionItem> functions = new ArrayList<FunctionItem>(); if (TeachUsSession.get().getUserLevel() == UserLevel.TEACHER) { functions.add(new PaidFunction()); }//from w w w . j a v a 2 s .c o m functions.add(new CancelPubilBookingFunction() { private static final long serialVersionUID = 1L; @Override protected void onBookingCancelled() { getRequestCycle().setResponsePage(PaymentPage.class); } }); List<IColumn> columns = new ArrayList<IColumn>(); columns.add(new PropertyColumn(new Model(TeachUsSession.get().getString("General.pupil")), "pupil.name", //$NON-NLS-1$//$NON-NLS-2$ "pupil.name")); columns.add(new RendererPropertyColumn(new Model(TeachUsSession.get().getString("General.date")), "date", //$NON-NLS-1$//$NON-NLS-2$ "date", new DateChoiceRenderer())); columns.add(new RendererPropertyColumn(new Model(TeachUsSession.get().getString("General.time")), "date", //$NON-NLS-1$//$NON-NLS-2$ new TimeChoiceRenderer())); columns.add(new RendererPropertyColumn(new Model(TeachUsSession.get().getString("General.price")), //$NON-NLS-1$ "period.price", "period.price", new CurrencyChoiceRenderer())); //$NON-NLS-1$ columns.add(new FunctionsColumn(new Model(TeachUsSession.get().getString("General.functions")), functions)); IModel bookingsModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; @Override protected Object load() { BookingDAO bookingDAO = TeachUsApplication.get().getBookingDAO(); List<PupilBooking> pupilBookings = null; if (TeachUsSession.get().getPerson() instanceof Pupil) { pupilBookings = bookingDAO.getUnpaidBookings((Pupil) TeachUsSession.get().getPerson()); } else if (TeachUsSession.get().getPerson() instanceof Teacher) { pupilBookings = bookingDAO.getUnpaidBookings((Teacher) TeachUsSession.get().getPerson()); } else { throw new RestartResponseAtInterceptPageException(Application.get().getHomePage()); } return pupilBookings; } }; add(new ListPanel("list", columns, new PaymentDataProvider(bookingsModel))); }
From source file:dk.teachus.frontend.pages.SignOutPage.java
License:Apache License
public SignOutPage() { super(UserLevel.PUPIL); throw new RestartResponseAtInterceptPageException(SignedOutPage.class); }
From source file:dk.teachus.frontend.pages.UnAuthenticatedBasePage.java
License:Apache License
private void signin() { TeachUsSession teachUsSession = TeachUsSession.get(); teachUsSession.signIn(user.getUsername(), user.getPassword()); if (teachUsSession.isAuthenticated()) { if (user.isRemember()) { CookieDefaults settings = new CookieDefaults(); // 14 days settings.setMaxAge(60 * 60 * 24 * 14); CookieUtils cookieUtils = new CookieUtils(settings); cookieUtils.save("username", user.getUsername()); cookieUtils.save("password", user.getPassword()); }//from ww w . j ava 2 s.c o m if (continueToOriginalDestination() == false) { throw new RestartResponseAtInterceptPageException(Application.get().getHomePage()); } } }
From source file:eu.uqasar.auth.strategies.UQasarRedirectWithoutLoginStrategy.java
License:Apache License
@Override public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) { // if it's not a wicket page --> allow if (!Page.class.isAssignableFrom(componentClass)) { return true; }//from w w w. j a va2 s . co m // if it's a page that does not require authentication --> allow for (Class<? extends WebPage> clazz : PAGES_WO_AUTH_REQ) { if (clazz.isAssignableFrom(componentClass)) { return true; } } // if it's any other wicket page and user is not logged in --> // redirect to login page if (!((UQSession) Session.get()).isAuthenticated()) { throw new RestartResponseAtInterceptPageException(LoginPage.class); } return true; }
From source file:fiftyfive.wicket.shiro.markup.LoginLink.java
License:Apache License
/** * If a specific destination page was specified in the constructor, throw * {@link RestartResponseAtInterceptPageException} to redirect to the login page, after * which the flow will continue to that destination. Otherwise simply navigate to the login * and follow the standard login-to-home page flow. */// w w w.j av a 2s. co m public void onClick() { // The way RestartResponseAtInterceptPageException works, after the // user successfully authenticates she will be redirected back to this // onClick() handler to continue the flow. Test whether we are in that // continuation be looking at the authenticated status. if (!SecurityUtils.getSubject().isAuthenticated()) { // User hasn't logged in yet. Send to login page. if (this.destinationPage != null) { throw new RestartResponseAtInterceptPageException(getLoginPage()); } else { setResponsePage(getLoginPage()); } } else { // User has completed login. Send to destination or home page. if (this.destinationPage != null) { setResponsePage(this.destinationPage, this.destinationParams); } else { setResponsePage(getApplication().getHomePage()); } } }
From source file:fiftyfive.wicket.shiro.ShiroWicketPlugin.java
License:Apache License
/** * React to an uncaught Exception by redirecting the browser to * the unauthorized page or login page if appropriate. This method will automatically be * called by Wicket if this plugin was installed by the standard {@link #install install()} * mechanism, via the {@link IRequestCycleListener} system. * This allows uncaught Shiro exceptions thrown by the backend to be * handled gracefully by the Wicket layer. * <p>//from w ww . j a v a 2 s.c o m * If the exception is a Shiro {@link AuthorizationException}, redirect * to the unauthorized page or login page depending on the type of error. * If the exception is not a Shiro {@link AuthorizationException} * return {@code null}. * * @param cycle The current request cycle, as provided by Wicket. * * @param error The exception to handle. If it is not a subclass of * Shiro's {@link AuthorizationException}, this method will * not have any effect. * * @return A {@link RenderPageRequestHandler} redirect to the login * page if the error is due to the user being * <em>unauthenticated</em>; * {@link RenderPageRequestHandler} to render the unauthorized page * if the error is due to the user being * <em>unauthorized</em>. */ @Override public IRequestHandler onException(RequestCycle cycle, Exception error) { Class<? extends Page> respondWithPage = null; RedirectPolicy redirectPolicy = RedirectPolicy.NEVER_REDIRECT; if (error instanceof AuthorizationException) { AuthorizationException ae = (AuthorizationException) error; if (authenticationNeeded(ae)) { if (loginPage != null) { onLoginRequired(); // Create a RestartResponseAtInterceptPageException to set the intercept, // even though we don't throw the exception. (The magic happens in the // RestartResponseAtInterceptPageException constructor.) new RestartResponseAtInterceptPageException(loginPage); respondWithPage = loginPage; redirectPolicy = RedirectPolicy.ALWAYS_REDIRECT; } } else { onUnauthorized(); if (this.unauthorizedRedirect || (cycle.getRequest() instanceof WebRequest && ((WebRequest) cycle.getRequest()).isAjax())) { redirectPolicy = RedirectPolicy.ALWAYS_REDIRECT; } respondWithPage = getUnauthorizedPage(); } } if (respondWithPage != null) { return new RenderPageRequestHandler(new PageProvider(respondWithPage), redirectPolicy); } return null; }
From source file:gr.abiss.calipso.wicket.CalipsoApplication.java
License:Open Source License
@Override public void init() { super.init(); // DEVELOPMENT or DEPLOYMENT RuntimeConfigurationType configurationType = this.getConfigurationType(); if (RuntimeConfigurationType.DEVELOPMENT.equals(configurationType)) { logger.info("You are in DEVELOPMENT mode"); // getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND); // getDebugSettings().setComponentUseCheck(true); getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(true); // getMarkupSettings().setStripWicketTags(false); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_EXCEPTION_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(true); } else if (RuntimeConfigurationType.DEPLOYMENT.equals(configurationType)) { getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(false); // getMarkupSettings().setStripWicketTags(true); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(false); }//from w w w . j a v a 2 s . co m // initialize velocity try { Velocity.init(); if (logger.isInfoEnabled()) { logger.info("Initialized Velocity engine"); } } catch (Exception e) { // TODO Auto-generated catch block logger.error("Failed to initialize velocity engine", e); } // Set custom page for internal errors getApplicationSettings().setInternalErrorPage(CalipsoErrorPage.class); // don't break down on missing resources getResourceSettings().setThrowExceptionOnMissingResource(false); // Redirect to PageExpiredError Page if current page is expired getApplicationSettings().setPageExpiredErrorPage(CalipsoPageExpiredErrorPage.class); // get hold of spring managed service layer (see BasePage, BasePanel etc // for how it is used) ServletContext sc = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); calipsoService = (CalipsoService) applicationContext.getBean("calipsoService"); calipsoPropertiesEditor = new CalipsoPropertiesEditor(); // check if acegi-cas authentication is being used, get reference to // object to be used // by wicket authentication to redirect to right pages for login / // logout try { calipsoCasProxyTicketValidator = (CalipsoCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info("casProxyTicketValidator retrieved from application context: " + calipsoCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.info( "casProxyTicketValidator not found in application context, CAS single-sign-on is not being used"); } // delegate wicket i18n support to spring i18n getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } }); // add DB i18n resources getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { locale = component == null ? Session.get().getLocale() : component.getLocale(); if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } }); // cache resources. resource cache is cleared when creating/updating a space getResourceSettings().getLocalizer().setEnableCache(true); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { @Override public boolean isActionAuthorized(Component c, Action a) { return true; } @Override public boolean isInstantiationAuthorized(Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (((CalipsoSession) Session.get()).isAuthenticated()) { return true; } if (calipsoCasProxyTicketValidator != null) { // attempt CAS authentication // ========================== // logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { // logger.debug("security context contains CAS authentication, initializing session"); ((CalipsoSession) Session.get()).setUser((User) authentication.getPrincipal()); return true; } } // attempt remember-me auto login // ========================== if (attemptRememberMeAutoLogin()) { return true; } // attempt *anonymous* guest access if there are // spaces that allow it if (((CalipsoSession) Session.get()).getUser() == null) { List<Space> anonymousSpaces = getCalipso().findSpacesWhereAnonymousAllowed(); if (anonymousSpaces.size() > 0) { // logger.debug("Found "+anonymousSpaces.size() // + // " anonymousSpaces allowing ANONYMOUS access, initializing anonymous user"); User guestUser = new User();//getCalipso().loadUser(2); guestUser.setLoginName("guest"); guestUser.setName("Anonymous"); guestUser.setLastname("Guest"); guestUser.setLocale(Session.get().getLocale().getLanguage()); getCalipso().initImplicitRoles(guestUser, anonymousSpaces, RoleType.ANONYMOUS); // store user in session ((CalipsoSession) Session.get()).setUser(guestUser); return true; } else { if (logger.isDebugEnabled()) { // logger.debug("Found no public spaces."); } } } // allow registration if (clazz.equals(RegisterUserFormPage.class)) { return true; } // not authenticated, go to login page // logger.debug("not authenticated, forcing login, page requested was " // + clazz.getName()); if (calipsoCasProxyTicketValidator != null) { String serviceUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // .getServiceProperties().getService(); String loginUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // logger.debug("cas authentication: service URL: " // + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; // logger.debug("attempting to redirect to: " + // redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); // TODO: create friendly URLs for all created pages // friendly URLs for selected pages if (calipsoCasProxyTicketValidator != null) { mountPage("/login", CasLoginPage.class); } else { mountPage("/login", LoginPage.class); } mountPage("/register", RegisterAnonymousUserFormPage.class); mountPage("/logout", LogoutPage.class); mountPage("/svn", SvnStatsPage.class); mountPage("/test", TestPage.class); mountPage("/casError", CasLoginErrorPage.class); mountPage("/item/", ItemViewPage.class); mountPage("/item/${itemId}", ItemViewPage.class); mountPage("/itemreport/", ItemTemplateViewPage.class); mountPage("/newItem/${spaceCode}", NewItemPage.class); // MixedParamUrlCodingStrategy newItemUrls = new MixedParamUrlCodingStrategy( // "/newItem", // NewItemPage.class, // new String[]{"spaceCode"} // ); // mount(newItemUrls); //fix for tinyMCE bug, see https://github.com/wicketstuff/core/issues/113 SecurePackageResourceGuard guard = (SecurePackageResourceGuard) getResourceSettings() .getPackageResourceGuard(); guard.addPattern("+*.htm"); this.getRequestCycleSettings().setTimeout(Duration.minutes(6)); this.getPageSettings().setVersionPagesByDefault(true); this.getExceptionSettings().setThreadDumpStrategy(ThreadDumpStrategy.THREAD_HOLDING_LOCK); }
From source file:gr.abiss.calipso.wicket.ItemViewPanel.java
License:Open Source License
/** * //from ww w . ja va 2 s .co m * @param tmpl * @param previewHistory */ private void addComponents(ItemRenderingTemplate tmpl, History previewHistory, User user) { final ItemSearch itemSearch = getCurrentItemSearch(); add(new ItemRelatePanel("relate", true)); boolean isRelate = itemSearch != null && itemSearch.getRelatingItemRefId() != null; // ensure user has appropriate rights to view the Item if (item != null && !user.getSpaces().contains(item.getSpace())) { logger.debug("user is not allocated to space"); logger.debug("user.getSpaces(): " + user.getSpaces()); logger.debug("item.getSpace(): " + item.getSpace()); throw new RestartResponseAtInterceptPageException(ErrorPage.class); } addVelocityTemplatePanel(tmpl, item); // hide overview? if (tmpl != null && tmpl.getHideOverview().booleanValue()) { add(new EmptyPanel("itemView").setRenderBodyOnly(true)); } else { add(new ItemView("itemView", getBreadCrumbModel(), tmpl, item, isRelate || user.getId() == 0) .setRenderBodyOnly(true)); } // // WebMarkupContainer addNewRecordContainer = new WebMarkupContainer("addNewRecord"); // add(addNewRecordContainer); // we are giving guest normal workflow roles, although we may want to // restrict in post-only if (/*user.isGuestForSpace(item.getSpace()) || */isRelate) { add(new WebMarkupContainer("addNewRecord").setVisible(false)); } else { // edit if (previewHistory != null) { add(new ItemViewFormPanel("addNewRecord", getBreadCrumbModel(), item, itemSearch, previewHistory)); } else { // new add(new ItemViewFormPanel("addNewRecord", getBreadCrumbModel(), item, itemSearch)); } } // back link ========================================================== //we add it here because we have addNewRecordContainer and the BackLinkPanel //from BasePanel won't work //addNewRecordContainer.add(getBackLinkPanel()); }
From source file:gr.abiss.calipso.wicket.NewItemPage.java
License:Open Source License
public NewItemPage(PageParameters parameters) { //breadcrumb navigation. stays static CalipsoBreadCrumbBar breadCrumbBar = new CalipsoBreadCrumbBar("breadCrumbBar", this); add(breadCrumbBar);/*from ww w .j a va 2 s. c o m*/ // figure out space String spaceCode = parameters.get("spaceCode").toString(); Space space = getCalipso().loadSpace(spaceCode); // can the user create an item in this space? if (space != null && getPrincipal().isAllowedToCreateNewItem(space)) { // new item form panel this.setCurrentSpace(space); ItemFormPanel itemFormPanel = new ItemFormPanel("panel", breadCrumbBar); add(itemFormPanel); breadCrumbBar.setActive(itemFormPanel); } else { // if not allowed, send to login throw new RestartResponseAtInterceptPageException(LoginPage.class); } this.setVersioned(true); }