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:org.jabylon.rest.ui.security.PermissionBasedAuthorizationStrategy.java

License:Open Source License

@Override
public boolean isActionAuthorized(Component component, Action action) {
    if (component instanceof RestrictedComponent) {
        RestrictedComponent restricted = (RestrictedComponent) component;
        String permission = restricted.getRequiredPermission();
        if (permission == null)
            return true;
        CDOAuthenticatedSession session = (CDOAuthenticatedSession) CDOAuthenticatedSession.get();
        if (session.getUser() == null) {
            User anonymousUser = session.getAnonymousUser();
            if (anonymousUser == null)
                return false;
            boolean allowed = anonymousUser.hasPermission(permission);
            if (allowed)
                return true;
            throw new RestartResponseAtInterceptPageException(LoginPage.class);
        }//w ww.j a v a 2  s.c  o m
        boolean allowed = session.getUser().hasPermission(permission);
        if (allowed)
            return true;
        if (CommonPermissions.isEditRequest(permission))
            throw new UnauthorizedActionException(component, action);
        return false;
    }
    return true;
}

From source file:org.jabylon.rest.ui.wicket.config.AbstractConfigSection.java

License:Open Source License

@Override
public boolean isVisible(IModel<T> input, Preferences config) {
    model = input;//from ww  w  . j  a v  a2  s  .  c om
    CDOAuthenticatedSession session = (CDOAuthenticatedSession) CDOAuthenticatedSession.get();
    User user = session.getUser();
    if (user != null)
        return user.hasPermission(getRequiredPermission());
    else {
        User anonymousUser = session.getAnonymousUser();
        boolean allowed = anonymousUser.hasPermission(getRequiredPermission());
        if (allowed)
            return true;
        throw new RestartResponseAtInterceptPageException(LoginPage.class);
    }
}

From source file:org.jabylon.rest.ui.wicket.config.SettingsPanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public SettingsPanel(String id, IModel<T> model, PageParameters pageParameters) {
    super(id, model);
    EClass eclass = getEClassToCreate(pageParameters);
    if (eclass != null) {
        setModel(new AttachableWritableModel<T>(eclass, getModel()));
    }//  w ww  .  j a  va 2  s  .  c  om

    T modelObject = getModelObject();
    boolean isNew = modelObject.cdoState() == CDOState.NEW || modelObject.cdoState() == CDOState.TRANSIENT;
    final Preferences preferences = isNew ? new AttachablePreferences()
            : new DelegatingPreferences(PreferencesUtil.scopeFor(modelObject));

    final List<ITab> extensions = loadTabExtensions(preferences);

    // submit section

    @SuppressWarnings({ "rawtypes" })
    Form form = new Form("form", getModel()) {

        private static final long serialVersionUID = 1L;
        String oldName;

        @Override
        protected void beforeUpdateFormComponentModels() {
            super.beforeUpdateFormComponentModels();
            IModel model = getModel();
            if (model != null && model.getObject() instanceof Resolvable) {
                //store the original project name in case it gets changed
                Resolvable resolvable = (Resolvable) model.getObject();
                oldName = resolvable.getName();
            }
        }

        @Override
        protected void onSubmit() {
            Preferences prefs = preferences;
            IModel<T> model = SettingsPanel.this.getModel();
            CDOObject object = model.getObject();
            CDOView cdoView;
            if (model instanceof AttachableModel) {
                // it's a new object that needs attaching
                AttachableModel<CDOObject> attachable = (AttachableModel) model;
                attachable.attach();
                CDOObject parent = (CDOObject) attachable.getObject().eContainer();
                cdoView = parent.cdoView();
            } else
                cdoView = object.cdoView();
            if (cdoView instanceof CDOTransaction) {
                CDOTransaction transaction = (CDOTransaction) cdoView;

                if (prefs instanceof AttachablePreferences) {
                    // the prefs are not in the tree yet
                    Preferences targetPrefs = PreferencesUtil.scopeFor(object);
                    try {
                        PreferencesUtil.cloneNode(prefs, targetPrefs);
                        prefs = targetPrefs;
                    } catch (BackingStoreException e) {
                        error("Some settings could not be saved: " + e.getMessage());
                        logger.error("Failed to attach preferences to target path", e);
                    }
                }
                if (oldName != null && !oldName
                        .equals(model.getObject().eGet(PropertiesPackage.Literals.RESOLVABLE__NAME))) {
                    renameResolvable(oldName, model);

                    prefs = PreferencesUtil.renamePreferenceNode(preferences,
                            (String) model.getObject().eGet(PropertiesPackage.Literals.RESOLVABLE__NAME));
                }
                commit(prefs, object, transaction);
                // model.detach();
            } else
                throw new IllegalStateException("not a transaction");
            super.onSubmit();
        }

        protected void commit(final Preferences preferences, CDOObject object, CDOTransaction transaction) {

            for (ConfigSection<?> section : allSections) {
                section.commit(getModel(), preferences);
            }
            try {
                transaction.commit();

                URI uri = resolver.getURI(object);
                setResponsePage(SettingsPage.class, WicketUtil.buildPageParametersFor(uri));

                preferences.flush();
                getSession().success(getString("save.success.feedback.message"));
            } catch (CommitException e) {
                getSession().error(e.getMessage());
                logger.error("failed to commit configuration for " + object, e);
            } catch (BackingStoreException e) {
                getSession().error(e.getMessage());
                logger.error("failed to commit configuration for " + object, e);
            } finally {
                // transaction.close();
            }
        }
    };

    ClientSideTabbedPanel<ITab> tabContainer = new ClientSideTabbedPanel<ITab>("tabs", extensions, false,
            "settings/" + model.getObject().getClass().getSimpleName()) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            List<ITab> tabContents = extensions;
            for (ITab component : tabContents) {
                if (component.isVisible())
                    return visible;
            }
            CDOAuthenticatedSession session = (CDOAuthenticatedSession) CDOAuthenticatedSession.get();
            User user = session.getUser();
            if (user == null || CommonPermissions.USER_ANONYMOUS.equals(user.getName()))
                // user is not logged in, give him the chance
                throw new RestartResponseAtInterceptPageException(LoginPage.class);
            // if no tab is visible, the user has no permission to be here
            throw new UnauthorizedInstantiationException(SettingsPanel.class);
        }

    };
    form.add(tabContainer);
    // form.add(new CustomFeedbackPanel("feedback"));

    Button submitButton = new Button("submit", new StringResourceModel("submit.button.label", this, null));
    form.add(submitButton);
    // Button cancelButton = new Button("cancel-button",
    // Model.of("Cancel"));
    // form.add(cancelButton);

    add(form);

}

