use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class SimpleSignTest method testSignUriStringAndModifyWithDsa.
@Test(expected = SimpleSign.SignatureException.class)
public void testSignUriStringAndModifyWithDsa() 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);
idpUri.queryParam("RelayState", "changedit");
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"));
simpleSign.validateSignature(signedMessage, signatureString, dsaCert);
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class RedirectResponseCreator method signSamlGetResponse.
protected URI signSamlGetResponse(org.opensaml.saml.saml2.core.Response samlResponse, AuthnRequest authnRequest, String relayState) throws WSSecurityException, SimpleSign.SignatureException, IOException {
LOGGER.debug("Signing SAML response for redirect.");
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
String encodedResponse = URLEncoder.encode(RestSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlResponse, doc, false))), "UTF-8");
String requestToSign = String.format("SAMLResponse=%s&RelayState=%s", encodedResponse, relayState);
String assertionConsumerServiceURL = getAssertionConsumerServiceURL(authnRequest);
UriBuilder uriBuilder = UriBuilder.fromUri(assertionConsumerServiceURL);
uriBuilder.queryParam(SSOConstants.SAML_RESPONSE, encodedResponse);
uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState);
getSimpleSign().signUriString(requestToSign, uriBuilder);
LOGGER.debug("Signing successful.");
return uriBuilder.build();
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class KmlEndpoint method createRootNetworkLink.
private Kml createRootNetworkLink(UriInfo uriInfo) throws UnknownHostException {
Kml kml = KmlFactory.createKml();
NetworkLink rootNetworkLink = kml.createAndSetNetworkLink();
rootNetworkLink.setName(this.productName);
rootNetworkLink.setSnippet(KmlFactory.createSnippet().withMaxLines(0));
UriBuilder baseUrlBuidler = UriBuilder.fromUri(uriInfo.getBaseUri());
baseUrlBuidler.replacePath("");
this.baseUrl = baseUrlBuidler.build().toString();
String descriptionHtml = description;
Handlebars handlebars = new Handlebars(templateLoader);
try {
Template template = handlebars.compile("description");
descriptionHtml = template.apply(this);
LOGGER.debug(descriptionHtml);
} catch (IOException e) {
LOGGER.debug("Failed to apply description Template", e);
}
rootNetworkLink.setDescription(descriptionHtml);
rootNetworkLink.setOpen(true);
rootNetworkLink.setVisibility(false);
Link link = rootNetworkLink.createAndSetLink();
UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + KML_TRANSFORM_PARAM + FORWARD_SLASH + "sources", builder);
link.setHref(builder.build().toString());
link.setViewRefreshMode(ViewRefreshMode.NEVER);
link.setRefreshMode(RefreshMode.ON_INTERVAL);
link.setRefreshInterval(REFRESH_INTERVAL);
return kml;
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class KmlEndpoint method getAvailableSources.
/**
* Creates a list of {@link NetworkLink}s, one for each {@link ddf.catalog.source.Source} including the local
* catalog.
*
* @param uriInfo - injected resource provding the URI.
* @return - {@link Kml} containing a folder of {@link NetworkLink}s.
*/
@GET
@Path(FORWARD_SLASH + "sources")
@Produces(KML_MIME_TYPE)
public Kml getAvailableSources(@Context UriInfo uriInfo) {
try {
SourceInfoResponse response = framework.getSourceInfo(new SourceInfoRequestEnterprise(false));
Kml kml = KmlFactory.createKml();
Folder folder = kml.createAndSetFolder();
folder.setOpen(true);
for (SourceDescriptor descriptor : response.getSourceInfo()) {
UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + OPENSEARCH_URL_PATH, builder);
builder = builder.queryParam(SOURCE_PARAM, descriptor.getSourceId());
builder = builder.queryParam(OPENSEARCH_SORT_KEY, OPENSEARCH_DEFAULT_SORT);
builder = builder.queryParam(OPENSEARCH_FORMAT_KEY, KML_TRANSFORM_PARAM);
NetworkLink networkLink = generateViewBasedNetworkLink(builder.build().toURL(), descriptor.getSourceId());
folder.getFeature().add(networkLink);
}
return kml;
} catch (SourceUnavailableException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (UnknownHostException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (MalformedURLException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (IllegalArgumentException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (UriBuilderException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
use of javax.ws.rs.core.UriBuilder in project ddf by codice.
the class TestKmlEndpoint method testGetKmlNetworkLink.
@Test
public void testGetKmlNetworkLink() {
when(mockUriInfo.getQueryParameters(false)).thenReturn(mockMap);
KmlEndpoint kmlEndpoint = new KmlEndpoint(mockBranding, mockFramework);
kmlEndpoint.setDescription("This is some description.");
kmlEndpoint.setLogo("https://tools.codice.org/wiki/download/attachments/3047457/DDF?version=1&modificationDate=1369422662164&api=v2");
kmlEndpoint.setWebSite("https://tools.codice.org/wiki/display/DDF/DDF+Home");
Kml response = kmlEndpoint.getKmlNetworkLink(mockUriInfo);
assertThat(response, notNullValue());
assertThat(response.getFeature(), instanceOf(NetworkLink.class));
NetworkLink networkLink = (NetworkLink) response.getFeature();
Link link = networkLink.getLink();
assertThat(link, notNullValue());
assertThat(link.getHref(), notNullValue());
UriBuilder builder = UriBuilder.fromUri(link.getHref());
URI uri = builder.build();
assertThat(uri.getHost(), is(TEST_HOST));
assertThat(String.valueOf(uri.getPort()), is(TEST_PORT));
assertThat(uri.getPath(), is("/services/catalog/kml/sources"));
}
Aggregations