Search in sources :

Example 1 with IAuthorizationStrategy

use of org.apache.wicket.authorization.IAuthorizationStrategy in project wicket by apache.

the class AjaxBehaviorEnabledTest method before.

/**
 */
@Before
public void before() {
    final IAuthorizationStrategy strategy = new CustomStrategy();
    tester = new WicketTester(new MockApplication() {

        @Override
        public Session newSession(Request request, Response response) {
            return new WebSession(request) {

                private static final long serialVersionUID = 1L;

                @Override
                public IAuthorizationStrategy getAuthorizationStrategy() {
                    return strategy;
                }
            };
        }
    });
}
Also used : Response(org.apache.wicket.request.Response) WebSession(org.apache.wicket.protocol.http.WebSession) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) WicketTester(org.apache.wicket.util.tester.WicketTester) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) Before(org.junit.Before)

Example 2 with IAuthorizationStrategy

use of org.apache.wicket.authorization.IAuthorizationStrategy in project wicket by apache.

the class Test method testRedirect.

/**
 */
@org.junit.Test
public void testRedirect() {
    final IAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(RedirectPage.class, LoginPage.class) {

        @Override
        protected boolean isAuthorized() {
            return false;
        }
    };
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);
    tester.startPage(RedirectPage.class);
    tester.assertRenderedPage(LoginPage.class);
}
Also used : IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) SimplePageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy)

Example 3 with IAuthorizationStrategy

use of org.apache.wicket.authorization.IAuthorizationStrategy in project wicket by apache.

the class LibraryApplication method init.

@Override
protected void init() {
    super.init();
    getResourceSettings().setThrowExceptionOnMissingResource(false);
    getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.REDIRECT_TO_RENDER);
    // Install a simple page authorization strategy, that checks all pages
    // of type AuthenticatedWebPage.
    IAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(AuthenticatedWebPage.class, SignIn.class) {

        @Override
        protected boolean isAuthorized() {
            // check whether the user is logged on
            return (((LibrarySession) Session.get()).isSignedIn());
        }
    };
    getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);
}
Also used : IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) SimplePageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy)

Aggregations

IAuthorizationStrategy (org.apache.wicket.authorization.IAuthorizationStrategy)3 SimplePageAuthorizationStrategy (org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy)2 MockApplication (org.apache.wicket.mock.MockApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 Request (org.apache.wicket.request.Request)1 Response (org.apache.wicket.request.Response)1 WicketTester (org.apache.wicket.util.tester.WicketTester)1 Before (org.junit.Before)1