From source file:org.obiba.onyx.webapp.OnyxApplication.java

License:Open Source License

public void onUnauthorizedInstantiation(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// ww w .  j  a va 2 s .c  om
    if (component instanceof Page) {
        if (!OnyxAuthenticatedSession.get().isSignedIn()) {
            // Redirect to intercept page to let the user sign in
            throw new RestartResponseAtInterceptPageException(LoginPage.class);
        }
        // User is signed in but doesn't have the proper access rights. Display error and redirect accordingly.
        throw new RestartResponseAtInterceptPageException(AccessDeniedPage.class);

    }
    // The component was not a page, so show an error message in the FeedbackPanel of the page
    component.error("You do not have sufficient privileges to see this component.");
    throw new UnauthorizedInstantiationException(component.getClass());
}

From source file:org.onexus.website.api.WebsiteApplication.java

License:Apache License

@Override
public void restartResponseAtSignInPage() {
    throw new RestartResponseAtInterceptPageException(getSignInPageClass());
}

From source file:org.patientview.radar.web.RadarApplication.java

License:Open Source License

@Override
public void init() {
    super.init();
    // This allows our SpringBean annotations to work
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    // set a security listener for checks on pages and what logins they should go to
    getSecuritySettings()/*www . j a v a2s.c o  m*/
            .setUnauthorizedComponentInstantiationListener(new IUnauthorizedComponentInstantiationListener() {
                public void onUnauthorizedInstantiation(final Component component) {
                    if (component instanceof Page) {
                        if (component instanceof AdminsBasePage) {
                            throw new RestartResponseAtInterceptPageException(AdminsLoginPage.class);
                        } else if (component.getClass() == SrnsPatientPageReadOnly.class) {
                            throw new RestartResponseAtInterceptPageException(PatientsLoginPage.class);
                        }

                        throw new RestartResponseAtInterceptPageException(ProfessionalsLoginPage.class);
                    } else {
                        throw new UnauthorizedInstantiationException(component.getClass());
                    }
                }
            });

    getRequestCycleListeners().add(new AbstractRequestCycleListener() {
        @Override
        public IRequestHandler onException(RequestCycle cycle, Exception ex) {
            return new RenderPageRequestHandler(new PageProvider(new ErrorPage(ex)));
        }
    });

    // remove ajax debug
    getDebugSettings().setAjaxDebugModeEnabled(ajaxDebug);

    // Mount nice URLs for pages - patient pages

    // admins
    mountPage(ADMINS_BASE_URL, AdminsPage.class);
    mountPage("login/admins", AdminsLoginPage.class);
    mountPage(ADMINS_BASE_URL + "/consultants", AdminConsultantsPage.class);
    mountPage(ADMINS_BASE_URL + "/consultants/edit", AdminConsultantPage.class);
    mountPage(ADMINS_BASE_URL + "/issues", AdminIssuesPage.class);
    mountPage(ADMINS_BASE_URL + "/issues/edit", AdminIssuePage.class);
    mountPage(ADMINS_BASE_URL + "/patients-all", AdminPatientsAllPage.class);
    mountPage(ADMINS_BASE_URL + "/patients-all/edit", AdminPatientAllPage.class);
    mountPage(ADMINS_BASE_URL + "/patients-user", AdminPatientsPage.class);
    mountPage(ADMINS_BASE_URL + "/patients-user/edit", AdminPatientPage.class);
    mountPage(ADMINS_BASE_URL + "/users", AdminUsersPage.class);
    mountPage(ADMINS_BASE_URL + "/users/edit", AdminUserPage.class);

    // patient pages
    mountPage("patient/edit", SrnsPatientPage.class);
    mountPage("patient/view", SrnsPatientPageReadOnly.class);
    mountPage("patients", ExistingPatientsListingPage.class);
    mountPage("patient/new", AddPatientPage.class);
    mountPage("patient/edit/generic", GenericPatientPage.class);

    // professional pages
    mountPage("registration/professional", ProfessionalRegistrationPage.class);
    mountPage("professionals", ProfessionalsPage.class);
    mountPage("recruitment", RecruitmentPage.class);
    mountPage("change-details", ChangeRegistrationDetails.class);

    // login pages
    mountPage("login/patient", PatientsLoginPage.class);
    mountPage("login/professional", ProfessionalsLoginPage.class);

    // forget password pages
    mountPage("patient/recover", PatientForgottenPasswordPage.class);
    mountPage("professional/recover", ProfessionalForgottenPasswordPage.class);

    // Static content pages
    mountPage("diseaseindex", DiseaseIndexPage.class);
    mountPage("mpgn", MpgnPage.class);
    mountPage("srns", SrnsPage.class);
    mountPage("consentforms", ConsentFormsPage.class);

    mountPage("error", ErrorPage.class);
}

