Search in sources :

Example 1 with SecurityFilters

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));
}
Also used : CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) ReadCompileTerminalPipeline(net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline) ObjectContext(net.n2oapp.framework.config.metadata.compile.context.ObjectContext) SecurityFilters(net.n2oapp.framework.access.metadata.SecurityFilters) Security(net.n2oapp.framework.access.metadata.Security) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Example 2 with SecurityFilters

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);
}
Also used : SecurityFilters(net.n2oapp.framework.access.metadata.SecurityFilters)

Example 3 with 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));
}
Also used : ReadCompileTerminalPipeline(net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline) QueryContext(net.n2oapp.framework.config.metadata.compile.context.QueryContext) SecurityFilters(net.n2oapp.framework.access.metadata.SecurityFilters) Security(net.n2oapp.framework.access.metadata.Security) CompiledQuery(net.n2oapp.framework.api.metadata.local.CompiledQuery) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Aggregations

SecurityFilters (net.n2oapp.framework.access.metadata.SecurityFilters)3 Security (net.n2oapp.framework.access.metadata.Security)2 ReadCompileTerminalPipeline (net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline)2 SimplePropertyResolver (net.n2oapp.framework.config.test.SimplePropertyResolver)2 Test (org.junit.Test)2 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)1 CompiledQuery (net.n2oapp.framework.api.metadata.local.CompiledQuery)1 ObjectContext (net.n2oapp.framework.config.metadata.compile.context.ObjectContext)1 QueryContext (net.n2oapp.framework.config.metadata.compile.context.QueryContext)1