Search in sources :

Example 1 with IRoleCheckingStrategy

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

the class InstantiationPermissionsTest method testRemove3.

/**
 * Test consistency in behavior between authorizing a role for a class and then unauthorizing it
 * with {@link #testRemove2()}.
 */
@Test
public void testRemove3() {
    MetaDataRoleAuthorizationStrategy strategy = new MetaDataRoleAuthorizationStrategy(new IRoleCheckingStrategy() {

        @Override
        public boolean hasAnyRole(Roles roles) {
            return false;
        }
    });
    tester.getApplication().setMetaData(MetaDataRoleAuthorizationStrategy.INSTANTIATION_PERMISSIONS, new InstantiationPermissions());
    MetaDataRoleAuthorizationStrategy.authorize(Page.class, "martijn");
    MetaDataRoleAuthorizationStrategy.unauthorize(Page.class, "martijn");
    assertFalse(strategy.isInstantiationAuthorized(Page.class));
}
Also used : Roles(org.apache.wicket.authroles.authorization.strategies.role.Roles) Page(org.apache.wicket.Page) IRoleCheckingStrategy(org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy) Test(org.junit.Test)

Example 2 with IRoleCheckingStrategy

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

the class ActionPermissionsTest method testRemove3.

/**
 * Test consistency in behavior between authorizing a role for an action and then unauthorizing
 * it with {@link #testRemove2()}.
 */
@Test
public void testRemove3() {
    Label label = new Label("label", "text");
    Action mambo = new Action("mambo");
    MetaDataRoleAuthorizationStrategy strategy = new MetaDataRoleAuthorizationStrategy(new IRoleCheckingStrategy() {

        @Override
        public boolean hasAnyRole(Roles roles) {
            return false;
        }
    });
    label.setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, new ActionPermissions());
    MetaDataRoleAuthorizationStrategy.authorize(label, mambo, "johan");
    MetaDataRoleAuthorizationStrategy.unauthorize(label, mambo, "johan");
    assertFalse(strategy.isActionAuthorized(label, mambo));
}
Also used : Action(org.apache.wicket.authorization.Action) Label(org.apache.wicket.markup.html.basic.Label) Roles(org.apache.wicket.authroles.authorization.strategies.role.Roles) IRoleCheckingStrategy(org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy) Test(org.junit.Test)

Example 3 with IRoleCheckingStrategy

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

the class ActionPermissionsTest method testRemove2.

/**
 * Test for issue <a href="http://issues.apache.org/jira/browse/WICKET-1152">WICKET-1152</a>.
 */
@Test
public void testRemove2() {
    Label label = new Label("label", "text");
    Action mambo = new Action("mambo");
    MetaDataRoleAuthorizationStrategy strategy = new MetaDataRoleAuthorizationStrategy(new IRoleCheckingStrategy() {

        @Override
        public boolean hasAnyRole(Roles roles) {
            return false;
        }
    });
    label.setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, new ActionPermissions());
    MetaDataRoleAuthorizationStrategy.unauthorize(label, mambo, "johan");
    assertFalse(strategy.isActionAuthorized(label, mambo));
}
Also used : Action(org.apache.wicket.authorization.Action) Label(org.apache.wicket.markup.html.basic.Label) Roles(org.apache.wicket.authroles.authorization.strategies.role.Roles) IRoleCheckingStrategy(org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy) Test(org.junit.Test)

Example 4 with IRoleCheckingStrategy

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

the class InstantiationPermissionsTest method testRemove2.

/**
 * Test for issue <a href="http://issues.apache.org/jira/browse/WICKET-1152">WICKET-1152</a>.
 */
@Test
public void testRemove2() {
    MetaDataRoleAuthorizationStrategy strategy = new MetaDataRoleAuthorizationStrategy(new IRoleCheckingStrategy() {

        @Override
        public boolean hasAnyRole(Roles roles) {
            return false;
        }
    });
    tester.getApplication().setMetaData(MetaDataRoleAuthorizationStrategy.INSTANTIATION_PERMISSIONS, new InstantiationPermissions());
    MetaDataRoleAuthorizationStrategy.unauthorize(Page.class, "martijn");
    assertFalse(strategy.isInstantiationAuthorized(Page.class));
}
Also used : Roles(org.apache.wicket.authroles.authorization.strategies.role.Roles) Page(org.apache.wicket.Page) IRoleCheckingStrategy(org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy) Test(org.junit.Test)

Aggregations

IRoleCheckingStrategy (org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy)4 Roles (org.apache.wicket.authroles.authorization.strategies.role.Roles)4 Test (org.junit.Test)4 Page (org.apache.wicket.Page)2 Action (org.apache.wicket.authorization.Action)2 Label (org.apache.wicket.markup.html.basic.Label)2