use of org.apache.druid.server.security.ResourceAction in project druid by druid-io.
the class RulesResourceFilter method filter.
@Override
public ContainerRequest filter(ContainerRequest request) {
final String dataSourceName = request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
@Override
public boolean apply(PathSegment input) {
return "rules".equals(input.getPath());
}
}) + 1).getPath();
Preconditions.checkNotNull(dataSourceName);
final ResourceAction resourceAction = new ResourceAction(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
final Access authResult = AuthorizationUtils.authorizeResourceAction(getReq(), resourceAction, getAuthorizerMapper());
if (!authResult.isAllowed()) {
throw new ForbiddenException(authResult.toString());
}
return request;
}
use of org.apache.druid.server.security.ResourceAction in project druid by druid-io.
the class DruidPlannerResourceAnalyzeTest method testDynamicParameters.
@Test
public void testDynamicParameters() {
final String sql = "SELECT SUBSTRING(dim2, CAST(? as BIGINT), CAST(? as BIGINT)) FROM druid.foo LIMIT ?";
Set<ResourceAction> requiredResources = analyzeResources(PLANNER_CONFIG_DEFAULT, sql, CalciteTests.REGULAR_USER_AUTH_RESULT);
Assert.assertEquals(ImmutableSet.of(new ResourceAction(new Resource("foo", ResourceType.DATASOURCE), Action.READ)), requiredResources);
}
use of org.apache.druid.server.security.ResourceAction in project druid by druid-io.
the class DruidPlannerResourceAnalyzeTest method testSubqueryUnion.
@Test
public void testSubqueryUnion() {
final String sql = "SELECT\n" + " SUM(cnt),\n" + " COUNT(*)\n" + "FROM (\n" + " SELECT dim2, SUM(cnt) AS cnt\n" + " FROM (SELECT * FROM druid.foo UNION ALL SELECT * FROM druid.foo2)\n" + " GROUP BY dim2\n" + ")";
Set<ResourceAction> requiredResources = analyzeResources(PLANNER_CONFIG_DEFAULT, sql, CalciteTests.REGULAR_USER_AUTH_RESULT);
Assert.assertEquals(ImmutableSet.of(new ResourceAction(new Resource("foo", ResourceType.DATASOURCE), Action.READ), new ResourceAction(new Resource("foo2", ResourceType.DATASOURCE), Action.READ)), requiredResources);
}
use of org.apache.druid.server.security.ResourceAction in project druid by druid-io.
the class DruidPlannerResourceAnalyzeTest method testConfusingViewIdentifiers.
@Test
public void testConfusingViewIdentifiers() {
final String sql = "SELECT COUNT(*) FROM view.dview as druid WHERE druid.numfoo <> 'z'";
Set<ResourceAction> requiredResources = analyzeResources(PLANNER_CONFIG_DEFAULT, sql, CalciteTests.REGULAR_USER_AUTH_RESULT);
Assert.assertEquals(ImmutableSet.of(new ResourceAction(new Resource("dview", ResourceType.VIEW), Action.READ)), requiredResources);
}
use of org.apache.druid.server.security.ResourceAction in project druid by druid-io.
the class DruidPlannerResourceAnalyzeTest method testView.
@Test
public void testView() {
final String sql = "SELECT COUNT(*) FROM view.aview as druid WHERE dim1_firstchar <> 'z'";
Set<ResourceAction> requiredResources = analyzeResources(PLANNER_CONFIG_DEFAULT, sql, CalciteTests.REGULAR_USER_AUTH_RESULT);
Assert.assertEquals(ImmutableSet.of(new ResourceAction(new Resource("aview", ResourceType.VIEW), Action.READ)), requiredResources);
}
Aggregations