Search in sources :

Example 1 with Action

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

the class ActionPermissionsTest method testRemove1.

/**
 * Test removing roles.
 *
 * @throws Exception
 */
@Test
public void testRemove1() throws Exception {
    ActionPermissions permissions = new ActionPermissions();
    Action mambo = new Action("mambo");
    assertEquals(null, permissions.rolesFor(mambo));
    permissions.unauthorize(mambo, new Roles("maurice"));
    assertEquals(new Roles(MetaDataRoleAuthorizationStrategy.NO_ROLE), permissions.rolesFor(mambo));
}
Also used : Action(org.apache.wicket.authorization.Action) Roles(org.apache.wicket.authroles.authorization.strategies.role.Roles) Test(org.junit.Test)

Example 2 with Action

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

the class EnclosureTest method testRenderPage13.

/**
 * @throws Exception
 */
@Test
public void testRenderPage13() throws Exception {
    tester = new WicketTester(new MockApplication() {

        @Override
        protected void init() {
            super.init();
            // This should cause all SecuredContainer components to be hidden
            getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

                @Override
                public boolean isActionAuthorized(Component component, Action action) {
                    return !(component instanceof SecuredContainer_13);
                }
            });
        }
    });
    executeTest(EnclosurePage_13.class, "EnclosurePageExpectedResult_13.html");
}
Also used : Action(org.apache.wicket.authorization.Action) MockApplication(org.apache.wicket.mock.MockApplication) WicketTester(org.apache.wicket.util.tester.WicketTester) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) Component(org.apache.wicket.Component) Test(org.junit.Test)

Example 3 with Action

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

the class AuthorizationTest method testEnabledDisallowedComponent.

/**
 * Test that a component will update it's model when authorization is ok.
 *
 * @throws Exception
 */
@Test
public void testEnabledDisallowedComponent() throws Exception {
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

        /**
         * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
         *      org.apache.wicket.authorization.Action)
         */
        @Override
        public boolean isActionAuthorized(Component c, Action action) {
            if (action == Component.ENABLE && c instanceof TextField && c.getId().equals("stringInput")) {
                return false;
            }
            return true;
        }
    });
    tester.startPage(AuthTestPage1.class);
    tester.assertRenderedPage(AuthTestPage1.class);
    tester.getRequest().getPostParameters().setParameterValue("form:stringInput", "test");
    try {
        tester.submitForm("form");
        Component component = tester.getComponentFromLastRenderedPage("form:stringInput");
        assertEquals("", component.getDefaultModelObjectAsString());
    } catch (WicketRuntimeException e) {
    // good
    }
}
Also used : Action(org.apache.wicket.authorization.Action) TextField(org.apache.wicket.markup.html.form.TextField) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) WebComponent(org.apache.wicket.markup.html.WebComponent) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) Test(org.junit.Test)

Example 4 with Action

use of org.apache.wicket.authorization.Action 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 5 with Action

use of org.apache.wicket.authorization.Action 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)

Aggregations

Action (org.apache.wicket.authorization.Action)6 Test (org.junit.Test)6 Roles (org.apache.wicket.authroles.authorization.strategies.role.Roles)4 IAuthorizationStrategy (org.apache.wicket.authorization.IAuthorizationStrategy)2 IRoleCheckingStrategy (org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy)2 Label (org.apache.wicket.markup.html.basic.Label)2 Component (org.apache.wicket.Component)1 WebComponent (org.apache.wicket.markup.html.WebComponent)1 TextField (org.apache.wicket.markup.html.form.TextField)1 MockApplication (org.apache.wicket.mock.MockApplication)1 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)1 WicketTester (org.apache.wicket.util.tester.WicketTester)1