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
}
}
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());
}
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;
}
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");
}
}
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);
}
Aggregations