Example usage for org.apache.wicket.authorization IUnauthorizedComponentInstantiationListener IUnauthorizedComponentInstantiationListener

List of usage examples for org.apache.wicket.authorization IUnauthorizedComponentInstantiationListener IUnauthorizedComponentInstantiationListener

Introduction

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

Prototype

IUnauthorizedComponentInstantiationListener

Source Link

Usage

From source file:com.madalla.webapp.authorization.AppAuthorizationStrategy.java

License:Apache License

/**
 * Construct.// w  ww  .  j a  v  a2  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:net.rrm.ehour.ui.common.TestEhourWebApplication.java

License:Open Source License

/**
 * When not authorized, just let it pass
 *///from   w ww .  j av  a  2  s.  co  m
@Override
protected void setupSecurity() {
    getApplicationSettings().setPageExpiredErrorPage(SessionExpiredPage.class);

    getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(this));

    getSecuritySettings()
            .setUnauthorizedComponentInstantiationListener(new IUnauthorizedComponentInstantiationListener() {
                public void onUnauthorizedInstantiation(final Component component) {
                }
            });
}

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  ww.ja v a 2s  .  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.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()//from w w  w.  ja v  a  2s  .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);
}