Example usage for org.apache.wicket RestartResponseAtInterceptPageException RestartResponseAtInterceptPageException

List of usage examples for org.apache.wicket RestartResponseAtInterceptPageException RestartResponseAtInterceptPageException

Introduction

In this page you can find the example usage for org.apache.wicket RestartResponseAtInterceptPageException RestartResponseAtInterceptPageException.

Prototype

public RestartResponseAtInterceptPageException(Class<? extends Page> interceptPageClass) 

Source Link

Document

Redirects to the specified intercept page, this will result in a bookmarkable redirect.

Usage

From source file:main.java.info.jtrac.wicket.ItemViewPage.java

License:Apache License

private void addComponents(final Item item) {
    final ItemSearch itemSearch = getCurrentItemSearch();
    add(new ItemRelatePanel("relate", true));
    Link link = new Link("back") {
        public void onClick() {
            itemSearch.setSelectedItemId(item.getId());
            if (itemSearch.getRefId() != null) {
                // user had entered item id directly, go back to search page
                setResponsePage(new ItemSearchFormPage(itemSearch));
            } else {
                setResponsePage(ItemListPage.class);
            }//ww  w  . j av a2  s  .  c o  m
        }
    };
    if (itemSearch == null) {
        link.setVisible(false);
    }

    add(link);

    boolean isRelate = itemSearch != null && itemSearch.getRelatingItemRefId() != null;

    User user = getPrincipal();

    if (!user.getSpaces().contains(item.getSpace())) {
        logger.debug("user is not allocated to space");
        throw new RestartResponseAtInterceptPageException(ErrorPage.class);
    }

    add(new Link("edit") {
        public void onClick() {
            setResponsePage(new ItemFormPage(item.getId()));
        }
    }.setVisible(user.isAdminForAllSpaces()));

    add(new ItemViewPanel("itemViewPanel", item, isRelate || user.getId() == 0));

    if (user.isGuestForSpace(item.getSpace()) || isRelate) {
        add(new WebMarkupContainer("itemViewFormPanel").setVisible(false));
    } else {
        add(new ItemViewFormPanel("itemViewFormPanel", item, itemSearch));
    }
}

From source file:main.java.info.jtrac.wicket.JtracApplication.java

License:Apache License

@Override
public void init() {

    super.init();

    // get hold of spring managed service layer (see BasePage, BasePanel etc for how it is used)
    ServletContext sc = getServletContext();
    //        applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc);        
    jtrac = (Jtrac) applicationContext.getBean("jtrac");

    // 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 {// w ww.ja  va 2 s  .co m
        jtracCasProxyTicketValidator = (JtracCasProxyTicketValidator) applicationContext
                .getBean("casProxyTicketValidator");
        logger.info(
                "casProxyTicketValidator retrieved from application context: " + jtracCasProxyTicketValidator);
    } 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().addStringResourceLoader(new IStringResourceLoader() {
        public String loadStringResource(Class clazz, String key, Locale locale, String style) {
            try {
                return applicationContext.getMessage(key, null, locale);
            } catch (Exception e) {
                // have to return null so that wicket can try to resolve again
                // e.g. without prefixing component id etc.
                if (logger.isDebugEnabled()) {
                    logger.debug("i18n failed for key: '" + key + "', Class: " + clazz + ", Style: " + style
                            + ", Exception: " + e);
                }
                return null;
            }
        }

        public String loadStringResource(Component component, String key) {
            Class clazz = component == null ? null : component.getClass();
            Locale locale = component == null ? Session.get().getLocale() : component.getLocale();
            return loadStringResource(clazz, key, locale, null);
        }
    });

    getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() {
        public boolean isActionAuthorized(Component c, Action a) {
            return true;
        }

        public boolean isInstantiationAuthorized(Class clazz) {
            if (BasePage.class.isAssignableFrom(clazz)) {
                if (((JtracSession) Session.get()).isAuthenticated()) {
                    return true;
                }
                if (jtracCasProxyTicketValidator != 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");
                        ((JtracSession) Session.get()).setUser((User) authentication.getPrincipal());
                        return true;
                    }
                }
                // attempt remember-me auto login ==========================
                if (attemptRememberMeAutoLogin()) {
                    return true;
                }
                // attempt guest access if there are "public" spaces =======
                List<Space> spaces = getJtrac().findSpacesWhereGuestAllowed();
                if (spaces.size() > 0) {
                    logger.debug(spaces.size() + " public space(s) available, initializing guest user");
                    User guestUser = new User();
                    guestUser.setLoginName("guest");
                    guestUser.setName("Guest");
                    guestUser.addSpaceWithRole(null, "ROLE_GUEST");
                    for (Space space : spaces) {
                        guestUser.addSpaceWithRole(space, "ROLE_GUEST");
                    }
                    ((JtracSession) Session.get()).setUser(guestUser);
                    // and proceed
                    return true;
                }
                // not authenticated, go to login page
                logger.debug("not authenticated, forcing login, page requested was " + clazz.getName());
                if (jtracCasProxyTicketValidator != null) {
                    String serviceUrl = jtracCasProxyTicketValidator.getServiceProperties().getService();
                    String loginUrl = jtracCasProxyTicketValidator.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;
        }
    });

    // friendly urls for selected pages
    if (jtracCasProxyTicketValidator != null) {
        mountBookmarkablePage("/login", CasLoginPage.class);
    } else {
        mountBookmarkablePage("/login", LoginPage.class);
    }
    mountBookmarkablePage("/logout", LogoutPage.class);
    mountBookmarkablePage("/svn", SvnStatsPage.class);
    mountBookmarkablePage("/test", TestPage.class);
    mountBookmarkablePage("/casError", CasLoginErrorPage.class);
    // bookmarkable url for viewing items
    mount(new IndexedParamUrlCodingStrategy("/item", ItemViewPage.class));
}

