Search in sources :

Example 51 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyWebTargetTest method testResolveTemplate.

@Test
public void testResolveTemplate() {
    URI uri;
    UriBuilder uriBuilder;
    uri = target.resolveTemplate("a", "v").getUri();
    assertEquals("/", uri.toString());
    uri = target.path("{a}").resolveTemplate("a", "v").getUri();
    assertEquals("/v", uri.toString());
    uriBuilder = target.path("{a}").resolveTemplate("qqq", "qqq").getUriBuilder();
    assertEquals("/{a}", uriBuilder.toTemplate());
    uriBuilder = target.path("{a}").resolveTemplate("a", "v").resolveTemplate("a", "x").getUriBuilder();
    assertEquals("/v", uriBuilder.build().toString());
    try {
        target.resolveTemplate(null, null);
        fail("NullPointerException expected.");
    } catch (NullPointerException ex) {
    // expected
    }
}
Also used : JerseyUriBuilder(org.glassfish.jersey.uri.internal.JerseyUriBuilder) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 52 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyWebTargetTest method testResolveTemplate2.

@Test
public void testResolveTemplate2() {
    final JerseyWebTarget newTarget = target.path("path/{a}").queryParam("query", "{q}").resolveTemplate("a", "param-a");
    final JerseyUriBuilder uriBuilder = (JerseyUriBuilder) newTarget.getUriBuilder();
    uriBuilder.resolveTemplate("q", "param-q").resolveTemplate("a", "will-be-ignored");
    assertEquals(URI.create("/path/param-a?query=param-q"), uriBuilder.build());
    final UriBuilder uriBuilderNew = newTarget.resolveTemplate("a", "will-be-ignored").resolveTemplate("q", "new-q").getUriBuilder();
    assertEquals(URI.create("/path/param-a?query=new-q"), uriBuilderNew.build());
}
Also used : JerseyUriBuilder(org.glassfish.jersey.uri.internal.JerseyUriBuilder) JerseyUriBuilder(org.glassfish.jersey.uri.internal.JerseyUriBuilder) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 53 with UriBuilder

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

the class EntityResource method getLocationURI.

@VisibleForTesting
public URI getLocationURI(List<String> guids) {
    URI locationURI = null;
    if (uriInfo != null) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        locationURI = CollectionUtils.isEmpty(guids) ? null : ub.path(guids.get(0)).build();
    } else {
        String uriPath = AtlasClient.API.GET_ENTITY.getPath();
        locationURI = guids.isEmpty() ? null : UriBuilder.fromPath(AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS).path(uriPath).path(guids.get(0)).build();
    }
    return locationURI;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 54 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project ddf by codice.

the class IdpHandler method doHttpRedirectBinding.

private void doHttpRedirectBinding(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    String redirectUrl;
    String idpRequest = null;
    String relayState = createRelayState(request);
    try {
        IDPSSODescriptor idpssoDescriptor = idpMetadata.getDescriptor();
        if (idpssoDescriptor == null) {
            throw new ServletException("IdP metadata is missing. No IDPSSODescriptor present.");
        }
        String queryParams = String.format("SAMLRequest=%s&RelayState=%s", encodeAuthnRequest(createAndSignAuthnRequest(false, idpssoDescriptor.getWantAuthnRequestsSigned()), false), URLEncoder.encode(relayState, "UTF-8"));
        idpRequest = idpMetadata.getSingleSignOnLocation() + "?" + queryParams;
        UriBuilder idpUri = new UriBuilderImpl(new URI(idpRequest));
        simpleSign.signUriString(queryParams, idpUri);
        redirectUrl = idpUri.build().toString();
    } catch (UnsupportedEncodingException e) {
        LOGGER.info("Unable to encode relay state: {}", relayState, e);
        throw new ServletException("Unable to create return location");
    } catch (SimpleSign.SignatureException e) {
        String msg = "Unable to sign request";
        LOGGER.info(msg, e);
        throw new ServletException(msg);
    } catch (URISyntaxException e) {
        LOGGER.info("Unable to parse IDP request location: {}", idpRequest, e);
        throw new ServletException("Unable to determine IDP location.");
    }
    try {
        response.sendRedirect(redirectUrl);
        response.flushBuffer();
    } catch (IOException e) {
        LOGGER.info("Unable to redirect AuthnRequest to {}", redirectUrl, e);
        throw new ServletException("Unable to redirect to IdP");
    }
}
Also used : ServletException(javax.servlet.ServletException) SimpleSign(ddf.security.samlp.SimpleSign) IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) UriBuilderImpl(org.apache.cxf.jaxrs.impl.UriBuilderImpl) URI(java.net.URI)

Example 55 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project ddf by codice.

the class SimpleSignTest method testSignUriStringWithDsa.

@Test
public void testSignUriStringWithDsa() throws Exception {
    systemCrypto = new SystemCrypto("dsa-encryption.properties", "dsa-signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    String deflatedSamlResponse = deflateAndBase64Encode(cannedResponse);
    String queryParams = String.format("SAMLResponse=%s&RelayState=%s", URLEncoder.encode(deflatedSamlResponse, "UTF-8"), URLEncoder.encode(RELAY_STATE_VAL, "UTF-8"));
    String idpRequest = SINGLE_SIGN_ON_LOCATION + "?" + queryParams;
    UriBuilder idpUri = new UriBuilderImpl(new URI(idpRequest));
    simpleSign.signUriString(queryParams, idpUri);
    String signatureAlgorithm = URLEncodedUtils.parse(idpUri.build(), "UTF-8").get(2).getValue();
    String signatureString = URLEncodedUtils.parse(idpUri.build(), "UTF-8").get(3).getValue();
    String signedMessage = String.format("%s=%s&%s=%s&%s=%s", SAML_RESPONSE, URLEncoder.encode(deflatedSamlResponse, "UTF-8"), RELAY_STATE, URLEncoder.encode(RELAY_STATE_VAL, "UTF-8"), SIG_ALG, URLEncoder.encode(signatureAlgorithm, "UTF-8"));
    boolean valid = simpleSign.validateSignature(signedMessage, signatureString, dsaCert);
    assertTrue("Signature was expected to be valid", valid);
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) UriBuilderImpl(org.apache.cxf.jaxrs.impl.UriBuilderImpl) URI(java.net.URI) Test(org.junit.Test)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)167 URI (java.net.URI)78 Test (org.junit.Test)58 HashMap (java.util.HashMap)21 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)12 PUT (javax.ws.rs.PUT)11 Produces (javax.ws.rs.Produces)9 URL (java.net.URL)8 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 Timed (com.codahale.metrics.annotation.Timed)7 POST (javax.ws.rs.POST)7 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 ServerException (org.eclipse.che.api.core.ServerException)6 List (java.util.List)5