Example usage for org.apache.wicket.authorization.strategies.page SimplePageAuthorizationStrategy SimplePageAuthorizationStrategy

List of usage examples for org.apache.wicket.authorization.strategies.page SimplePageAuthorizationStrategy SimplePageAuthorizationStrategy

Introduction

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

Prototype

public <S extends Page> SimplePageAuthorizationStrategy(final Class<?> securePageSuperType,
        final Class<S> signInPageClass) 

Source Link

Document

Construct.

Usage

From source file:eu.esdihumboldt.hale.server.webapp.BaseWebApplication.java

License:Open Source License

@Override
public void init() {
    super.init();

    BootstrapSettings settings = new BootstrapSettings();
    final ThemeProvider themeProvider = new BootswatchThemeProvider() {

        {//from w  w w .  j  av a 2  s  .  c o  m
            add(new MetroTheme());
            add(new GoogleTheme());
            add(new WicketTheme());
            add(new Bootstrap3Theme());
            defaultTheme("bootstrap-responsive");
            //            defaultTheme("bootstrap");
        }
    };
    settings.setThemeProvider(themeProvider);

    Bootstrap.install(this, settings);
    BootstrapLess.install(this);
    configureResourceBundles();

    IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
    if (packageResourceGuard instanceof SecurePackageResourceGuard) {
        SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
        guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
    }

    // enforce mounts so security interceptors based on URLs can't be fooled
    getSecuritySettings().setEnforceMounts(true);

    getSecuritySettings().setAuthorizationStrategy(
            new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {

                @Override
                protected boolean isAuthorized() {
                    SecurityContext securityContext = SecurityContextHolder.getContext();
                    if (securityContext != null) {
                        Authentication authentication = securityContext.getAuthentication();
                        if (authentication != null && authentication.isAuthenticated()) {
                            for (GrantedAuthority authority : authentication.getAuthorities()) {
                                if (authority.getAuthority().equals(UserConstants.ROLE_USER)
                                        || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {

                                    // allow access only for users/admins
                                    return true;
                                }
                            }
                        }
                    }

                    return false;
                }

            });

    getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public IRequestHandler onException(RequestCycle cycle, Exception ex) {
            return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
        }
    });

    // add login page to every application based on this one (if enabled)
    Class<? extends BasePage> loginClass = getLoginPageClass();
    if (loginClass != null) {
        // login page
        mountPage("/login", loginClass);

        // user settings
        mountPage("/settings", UserSettingsPage.class);

        // about
        mountPage("/about", AboutPage.class);

        // contact
        mountPage("/contact", ContactPage.class);

        if (OpenIdLoginPage.class.equals(loginClass)) {
            // for OpenID auth also add page for new users
            mountPage("/new", NewUserPage.class);
        }
    }
}

From source file:org.efaps.mobile.wicket.MobileApplication.java

License:Apache License

@Override
protected void init() {
    getMarkupSettings().setStripWicketTags(true);
    getMarkupSettings().setStripComments(true);
    getMarkupSettings().setCompressWhitespace(true);
    getMarkupSettings().setAutomaticLinking(false);

    getRequestCycleListeners().add(new MobileRequestCycleListener());

    getSecuritySettings()//from   w  w w .  j  a v a  2s .  co m
            .setAuthorizationStrategy(new SimplePageAuthorizationStrategy(ISecuredPage.class, LoginPage.class) {
                @Override
                protected boolean isAuthorized() {
                    final MobileSession session = (MobileSession) WebSession.get();
                    return session.isAuthenticated();
                }
            });
}

From source file:org.tdmx.console.AdminApplication.java

License:Open Source License

@Override
protected void init() {
    super.init();

    // dev utilities
    getDebugSettings().setDevelopmentUtilitiesEnabled(false);
    getDebugSettings().setAjaxDebugModeEnabled(false);
    getRequestCycleSettings().addResponseFilter(new ServerAndClientTimeFilter());

    // wicket bootstrap
    configureBootstrap();/*from  w w  w.ja  v a2 s.  c o m*/

    // javascripts to the bottom
    setHeaderResponseDecorator(new RenderJavaScriptToFooterHeaderResponseDecorator());

    // Setting authorization strategy
    SimplePageAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(
            IProtectedPage.class, LoginPage.class) {
        @Override
        protected boolean isAuthorized() {
            return ((CustomSession) Session.get()).isLoggedIn();
        }
    };
    getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);

    // setting session expired error page
    IApplicationSettings applicationSettings = getApplicationSettings();
    applicationSettings.setPageExpiredErrorPage(LoginPage.class);

    // mount pages
    mountPage("login", LoginPage.class);
    mountPage("profile", ProfilePage.class);
    mount(new MountedMapperWithoutPageComponentInfo("domain", DomainPage.class));
    mountPage("domain/details", DomainDetailsPage.class);

    getMarkupSettings().setStripWicketTags(true);

}

From source file:ro.nextreports.server.web.NextServerApplication.java

License:Apache License

protected void addSecurityAuthorization() {
    Class<? extends Page> signInPageClass = LoginPage.class;
    if (CasUtil.isCasUsed()) {
        signInPageClass = CasLoginPage.class;
    }// w  w  w.  j a  va2  s  .  c o  m

    IAuthorizationStrategy authStrategy = new SimplePageAuthorizationStrategy(SecurePage.class,
            signInPageClass) {

        @Override
        protected boolean isAuthorized() {
            boolean b = NextServerSession.get().isSignedIn();
            if (!b) {
                if (CasUtil.isCasUsed()) {
                    LOG.debug("Checking if context contains CAS authentication");
                    b = NextServerSession.get().checkForSignIn();
                    if (!b) {
                        String serviceUrl = CasUtil.getServiceProperties().getService();
                        String loginUrl = CasUtil.getLoginUrl();
                        LOG.debug("cas authentication: service URL: " + serviceUrl);
                        String redirectUrl = loginUrl + "?service=" + serviceUrl;
                        LOG.debug("attempting to redirect to: " + redirectUrl);
                        throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl));
                    }
                }
            }

            return b;
        }

    };
    getSecuritySettings().setAuthorizationStrategy(authStrategy);
}