Search in sources :

Example 1 with ResourceAction

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;
}
Also used : ForbiddenException(org.apache.druid.server.security.ForbiddenException) Resource(org.apache.druid.server.security.Resource) Access(org.apache.druid.server.security.Access) PathSegment(javax.ws.rs.core.PathSegment) Predicate(com.google.common.base.Predicate) ResourceAction(org.apache.druid.server.security.ResourceAction)

Example 2 with ResourceAction

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);
}
Also used : Resource(org.apache.druid.server.security.Resource) ResourceAction(org.apache.druid.server.security.ResourceAction) Test(org.junit.Test)

Example 3 with ResourceAction

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);
}
Also used : Resource(org.apache.druid.server.security.Resource) ResourceAction(org.apache.druid.server.security.ResourceAction) Test(org.junit.Test)

Example 4 with ResourceAction

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);
}
Also used : Resource(org.apache.druid.server.security.Resource) ResourceAction(org.apache.druid.server.security.ResourceAction) Test(org.junit.Test)

Example 5 with ResourceAction

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);
}
Also used : Resource(org.apache.druid.server.security.Resource) ResourceAction(org.apache.druid.server.security.ResourceAction) Test(org.junit.Test)

Aggregations

ResourceAction (org.apache.druid.server.security.ResourceAction)40 Resource (org.apache.druid.server.security.Resource)35 Test (org.junit.Test)22 Access (org.apache.druid.server.security.Access)19 ForbiddenException (org.apache.druid.server.security.ForbiddenException)13 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 List (java.util.List)5 POST (javax.ws.rs.POST)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 BasicAuthorizerGroupMapping (org.apache.druid.security.basic.authorization.entity.BasicAuthorizerGroupMapping)5 Inject (com.google.inject.Inject)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 Consumes (javax.ws.rs.Consumes)4 DELETE (javax.ws.rs.DELETE)4