From source file:name.martingeisse.admin.application.wicket.LoginRequestCycleListener.java

License:Open Source License

@Override
public void onRequestHandlerResolved(final RequestCycle cycle, final IRequestHandler handler) {
    logger.trace("LoginRequestCycleListener: checking...");
    ParameterUtil.ensureNotNull(cycle, "cycle");
    ParameterUtil.ensureNotNull(handler, "handler");

    // this handler has no business with the request if he user is logged in
    if (SecurityUtil.isLoggedIn()) {
        logger.trace("user is logged in -> ok");
        return;//from  ww  w .jav a  2  s . co m
    }

    // decide by handler type whether the request is allowed, blocked or redirected
    logger.trace("user is not logged in -> checking handler...");
    if (handler instanceof IPageClassRequestHandler) {

        // handler for a page -- allowed if it is the login page
        final IPageClassRequestHandler pageClassRequestHandler = (IPageClassRequestHandler) handler;
        final Class<?> pageClass = pageClassRequestHandler.getPageClass();
        logger.trace("handler is for page: " + pageClass);
        final Class<? extends Page> loginPageClass = SecurityConfiguration.getInstanceSafe()
                .getLoginPageClass();
        ReturnValueUtil.nullMeansMissing(loginPageClass, "security configuration: login page class");
        if (pageClass != loginPageClass) {
            logger.trace("sending intercept-redirect to the login page");
            throw new RestartResponseAtInterceptPageException(loginPageClass);
        }
        logger.trace("accepted.");
        return;

    } else if (handler instanceof ResourceReferenceRequestHandler || handler instanceof ResourceRequestHandler
            || handler instanceof ResourceStreamRequestHandler) {

        // accessing resources is allowed
        logger.trace("handler is for a resource -> ok");
        return;

    } else if (handler.getClass().getCanonicalName()
            .equals("org.apache.wicket.request.flow.ResetResponseException.ResponseResettingDecorator")) {

        // needed for ResetResponseException to work
        logger.trace("handler is from a ResetResponseException");
        return;

    } else if (handler.getClass().getCanonicalName()
            .equals("org.apache.wicket.protocol.https.SwitchProtocolRequestHandler")) {

        // needed for automatically switching to HTTPS
        logger.trace("handler is a SwitchProtocolRequestHandler");
        return;

    } else if (handler instanceof BufferedResponseRequestHandler) {

        // needed to render stateful login pages
        logger.trace("handler is a BufferedResponseRequestHandler");
        return;

    }

    // any other type of request handler is blocked
    logger.trace("blocking handler: " + handler + " / " + handler.getClass().getCanonicalName());
    throw new AbortWithHttpErrorCodeException(403);

}

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 w w.ja  va 2s . 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.lunikon.rethul.web.auth.RethulPageAuthorizationStrategy.java

License:Open Source License

/**
 * {@inheritDoc}//  w ww . ja va 2 s.c om
 */
@Override
protected <T extends Page> boolean isPageAuthorized(Class<T> pageClass) {
    if (instanceOf(pageClass, IAuthenticatedPage.class)) {
        RethulSession session = RethulSession.get();
        if (!session.isAuthenticated())
            throw new RestartResponseAtInterceptPageException(LoginPage.class);
    }

    return true;
}

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   ww  w  . j a v a 2  s. co 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:nl.knaw.dans.dccd.web.base.BasePage.java

License:Apache License

protected void redirectIfNotLoggedIn() {
    logger.debug("Check if we need to Redirecting to login page");

    if (!isLoggedIn()) {
        logger.debug("User not logged in; Redirecting to login page");

        // redirect to login page and enable the login to return here
        throw new RestartResponseAtInterceptPageException(LoginPage.class);
    }/*from  www  . j  a v a  2s .  c o m*/
}

From source file:nl.ru.cmbi.vase.web.page.AlignmentPage.java

License:Apache License

