Search in sources :

Example 1 with MapPermission

use of com.hazelcast.security.permission.MapPermission in project hazelcast by hazelcast.

the class StreamEventJournalP method streamRemoteMapSupplier.

@SuppressWarnings("unchecked")
public static <K, V, T> ProcessorMetaSupplier streamRemoteMapSupplier(@Nonnull String mapName, @Nonnull String clientXml, @Nonnull PredicateEx<? super EventJournalMapEvent<K, V>> predicate, @Nonnull FunctionEx<? super EventJournalMapEvent<K, V>, ? extends T> projection, @Nonnull JournalInitialPosition initialPos, @Nonnull EventTimePolicy<? super T> eventTimePolicy) {
    checkSerializable(predicate, "predicate");
    checkSerializable(projection, "projection");
    return new ClusterMetaSupplier<>(clientXml, SecuredFunctions.mapEventJournalReaderFn(mapName), predicate, projection, initialPos, eventTimePolicy, () -> new MapPermission(mapName, ACTION_CREATE, ACTION_READ));
}
Also used : MapPermission(com.hazelcast.security.permission.MapPermission)

Example 2 with MapPermission

use of com.hazelcast.security.permission.MapPermission in project hazelcast by hazelcast.

the class SqlSecurityCallbackTest method check.

private void check(String sql, boolean useIndex) {
    // Execute twice to make sure that permission is checked when the plan is cached.
    for (int i = 0; i < 2; i++) {
        TestSqlSecurityContext securityContext = new TestSqlSecurityContext();
        try (SqlResult ignored = ((SqlServiceImpl) instance().getSql()).execute(new SqlStatement(sql), securityContext)) {
            // Check whether the index is used as expected.
            checkIndexUsage(sql, useIndex);
            // Check permissions.
            assertThat(securityContext.getPermissions()).contains(new MapPermission(mapName, ActionConstants.ACTION_READ));
        }
    }
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) MapPermission(com.hazelcast.security.permission.MapPermission)

Example 3 with MapPermission

use of com.hazelcast.security.permission.MapPermission in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method extractPermissions.

private List<Permission> extractPermissions(PhysicalRel physicalRel) {
    List<Permission> permissions = new ArrayList<>();
    physicalRel.accept(new RelShuttleImpl() {

        @Override
        public RelNode visit(TableScan scan) {
            addPermissionForTable(scan.getTable(), ActionConstants.ACTION_READ);
            return super.visit(scan);
        }

        @Override
        public RelNode visit(RelNode other) {
            addPermissionForTable(other.getTable(), ActionConstants.ACTION_PUT);
            return super.visit(other);
        }

        private void addPermissionForTable(RelOptTable t, String action) {
            if (t == null) {
                return;
            }
            HazelcastTable table = t.unwrap(HazelcastTable.class);
            if (table != null && table.getTarget() instanceof AbstractMapTable) {
                String mapName = ((AbstractMapTable) table.getTarget()).getMapName();
                permissions.add(new MapPermission(mapName, action));
            }
        }
    });
    return permissions;
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) AbstractMapTable(com.hazelcast.sql.impl.schema.map.AbstractMapTable) RelNode(org.apache.calcite.rel.RelNode) MapPermission(com.hazelcast.security.permission.MapPermission) Permission(java.security.Permission) MapPermission(com.hazelcast.security.permission.MapPermission) ArrayList(java.util.ArrayList) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlString(org.apache.calcite.sql.util.SqlString) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Example 4 with MapPermission

use of com.hazelcast.security.permission.MapPermission in project hazelcast by hazelcast.

the class StreamEventJournalP method streamMapSupplier.

@SuppressWarnings("unchecked")
public static <K, V, T> ProcessorMetaSupplier streamMapSupplier(@Nonnull String mapName, @Nonnull PredicateEx<? super EventJournalMapEvent<K, V>> predicate, @Nonnull FunctionEx<? super EventJournalMapEvent<K, V>, ? extends T> projection, @Nonnull JournalInitialPosition initialPos, @Nonnull EventTimePolicy<? super T> eventTimePolicy) {
    checkSerializable(predicate, "predicate");
    checkSerializable(projection, "projection");
    return new ClusterMetaSupplier<>(null, SecuredFunctions.mapEventJournalReaderFn(mapName), predicate, projection, initialPos, eventTimePolicy, () -> new MapPermission(mapName, ACTION_CREATE, ACTION_READ));
}
Also used : MapPermission(com.hazelcast.security.permission.MapPermission)

Aggregations

MapPermission (com.hazelcast.security.permission.MapPermission)4 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)1 SqlResult (com.hazelcast.sql.SqlResult)1 SqlStatement (com.hazelcast.sql.SqlStatement)1 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)1 AbstractMapTable (com.hazelcast.sql.impl.schema.map.AbstractMapTable)1 Permission (java.security.Permission)1 ArrayList (java.util.ArrayList)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelNode (org.apache.calcite.rel.RelNode)1 RelShuttleImpl (org.apache.calcite.rel.RelShuttleImpl)1 TableScan (org.apache.calcite.rel.core.TableScan)1 SqlString (org.apache.calcite.sql.util.SqlString)1