Search in sources :

Example 16 with PathSegment

use of javax.ws.rs.core.PathSegment in project scheduling by ow2-proactive.

the class WorkflowVariablesTransformerTest method testTwoVariablesMap.

@Test
public void testTwoVariablesMap() {
    Map<String, String> expectedVariables = Maps.newHashMap();
    expectedVariables.put("KEY1", "VALUE1");
    expectedVariables.put("KEY2", "VALUE2");
    PathSegment pathSegment = mock(PathSegment.class);
    MultivaluedMap<String, String> multivalueMap = new MultivaluedHashMap();
    multivalueMap.put("KEY1", Lists.newArrayList("VALUE1"));
    multivalueMap.put("KEY2", Lists.newArrayList("VALUE2"));
    when(pathSegment.getMatrixParameters()).thenReturn(multivalueMap);
    Map<String, String> variables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
    assertThat(variables, is(expectedVariables));
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) PathSegment(javax.ws.rs.core.PathSegment) Test(org.junit.Test)

Example 17 with PathSegment

use of javax.ws.rs.core.PathSegment in project Payara by payara.

the class Util method getBasePathFromUri.

private static String getBasePathFromUri(UriInfo uriInfo) {
    List<PathSegment> pathSegments = uriInfo.getPathSegments();
    // Discard the last segment if it is empty. This happens if some one accesses the resource
    // with trailing '/' at end like in htto://host:port/mangement/domain/.../pathelement/
    PathSegment lastSegment = pathSegments.get(pathSegments.size() - 1);
    if (lastSegment.getPath().isEmpty()) {
        pathSegments = pathSegments.subList(0, pathSegments.size() - 1);
    }
    List<PathSegment> candidatePathSegment = null;
    if (pathSegments.size() != 1) {
        // Discard "domain"
        candidatePathSegment = pathSegments.subList(1, pathSegments.size());
    } else {
        // We are being called for a config change at domain level.
        // CLI "set" requires name to be of form domain.<attribute-name>.
        // Preserve "domain"
        candidatePathSegment = pathSegments;
    }
    final StringBuilder sb = new StringBuilder();
    for (PathSegment pathSegment : candidatePathSegment) {
        sb.append(pathSegment.getPath());
        sb.append('.');
    }
    return sb.toString();
}
Also used : PathSegment(javax.ws.rs.core.PathSegment)

Example 18 with PathSegment

use of javax.ws.rs.core.PathSegment in project druid by druid-io.

the class DatasourceResourceFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    if (getAuthConfig().isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String dataSourceName = request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {

            @Override
            public boolean apply(PathSegment input) {
                return input.getPath().equals("datasources");
            }
        }) + 1).getPath();
        Preconditions.checkNotNull(dataSourceName);
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        final Access authResult = authorizationInfo.isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
        if (!authResult.isAllowed()) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
        }
    }
    return request;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) PathSegment(javax.ws.rs.core.PathSegment) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Predicate(com.google.common.base.Predicate)

Example 19 with PathSegment

use of javax.ws.rs.core.PathSegment in project druid by druid-io.

the class TaskResourceFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    if (getAuthConfig().isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String taskId = Preconditions.checkNotNull(request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {

            @Override
            public boolean apply(PathSegment input) {
                return input.getPath().equals("task");
            }
        }) + 1).getPath());
        Optional<Task> taskOptional = taskStorageQueryAdapter.getTask(taskId);
        if (!taskOptional.isPresent()) {
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(String.format("Cannot find any task with id: [%s]", taskId)).build());
        }
        final String dataSourceName = Preconditions.checkNotNull(taskOptional.get().getDataSource());
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        final Access authResult = authorizationInfo.isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
        if (!authResult.isAllowed()) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
        }
    }
    return request;
}
Also used : Task(io.druid.indexing.common.task.Task) WebApplicationException(javax.ws.rs.WebApplicationException) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) PathSegment(javax.ws.rs.core.PathSegment) AuthorizationInfo(io.druid.server.security.AuthorizationInfo)

Example 20 with PathSegment

use of javax.ws.rs.core.PathSegment in project incubator-atlas by apache.

the class TaxonomyServiceTest method testGetSubTerms_instance.

@Test
public void testGetSubTerms_instance() throws Exception {
    MetadataService metadataService = createStrictMock(MetadataService.class);
    AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
    ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
    UriInfo uriInfo = createNiceMock(UriInfo.class);
    URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
    JsonSerializer serializer = createStrictMock(JsonSerializer.class);
    PathSegment segment1 = createNiceMock(PathSegment.class);
    PathSegment segment2 = createNiceMock(PathSegment.class);
    PathSegment segment3 = createNiceMock(PathSegment.class);
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
    Map<String, Object> propertyMap = new HashMap<>();
    propertyMap.put("name", "testTaxonomy.testTerm.testTerm2");
    resultPropertyMaps.add(propertyMap);
    Result result = new Result(resultPropertyMaps);
    // set mock expectations
    expect(uriInfo.getRequestUri()).andReturn(uri);
    expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
    expect(segment3.getPath()).andReturn("testTerm2");
    expect(termResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
    expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
    expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
    replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
    // instantiate service and invoke method being tested
    TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
    Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2");
    Request request = requestCapture.getValue();
    assertEquals(request.getQueryProperties().size(), 1);
    TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
    assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
    assertNull(request.getQueryString());
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getEntity(), "Taxonomy Term Get Response");
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) PathSegment(javax.ws.rs.core.PathSegment) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

PathSegment (javax.ws.rs.core.PathSegment)33 Test (org.junit.Test)13 UriInfo (javax.ws.rs.core.UriInfo)10 Map (java.util.Map)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 URI (java.net.URI)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)4 Response (javax.ws.rs.core.Response)4 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)4 Access (io.druid.server.security.Access)3 AuthorizationInfo (io.druid.server.security.AuthorizationInfo)3 Resource (io.druid.server.security.Resource)3 TreeMap (java.util.TreeMap)3 Produces (javax.ws.rs.Produces)3 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)3 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)3