From source file:org.projectforge.web.wicket.MyAuthorizationStrategy.java

License:Open Source License

@Override
public void onUnauthorizedInstantiation(final Component component) {
    if (MySession.get().isMobileUserAgent() == true) {
        throw new RestartResponseAtInterceptPageException(LoginMobilePage.class);
    } else {//  w  w  w  . jav  a  2 s  .c  o  m
        throw new RestartResponseAtInterceptPageException(LoginPage.class);
    }
}

From source file:org.tdmx.console.pages.login.LoginPage.java

License:Open Source License

public LoginPage() {
    CustomSession session = getCustomSession();
    if (session.isLoggedIn()) {
        throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
    }/*  w w w .j av  a2s .co m*/
    createComponents();
}

From source file:org.wicketstuff.security.checks.AlwaysGrantedSecurityCheck.java

License:Apache License

/**
 * @see org.wicketstuff.security.checks.ISecurityCheck#isActionAuthorized(org.wicketstuff.security.actions.WaspAction)
 *//*from www.j  a  va2s.com*/
public boolean isActionAuthorized(WaspAction action) {
    if (!isAuthenticated())
        throw new RestartResponseAtInterceptPageException(getLoginPage());
    return true;
}

From source file:org.wicketstuff.security.checks.ClassSecurityCheck.java

License:Apache License

/**
 * Checks if the user is authorized for the action. special permission is given to the
 * loginpage, which is always authorized. If the user is not authenticated he is redirected to
 * the login page. Redirects the authorization check to the strategy if the user is
 * authenticated./*  w  ww  .  j av  a2s . c om*/
 * 
 * @return true if the user is authenticated and authorized, false otherwise.
 * @see org.wicketstuff.security.checks.ISecurityCheck#isActionAuthorized(org.wicketstuff.security.actions.WaspAction)
 * @see WaspApplication#getLoginPage()
 * @see WaspAuthorizationStrategy#isClassAuthorized(Class, WaspAction)
 * @throws RestartResponseAtInterceptPageException
 *             if the user is not authenticated.
 */
public boolean isActionAuthorized(WaspAction action) {
    if (getClazz() == getLoginPage())
        return true;
    if (isAuthenticated())
        return getStrategy().isClassAuthorized(getClazz(), action);
    throw new RestartResponseAtInterceptPageException(getLoginPage());

}