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));
}
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");
}
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
}
}
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));
}
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));
}
Aggregations