Search in sources :

Example 1 with RoleAuthorizationStrategy

use of org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy in project wicket by apache.

the class AnnotationsRoleTest method testClear.

/**
 * @throws Exception
 */
@Test
public void testClear() throws Exception {
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(new UserRolesAuthorizer("FOO")));
    tester.startPage(NormalPage.class);
    tester.assertRenderedPage(NormalPage.class);
}
Also used : RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy) Test(org.junit.Test)

Example 2 with RoleAuthorizationStrategy

use of org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy in project wicket by apache.

the class AnnotationsRoleTest method testAuthorized.

/**
 * @throws Exception
 */
@Test
public void testAuthorized() throws Exception {
    WicketTester tester = new WicketTester();
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(new UserRolesAuthorizer("ADMIN")));
    tester.startPage(AdminPage.class);
    tester.assertRenderedPage(AdminPage.class);
}
Also used : RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 3 with RoleAuthorizationStrategy

use of org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy in project wicket by apache.

the class RolesApplication method init.

@Override
protected void init() {
    super.init();
    getDebugSettings().setDevelopmentUtilitiesEnabled(true);
    getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(new UserRolesAuthorizer()));
    MetaDataRoleAuthorizationStrategy.authorize(AdminBookmarkablePage.class, "ADMIN");
    MetaDataRoleAuthorizationStrategy.authorize(AdminInternalPage.class, "ADMIN");
}
Also used : MetaDataRoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy) RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy)

Example 4 with RoleAuthorizationStrategy

use of org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy in project wicket by apache.

the class AnnotationsRoleTest method testNotAuthorized.

/**
 * @throws Exception
 */
@Test
public void testNotAuthorized() throws Exception {
    WicketTester tester = new WicketTester();
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(new UserRolesAuthorizer("USER")));
    final class Listener implements IUnauthorizedComponentInstantiationListener {

        private boolean eventReceived = false;

        @Override
        public void onUnauthorizedInstantiation(Component component) {
            eventReceived = true;
        }
    }
    Listener listener = new Listener();
    tester.getApplication().getSecuritySettings().setUnauthorizedComponentInstantiationListener(listener);
    try {
        tester.startPage(AdminPage.class);
        assertTrue("an authorization exception event should have been received", listener.eventReceived);
    } catch (Exception e) {
        if (!(e.getCause() instanceof InvocationTargetException && ((InvocationTargetException) e.getCause()).getTargetException() instanceof UnauthorizedInstantiationException)) {
            throw e;
        }
    }
}
Also used : IUnauthorizedComponentInstantiationListener(org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener) RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy) WicketTester(org.apache.wicket.util.tester.WicketTester) IUnauthorizedComponentInstantiationListener(org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener) Component(org.apache.wicket.Component) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 5 with RoleAuthorizationStrategy

use of org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy in project wicket by apache.

the class AuthenticatedWebApplication method init.

/**
 * @see org.apache.wicket.protocol.http.WebApplication#init()
 */
@Override
protected void init() {
    super.init();
    // Set authorization strategy and unauthorized instantiation listener
    getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(this));
    getSecuritySettings().setUnauthorizedComponentInstantiationListener(this);
}
Also used : RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy)

Aggregations

RoleAuthorizationStrategy (org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy)5 Test (org.junit.Test)3 WicketTester (org.apache.wicket.util.tester.WicketTester)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Component (org.apache.wicket.Component)1 IUnauthorizedComponentInstantiationListener (org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener)1 UnauthorizedInstantiationException (org.apache.wicket.authorization.UnauthorizedInstantiationException)1 MetaDataRoleAuthorizationStrategy (org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy)1