public AlignmentPage(final PageParameters parameters) {

    log.info("start AlignmentPage with parameters " + parameters.toString());

    StringValue structureIDString = parameters.get(0), chainIDString = parameters.get(1);

    if (structureIDString == null || structureIDString.isNull() || structureIDString.isEmpty()) {

        throw new RestartResponseAtInterceptPageException(new ErrorPage("structure id missing"));

    } else {/*from w w w .  j  av  a 2 s. c o  m*/

        structureID = structureIDString.toString().toLowerCase();

        if (chainIDString != null && !chainIDString.isNull() && !chainIDString.isEmpty()) {

            chainID = chainIDString.toChar();
        }

        try {
            File xmlFile = new File(Config.getCacheDir(), structureID + ".xml"),
                    gzXmlFile = new File(Config.getCacheDir(), structureID + ".xml.gz");
            if (xmlFile.isFile()) {

                VASEDataObject data = VASEXMLParser.parse(new FileInputStream(xmlFile));

                this.initPageWith(data);
            } else if (gzXmlFile.isFile()) {

                VASEDataObject data = VASEXMLParser.parse(new GZIPInputStream(new FileInputStream(xmlFile)));

                this.initPageWith(data);
            } else {

                if (Config.isXmlOnly()) {

                    throw new RestartResponseAtInterceptPageException(new ErrorPage(
                            "VASE is running in xml-only mode, so only xml-entries can be accessed. (see homepage)"));
                }

                InputStream pdbIn = Utils.getPdbInputStream(structureID);
                if (pdbIn == null) {

                    throw new RestartResponseAtInterceptPageException(
                            new ErrorPage("Unable to resolve PDB URL for: " + structureID));
                }

                InputStream stockholmInputStream = Utils.getStockholmInputStream(structureID);
                if (stockholmInputStream == null) {

                    throw new RestartResponseAtInterceptPageException(
                            new ErrorPage("No alignment data for: " + structureID));
                }

                Set<Character> stockholmChainIDs = StockholmParser.listChainsInStockholm(stockholmInputStream);

                if (chainID == null) {

                    if (stockholmChainIDs.size() == 1) {

                        // no chain id needs to be given, since there's only one

                        chainID = stockholmChainIDs.iterator().next();
                    } else {

                        // Redirect to a page with chain selection

                        PageParameters params = new PageParameters();
                        params.add(SearchResultsPage.parameterName, structureID);

                        this.setResponsePage(SearchResultsPage.class, params);
                        return;
                    }
                } else if (!stockholmChainIDs.contains(chainID)) {

                    throw new RestartResponseAtInterceptPageException(
                            new ErrorPage("No such chain in " + structureID + ": " + chainID));
                }

                stockholmInputStream = Utils.getStockholmInputStream(structureID);

                VASEDataObject data = StockholmParser.parseStockHolm(stockholmInputStream, pdbIn, structureID,
                        chainID);
                if (data == null)
                    log.error("data is null");

                this.initPageWith(data);
            }

        } catch (RestartResponseAtInterceptPageException e) {

            //just rethrow it
            throw e;

        } catch (Exception e) { // any other type of exception

            log.error("Error getting alignments for " + structureIDString + " : " + e.getMessage(), e);

            throw new RestartResponseAtInterceptPageException(
                    new ErrorPage("Error getting alignments for " + structureIDString + " : " + e.toString()));
        }
    }
}

From source file:ontopoly.components.UserPanel.java

License:Apache License

public UserPanel(String id, Class<? extends Page> logoutPageClass) {
    super(id);//from w  w w . java 2 s . co  m
    add(new Label("fullname", new PropertyModel<Object>(this, "session.user.fullname")));
    PageParameters parameters = new PageParameters();
    parameters.add(SignOutPage.REDIRECTPAGE_PARAM, logoutPageClass.getName());
    add(new BookmarkablePageLink<Page>("signout", SignOutPage.class, parameters) {
        @Override
        public boolean isVisible() {
            OntopolySession session = (OntopolySession) Session.get();
            return session.isAuthenticated();
        }

        @Override
        public boolean isEnabled() {
            OntopolySession session = (OntopolySession) Session.get();
            return !session.isAutoLogin();
        }
    });
    add(new Link<Object>("signin") {
        @Override
        public void onClick() {
            throw new RestartResponseAtInterceptPageException(SignInPage.class);
        }

        @Override
        public boolean isVisible() {
            OntopolySession session = (OntopolySession) Session.get();
            return !session.isAuthenticated();
        }
    });
}

From source file:org.antbear.jee.wicket.guestbook.web.ViewGuestbook.java

License:Apache License

public ViewGuestbook(final PageParameters parameters) {
    super(parameters);

    if (null == (this.guestbookId = parameters.getAsLong(PAGE_PARAM_GUESTBOOK_ID)))
        throw new RestartResponseAtInterceptPageException(HomePage.class);
}