use of net.n2oapp.framework.access.metadata.SecurityFilters in project n2o-framework by i-novus-llc.
the class ObjectAccessTransformerTest method testObjectTransformV2.
@Test
public void testObjectTransformV2() {
((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "testObjectV2");
ReadCompileTerminalPipeline pipeline = compile("net/n2oapp/framework/access/metadata/schema/testObjectV2.access.xml", "net/n2oapp/framework/access/metadata/transform/testObjectAccessTransformer.object.xml");
CompiledObject object = (CompiledObject) ((ReadCompileTerminalPipeline) pipeline.transform()).get(new ObjectContext("testObjectAccessTransformer"));
CompiledObject.Operation create = object.getOperations().get("create");
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().size(), is(3));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().contains("test"), is(true));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().contains("test2"), is(true));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().contains("test3"), is(true));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getRoles().size(), is(1));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getRoles().contains("role"), is(true));
assertThat(((Security) create.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getAnonymous(), is(true));
CompiledObject.Operation update = object.getOperations().get("update");
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().size(), is(2));
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().contains("test"), is(true));
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions().contains("test3"), is(true));
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getUsernames().size(), is(1));
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getUsernames().contains("user"), is(true));
assertThat(((Security) update.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getAnonymous(), is(true));
SecurityFilters updateFilters = (SecurityFilters) update.getProperties().get(SecurityFilters.SECURITY_FILTERS_PROP_NAME);
assertThat(updateFilters.getRemoveUserFilters().size(), is(1));
assertThat(updateFilters.getRemoveUserFilters().get("user").size(), is(1));
assertThat(updateFilters.getRemoveUserFilters().get("user").contains("nameFilter"), is(true));
assertThat(updateFilters.getPermitAllFilters().size(), is(2));
}
use of net.n2oapp.framework.access.metadata.SecurityFilters in project n2o-framework by i-novus-llc.
the class BaseAccessTransformer method collectObjectFilters.
protected void collectObjectFilters(PropertiesAware compiled, String objectId, String operationId, SimpleCompiledAccessSchema schema) {
if (objectId == null)
return;
if (compiled.getProperties() == null) {
compiled.setProperties(new HashMap<>());
}
if (compiled.getProperties().get(SECURITY_FILTERS_PROP_NAME) == null) {
compiled.getProperties().put(SECURITY_FILTERS_PROP_NAME, new SecurityFilters());
}
SecurityFilters securityFilters = (SecurityFilters) compiled.getProperties().get(SECURITY_FILTERS_PROP_NAME);
collectFilters(objectId, schema, securityFilters);
collectRemoveFilters(objectId, operationId, schema, securityFilters);
}
use of net.n2oapp.framework.access.metadata.SecurityFilters in project n2o-framework by i-novus-llc.
the class QueryAccessTransformerTest method testQueryTransformV2.
@Test
public void testQueryTransformV2() {
((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "testQueryV2");
ReadCompileTerminalPipeline pipeline = compile("net/n2oapp/framework/access/metadata/schema/testQueryV2.access.xml", "net/n2oapp/framework/access/metadata/transform/testQueryAccessTransformer.query.xml");
CompiledQuery query = (CompiledQuery) ((ReadCompileTerminalPipeline) pipeline.transform()).get(new QueryContext("testQueryAccessTransformer"));
assertThat(((Security) query.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getRoles().contains("role"), is(true));
assertThat(((Security) query.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getUsernames().contains("user"), is(true));
assertThat(((Security) query.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermissions(), notNullValue());
assertThat(((Security) query.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getAnonymous(), is(true));
assertThat(((Security) query.getProperties().get(SECURITY_PROP_NAME)).getSecurityMap().get("object").getPermitAll(), is(true));
SecurityFilters securityFilters = (SecurityFilters) query.getProperties().get(SecurityFilters.SECURITY_FILTERS_PROP_NAME);
// filters
assertThat(securityFilters.getRoleFilters().size(), is(2));
assertThat(securityFilters.getRoleFilters().get("role").size(), is(2));
assertThat(securityFilters.getRoleFilters().get("role").get(0).getId(), is("idFilter"));
assertThat(securityFilters.getRoleFilters().get("role").get(1).getId(), is("nameFilter"));
assertThat(securityFilters.getRoleFilters().get("role2").size(), is(2));
assertThat(securityFilters.getPermissionFilters().size(), is(2));
assertThat(securityFilters.getPermissionFilters().get("permission").size(), is(2));
assertThat(securityFilters.getPermissionFilters().get("permission").get(0).getId(), is("permIdFilter"));
assertThat(securityFilters.getPermissionFilters().get("permission").get(1).getId(), is("permNameFilter"));
assertThat(securityFilters.getPermissionFilters().get("permission2").size(), is(2));
assertThat(securityFilters.getUserFilters().size(), is(1));
assertThat(securityFilters.getUserFilters().get("user2").size(), is(2));
assertThat(securityFilters.getUserFilters().get("user2").get(0).getId(), is("userIdFilter2"));
assertThat(securityFilters.getUserFilters().get("user2").get(1).getId(), is("userNameFilter2"));
assertThat(securityFilters.getAnonymousFilters().size(), is(2));
assertThat(securityFilters.getAnonymousFilters().get(0).getId(), is("anonymIdFilter"));
assertThat(securityFilters.getAnonymousFilters().get(1).getId(), is("anonymNameFilter"));
assertThat(securityFilters.getPermitAllFilters().size(), is(2));
assertThat(securityFilters.getPermitAllFilters().get(0).getId(), is("permitAllIdFilter"));
assertThat(securityFilters.getPermitAllFilters().get(1).getId(), is("permitAllNameFilter"));
assertThat(securityFilters.getAuthenticatedFilters().size(), is(2));
assertThat(securityFilters.getAuthenticatedFilters().get(0).getId(), is("authIdFilter"));
assertThat(securityFilters.getAuthenticatedFilters().get(1).getId(), is("authNameFilter"));
// remove filters
assertThat(securityFilters.getRemoveRoleFilters().size(), is(2));
assertThat(securityFilters.getRemoveRoleFilters().get("role").size(), is(2));
assertThat(securityFilters.getRemoveRoleFilters().get("role").contains("idFilter"), is(true));
assertThat(securityFilters.getRemoveRoleFilters().get("role").contains("nameFilter"), is(true));
assertThat(securityFilters.getRemoveRoleFilters().get("role2").size(), is(2));
assertThat(securityFilters.getRemovePermissionFilters().size(), is(2));
assertThat(securityFilters.getRemovePermissionFilters().get("permission").size(), is(2));
assertThat(securityFilters.getRemovePermissionFilters().get("permission").contains("permIdFilter"), is(true));
assertThat(securityFilters.getRemovePermissionFilters().get("permission").contains("permNameFilter"), is(true));
assertThat(securityFilters.getRemovePermissionFilters().get("permission2").size(), is(2));
assertThat(securityFilters.getRemoveUserFilters().size(), is(1));
assertThat(securityFilters.getRemoveUserFilters().get("user2").size(), is(2));
assertThat(securityFilters.getRemoveUserFilters().get("user2").contains("userIdFilter2"), is(true));
assertThat(securityFilters.getRemoveUserFilters().get("user2").contains("userNameFilter2"), is(true));
assertThat(securityFilters.getRemoveAnonymousFilters().size(), is(2));
assertThat(securityFilters.getRemoveAnonymousFilters().contains("anonymIdFilter"), is(true));
assertThat(securityFilters.getRemoveAnonymousFilters().contains("anonymNameFilter"), is(true));
assertThat(securityFilters.getRemovePermitAllFilters().size(), is(2));
assertThat(securityFilters.getRemovePermitAllFilters().contains("permitAllIdFilter"), is(true));
assertThat(securityFilters.getRemovePermitAllFilters().contains("permitAllNameFilter"), is(true));
assertThat(securityFilters.getRemoveAuthenticatedFilters().size(), is(2));
assertThat(securityFilters.getRemoveAuthenticatedFilters().contains("authIdFilter"), is(true));
assertThat(securityFilters.getRemoveAuthenticatedFilters().contains("authNameFilter"), is(true));
}
Aggregations