diff --git a/catalog/confluence/catalog-confluence-source/src/main/java/org/codice/ddf/confluence/source/ConfluenceSource.java b/catalog/confluence/catalog-confluence-source/src/main/java/org/codice/ddf/confluence/source/ConfluenceSource.java index f13fe67d3d19..c999d1453d07 100644 --- a/catalog/confluence/catalog-confluence-source/src/main/java/org/codice/ddf/confluence/source/ConfluenceSource.java +++ b/catalog/confluence/catalog-confluence-source/src/main/java/org/codice/ddf/confluence/source/ConfluenceSource.java @@ -44,6 +44,7 @@ import java.io.Serializable; import java.net.URI; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -277,7 +278,7 @@ public SourceResponse query(QueryRequest request) throws UnsupportedQueryExcepti String error = ""; try { if (stream != null) { - error = IOUtils.toString(stream); + error = IOUtils.toString(stream, StandardCharsets.UTF_8); } } catch (IOException ioe) { LOGGER.debug("Could not convert error message to a string for output.", ioe); diff --git a/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceInputTransformerTest.java b/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceInputTransformerTest.java index 46a79ab6b710..208e2fff832e 100644 --- a/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceInputTransformerTest.java +++ b/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceInputTransformerTest.java @@ -171,7 +171,7 @@ public void testTransformingAnonymousContent() throws Exception { private String getFileContent(String filePath) { try { return IOUtils.toString( - this.getClass().getClassLoader().getResourceAsStream(filePath), "UTF-8"); + this.getClass().getClassLoader().getResourceAsStream(filePath), StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Failed to read filepath: " + filePath); } diff --git a/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceSourceTest.java b/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceSourceTest.java index 8d64071c65af..8e54b0f9c01e 100644 --- a/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceSourceTest.java +++ b/catalog/confluence/catalog-confluence-source/src/test/java/org/codice/ddf/confluence/source/ConfluenceSourceTest.java @@ -555,7 +555,7 @@ private static String getFileContent(String filePath) { try { return IOUtils.toString( ConfluenceSourceTest.class.getClassLoader().getResourceAsStream(filePath), - StandardCharsets.UTF_8.toString()); + StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Failed to read filepath: " + filePath); } diff --git a/catalog/core/catalog-core-commands/src/main/java/org/codice/ddf/commands/catalog/ValidateCommand.java b/catalog/core/catalog-core-commands/src/main/java/org/codice/ddf/commands/catalog/ValidateCommand.java index 9d8a39226f44..a3180030d296 100644 --- a/catalog/core/catalog-core-commands/src/main/java/org/codice/ddf/commands/catalog/ValidateCommand.java +++ b/catalog/core/catalog-core-commands/src/main/java/org/codice/ddf/commands/catalog/ValidateCommand.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -122,7 +123,7 @@ private List createMetacardsFromFiles() throws IOException { List metacards = new ArrayList<>(); for (File file : files) { Metacard metacard = new MetacardImpl(); - String metadata = IOUtils.toString(file.toURI()); + String metadata = IOUtils.toString(file.toURI(), StandardCharsets.UTF_8); metacard.setAttribute(new AttributeImpl(Metacard.METADATA, metadata)); metacard.setAttribute(new AttributeImpl(Metacard.TITLE, file.getName())); metacards.add(metacard); diff --git a/catalog/core/catalog-core-definitionparser/src/main/java/ddf/catalog/definition/impl/DefinitionParser.java b/catalog/core/catalog-core-definitionparser/src/main/java/ddf/catalog/definition/impl/DefinitionParser.java index 30418050ad7e..f59fb591f4d0 100644 --- a/catalog/core/catalog-core-definitionparser/src/main/java/ddf/catalog/definition/impl/DefinitionParser.java +++ b/catalog/core/catalog-core-definitionparser/src/main/java/ddf/catalog/definition/impl/DefinitionParser.java @@ -250,7 +250,7 @@ public boolean canHandle(File file) { private void apply(File file) throws Exception { String data; try (InputStream input = new FileInputStream(file)) { - data = IOUtils.toString(input, StandardCharsets.UTF_8.name()); + data = IOUtils.toString(input, StandardCharsets.UTF_8); LOGGER.debug("Installing file [{}]. Contents:\n{}", file.getAbsolutePath(), data); } if (StringUtils.isEmpty(data)) { diff --git a/catalog/core/catalog-core-urlresourcereader/src/main/java/ddf/catalog/resource/impl/URLResourceReader.java b/catalog/core/catalog-core-urlresourcereader/src/main/java/ddf/catalog/resource/impl/URLResourceReader.java index 376c20af16d2..fb4f944f8f65 100644 --- a/catalog/core/catalog-core-urlresourcereader/src/main/java/ddf/catalog/resource/impl/URLResourceReader.java +++ b/catalog/core/catalog-core-urlresourcereader/src/main/java/ddf/catalog/resource/impl/URLResourceReader.java @@ -32,6 +32,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.nio.file.InvalidPathException; import java.nio.file.Paths; import java.security.AccessController; @@ -423,7 +424,7 @@ private ResourceResponse retrieveHttpProduct( private String getResponseErrorMessage(InputStream is) { String error = ""; try { - error = IOUtils.toString(is); + error = IOUtils.toString(is, StandardCharsets.UTF_8); } catch (IOException ioe) { LOGGER.debug("Could not convert error message to a string for output.", ioe); } diff --git a/catalog/schematron/catalog-schematron-plugin/src/test/java/ddf/services/schematron/SchematronValidationServiceTest.java b/catalog/schematron/catalog-schematron-plugin/src/test/java/ddf/services/schematron/SchematronValidationServiceTest.java index 22036b158228..ecc9804898df 100755 --- a/catalog/schematron/catalog-schematron-plugin/src/test/java/ddf/services/schematron/SchematronValidationServiceTest.java +++ b/catalog/schematron/catalog-schematron-plugin/src/test/java/ddf/services/schematron/SchematronValidationServiceTest.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Optional; @@ -224,7 +225,9 @@ public void testSanitizationChangesInput() { } private MetacardImpl getMetacard(String filename) throws IOException { - String metadata = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(filename)); + String metadata = + IOUtils.toString( + getClass().getClassLoader().getResourceAsStream(filename), StandardCharsets.UTF_8); MetacardImpl metacard = new MetacardImpl(); metacard.setMetadata(metadata); return metacard; diff --git a/catalog/spatial/csw/spatial-csw-endpoint/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/endpoint/event/CswSubscriptionConfigFactoryTest.java b/catalog/spatial/csw/spatial-csw-endpoint/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/endpoint/event/CswSubscriptionConfigFactoryTest.java index 6900c04c0386..fd57f08bfa86 100644 --- a/catalog/spatial/csw/spatial-csw-endpoint/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/endpoint/event/CswSubscriptionConfigFactoryTest.java +++ b/catalog/spatial/csw/spatial-csw-endpoint/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/endpoint/event/CswSubscriptionConfigFactoryTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.nio.charset.StandardCharsets; import net.opengis.cat.csw.v_2_0_2.GetRecordsType; import org.apache.commons.io.IOUtils; import org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswSubscriptionEndpoint; @@ -47,7 +48,8 @@ public void setup() throws Exception { cswSubscriptionConfigFactory = new CswSubscriptionConfigFactory(subscriptionService); filterXml = IOUtils.toString( - CswSubscriptionConfigFactoryTest.class.getResourceAsStream("/GetRecords.xml"), "UTF-8"); + CswSubscriptionConfigFactoryTest.class.getResourceAsStream("/GetRecords.xml"), + StandardCharsets.UTF_8); } @Test diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProvider.java b/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProvider.java index d17d7581682f..73a4daed6755 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProvider.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProvider.java @@ -174,10 +174,10 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co try (InputStream is = readXml(reader, context)) { InputStream inputStream = is; if (LOGGER.isDebugEnabled()) { - String originalInputStream = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); + String originalInputStream = IOUtils.toString(inputStream, StandardCharsets.UTF_8); LOGGER.debug("About to transform\n{}", originalInputStream); inputStream = - new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8.name())); + new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8)); } metacard = transformer.transform(inputStream); } catch (IOException | CatalogTransformerException e) { diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformer.java b/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformer.java index 8e043bff3d25..87bdce302042 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformer.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/main/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformer.java @@ -42,6 +42,7 @@ import java.io.StringReader; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -230,7 +231,7 @@ private Metacard handleTransform(InputStream inputStream, String id) byteArray = temporaryFileBackedOutputStream.asByteSource(); try (InputStream xmlSourceInputStream = getSourceInputStream()) { - xml = IOUtils.toString(xmlSourceInputStream); + xml = IOUtils.toString(xmlSourceInputStream, StandardCharsets.UTF_8); } argumentHolder.put(XstreamPathConverter.PATH_KEY, buildPaths()); diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswRecordConverterTest.java b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswRecordConverterTest.java index dfa396c3da6f..b54db932e695 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswRecordConverterTest.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswRecordConverterTest.java @@ -137,7 +137,9 @@ public static void setUpBeforeClass() throws Exception { converter = new CswRecordConverter(getCswMetacardType()); cswRecordXml = - IOUtils.toString(CswRecordConverterTest.class.getResourceAsStream("/Csw_Record_Text.xml")); + IOUtils.toString( + CswRecordConverterTest.class.getResourceAsStream("/Csw_Record_Text.xml"), + StandardCharsets.UTF_8); } @Test @@ -440,7 +442,7 @@ public void testMetacardTransform() BinaryContent content = converter.transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat( xml, containsString("")); XMLUnit.setIgnoreWhitespace(true); @@ -458,7 +460,7 @@ public void testMetacardTransformOmitXmlDeclaration() BinaryContent content = converter.transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat( xml, not(containsString(""))); XMLUnit.setIgnoreWhitespace(true); @@ -475,7 +477,7 @@ public void testMetacardTransformOmitNamespaces() BinaryContent content = converter.transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml, containsString("")); } @@ -489,7 +491,7 @@ public void testMetacardTransformWithCswRecordMetadata() BinaryContent content = converter.transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml, containsString("")); XMLUnit.setIgnoreWhitespace(true); assertXMLEqual(cswRecordXml, xml); diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProviderTest.java b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProviderTest.java index d691cde9f5b0..9276355d22e4 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProviderTest.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/CswTransformProviderTest.java @@ -215,7 +215,7 @@ public void testUnmarshalCopyPreservesNamespaces() throws Exception { verify(mockInputTransformer, times(1)).transform(captor.capture()); InputStream inStream = captor.getValue(); - String result = IOUtils.toString(inStream); + String result = IOUtils.toString(inStream, StandardCharsets.UTF_8); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(getRecord(), result); @@ -289,7 +289,7 @@ public void testUnmarshalMissingNamespaces() throws Exception { verify(mockInputTransformer, times(1)).transform(captor.capture()); InputStream inStream = captor.getValue(); - String result = IOUtils.toString(inStream); + String result = IOUtils.toString(inStream, StandardCharsets.UTF_8); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(getRecord(), result); diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/GmdConverterTest.java b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/GmdConverterTest.java index ac0d9cc2c5df..b17603366b46 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/GmdConverterTest.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/GmdConverterTest.java @@ -35,6 +35,7 @@ import java.io.StringWriter; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.GregorianCalendar; import java.util.TimeZone; @@ -124,7 +125,7 @@ public void testMarshalSparseMetacard() throws IOException, SAXException { private void assertMetacard(Metacard metacard, String xmlPath) throws IOException, SAXException { String compareString; try (InputStream input = getClass().getResourceAsStream(xmlPath)) { - compareString = IOUtils.toString(input); + compareString = IOUtils.toString(input, StandardCharsets.UTF_8); } String xml = convert(metacard, true); diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/TransactionRequestConverterTest.java b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/TransactionRequestConverterTest.java index efb517300bd2..437badeb68b1 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/TransactionRequestConverterTest.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/converter/TransactionRequestConverterTest.java @@ -35,6 +35,7 @@ import ddf.catalog.data.impl.types.MediaAttributes; import ddf.catalog.data.impl.types.TopicAttributes; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import net.opengis.cat.csw.v_2_0_2.DeleteType; import net.opengis.cat.csw.v_2_0_2.QueryConstraintType; @@ -208,7 +209,8 @@ public void testMultipleOperations() throws Exception { public void testUnmarshalInsert() throws Exception { String insertRequest = IOUtils.toString( - TransactionRequestConverterTest.class.getResourceAsStream("/insertRequest.xml")); + TransactionRequestConverterTest.class.getResourceAsStream("/insertRequest.xml"), + StandardCharsets.UTF_8); CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(insertRequest); assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class)); assertThat(request.getUpdateActions(), emptyCollectionOf(UpdateAction.class)); @@ -222,7 +224,8 @@ public void testUnmarshalUpdateWholeRecord() throws Exception { String updateRequest = IOUtils.toString( TransactionRequestConverterTest.class.getResourceAsStream( - "/updateWholeRecordRequest.xml")); + "/updateWholeRecordRequest.xml"), + StandardCharsets.UTF_8); CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(updateRequest); assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class)); assertThat(request.getUpdateActions(), hasSize(1)); @@ -236,7 +239,8 @@ public void testUnmarshalByProperty() throws Exception { String updateRequest = IOUtils.toString( TransactionRequestConverterTest.class.getResourceAsStream( - "/updateByPropertyRequest.xml")); + "/updateByPropertyRequest.xml"), + StandardCharsets.UTF_8); CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(updateRequest); assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class)); assertThat(request.getUpdateActions(), hasSize(1)); @@ -259,7 +263,8 @@ public void testUnmarshalByProperty() throws Exception { public void testUnmarshalDelete() throws Exception { String deleteRequest = IOUtils.toString( - TransactionRequestConverterTest.class.getResourceAsStream("/deleteRequest.xml")); + TransactionRequestConverterTest.class.getResourceAsStream("/deleteRequest.xml"), + StandardCharsets.UTF_8); CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(deleteRequest); assertThat(request.getDeleteActions(), hasSize(1)); assertThat(request.getUpdateActions(), emptyCollectionOf(UpdateAction.class)); diff --git a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformerTest.java b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformerTest.java index 4bcec8684ab9..003262a837c6 100644 --- a/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformerTest.java +++ b/catalog/spatial/csw/spatial-csw-transformer/src/test/java/org/codice/ddf/spatial/ogc/csw/catalog/transformer/GmdTransformerTest.java @@ -48,6 +48,7 @@ import java.io.InputStreamReader; import java.io.Serializable; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -249,7 +250,7 @@ public void testMetacardTransform() throws IOException, CatalogTransformerExcept BinaryContent content = new GmdTransformer(gmdMetacardType).transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml, startsWith(XML_DECLARATION)); } @@ -262,7 +263,7 @@ public void testMetacardTransformNoDeclaration() throws IOException, CatalogTran BinaryContent content = new GmdTransformer(gmdMetacardType).transform(metacard, args); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml, not(startsWith(XML_DECLARATION))); } @@ -272,7 +273,7 @@ public void testMetacardTransformNullArgs() throws IOException, CatalogTransform BinaryContent content = new GmdTransformer(gmdMetacardType).transform(metacard, null); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml, startsWith(XML_DECLARATION)); } @@ -280,7 +281,7 @@ public void testMetacardTransformNullArgs() throws IOException, CatalogTransform public void testMetacardTransformNullMetacard() throws IOException, CatalogTransformerException { BinaryContent content = new GmdTransformer(gmdMetacardType).transform((Metacard) null, null); - String xml = IOUtils.toString(content.getInputStream()); + String xml = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8); assertThat(xml.trim(), is(XML_DECLARATION)); } diff --git a/catalog/spatial/geocoding/spatial-geocoding-websearch/src/test/java/org/codice/ddf/spatial/geocoder/geonames/GeoNamesWebServiceTest.java b/catalog/spatial/geocoding/spatial-geocoding-websearch/src/test/java/org/codice/ddf/spatial/geocoder/geonames/GeoNamesWebServiceTest.java index 896e8a4b4aa0..2bf30d57493a 100644 --- a/catalog/spatial/geocoding/spatial-geocoding-websearch/src/test/java/org/codice/ddf/spatial/geocoder/geonames/GeoNamesWebServiceTest.java +++ b/catalog/spatial/geocoding/spatial-geocoding-websearch/src/test/java/org/codice/ddf/spatial/geocoder/geonames/GeoNamesWebServiceTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.Optional; import javax.ws.rs.WebApplicationException; @@ -123,7 +124,8 @@ public void testGetLocation() throws IOException, GeoEntryQueryException { IOUtils.toString( GeoNamesWebServiceTest.class .getClassLoader() - .getResourceAsStream("getLocationTestResponse.json")); + .getResourceAsStream("getLocationTestResponse.json"), + StandardCharsets.UTF_8); prepareWebClient(response); diff --git a/catalog/spatial/kml/spatial-kml-transformer/src/test/java/org/codice/ddf/spatial/kml/transformer/KmzTransformerTest.java b/catalog/spatial/kml/spatial-kml-transformer/src/test/java/org/codice/ddf/spatial/kml/transformer/KmzTransformerTest.java index 0d1016471a89..d32bbbe09efe 100644 --- a/catalog/spatial/kml/spatial-kml-transformer/src/test/java/org/codice/ddf/spatial/kml/transformer/KmzTransformerTest.java +++ b/catalog/spatial/kml/spatial-kml-transformer/src/test/java/org/codice/ddf/spatial/kml/transformer/KmzTransformerTest.java @@ -126,12 +126,12 @@ private String getOutputFromBinaryContent(BinaryContent binaryContent) throws IO private String resourceToString(String resourceName) throws IOException { try (final InputStream inputStream = getResourceAsStream(resourceName)) { - return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); + return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } } private String readContentsFromZipInputStream(ZipInputStream zipInputStream) throws IOException { - String kmlDocument = IOUtils.toString(zipInputStream, StandardCharsets.UTF_8.name()); + String kmlDocument = IOUtils.toString(zipInputStream, StandardCharsets.UTF_8); IOUtils.closeQuietly(zipInputStream); return kmlDocument; } diff --git a/catalog/transformer/catalog-transformer-xml/src/test/java/ddf/catalog/transform/xml/XmlMetacardTransformerTest.java b/catalog/transformer/catalog-transformer-xml/src/test/java/ddf/catalog/transform/xml/XmlMetacardTransformerTest.java index 531f554f6388..61074847a728 100644 --- a/catalog/transformer/catalog-transformer-xml/src/test/java/ddf/catalog/transform/xml/XmlMetacardTransformerTest.java +++ b/catalog/transformer/catalog-transformer-xml/src/test/java/ddf/catalog/transform/xml/XmlMetacardTransformerTest.java @@ -29,6 +29,7 @@ import ddf.catalog.transformer.xml.XmlMetacardTransformer; import java.io.InputStream; import java.io.Serializable; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -156,7 +157,7 @@ public void testXmlMetacardTransformer() throws Exception { mc.setThumbnail(testThumbnail); InputStream input = getClass().getResourceAsStream("/extensibleMetacard.xml"); - String metadata = IOUtils.toString(input); + String metadata = IOUtils.toString(input, StandardCharsets.UTF_8); mc.setMetadata(metadata); String outputXml = transform(mc); diff --git a/platform/admin/core/admin-core-appservice/src/main/java/org/codice/ddf/admin/application/service/impl/ApplicationServiceImpl.java b/platform/admin/core/admin-core-appservice/src/main/java/org/codice/ddf/admin/application/service/impl/ApplicationServiceImpl.java index b3d1712eca2d..7f9af851ddf3 100644 --- a/platform/admin/core/admin-core-appservice/src/main/java/org/codice/ddf/admin/application/service/impl/ApplicationServiceImpl.java +++ b/platform/admin/core/admin-core-appservice/src/main/java/org/codice/ddf/admin/application/service/impl/ApplicationServiceImpl.java @@ -19,6 +19,7 @@ import ddf.security.service.SecurityServiceException; import java.io.File; import java.lang.reflect.InvocationTargetException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.security.AccessController; @@ -99,7 +100,8 @@ public Set getApplications() { try { String appJson = AccessController.doPrivileged( - (PrivilegedExceptionAction) () -> IOUtils.toString(appDef.toURI())); + (PrivilegedExceptionAction) + () -> IOUtils.toString(appDef.toURI(), StandardCharsets.UTF_8)); ApplicationImpl app = JsonUtils.fromJson(appJson, ApplicationImpl.class); if (isPermittedToViewFeature(app.getName())) { app.loadBundles(bundlesByLocation); diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/RequestImpl.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/RequestImpl.java index dac91466d647..311af062aae0 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/RequestImpl.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/RequestImpl.java @@ -17,14 +17,14 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opensaml.core.xml.AbstractXMLObject; import org.opensaml.core.xml.XMLObject; import org.opensaml.core.xml.schema.XSBooleanValue; -import org.opensaml.saml.common.AbstractSAMLObject; import org.opensaml.saml.common.SAMLObject; import org.opensaml.soap.soap11.ActorBearing; import org.opensaml.soap.soap11.MustUnderstandBearing; -public class RequestImpl extends AbstractSAMLObject +public class RequestImpl extends AbstractXMLObject implements Request, SAMLObject, MustUnderstandBearing, ActorBearing { private String responseConsumerURL; diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/ResponseImpl.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/ResponseImpl.java index 92a896c5d7ca..c4137644a308 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/ResponseImpl.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/liberty/paos/impl/ResponseImpl.java @@ -17,14 +17,14 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opensaml.core.xml.AbstractXMLObject; import org.opensaml.core.xml.XMLObject; import org.opensaml.core.xml.schema.XSBooleanValue; -import org.opensaml.saml.common.AbstractSAMLObject; import org.opensaml.saml.common.SAMLObject; import org.opensaml.soap.soap11.ActorBearing; import org.opensaml.soap.soap11.MustUnderstandBearing; -public class ResponseImpl extends AbstractSAMLObject +public class ResponseImpl extends AbstractXMLObject implements Response, SAMLObject, MustUnderstandBearing, ActorBearing { private String refToMessageID; diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/HtmlResponseTemplate.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/HtmlResponseTemplate.java index 3f3626ff1951..13a3146e74ec 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/HtmlResponseTemplate.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/HtmlResponseTemplate.java @@ -14,6 +14,7 @@ package ddf.security.samlp.impl; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,8 +31,8 @@ public class HtmlResponseTemplate { HtmlResponseTemplate.class.getResourceAsStream("/templates/submitFormTemplate.html"); InputStream redirectPageStream = HtmlResponseTemplate.class.getResourceAsStream("/templates/redirectTemplate.html")) { - submitTemplate = IOUtils.toString(submitFormStream); - redirectTemplate = IOUtils.toString(redirectPageStream); + submitTemplate = IOUtils.toString(submitFormStream, StandardCharsets.UTF_8); + redirectTemplate = IOUtils.toString(redirectPageStream, StandardCharsets.UTF_8); } catch (Exception e) { LOGGER.warn("Unable to load index page for IDP.", e); } diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/MetadataConfigurationParser.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/MetadataConfigurationParser.java index b068516628b4..fc48658e61fc 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/MetadataConfigurationParser.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/MetadataConfigurationParser.java @@ -307,7 +307,7 @@ private void validateMetadata(EntityDescriptor root) { "IDP metadata must either have cache duration or valid-until date." + " Defaulting IDP metadata cache duration to {}", SamlProtocol.getCacheDuration()); - root.setCacheDuration(SamlProtocol.getCacheDuration().toMillis()); + root.setCacheDuration(SamlProtocol.getCacheDuration()); } } } diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlProtocol.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlProtocol.java index e588b2e10e50..af8b161d67cf 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlProtocol.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlProtocol.java @@ -17,6 +17,7 @@ import ddf.security.samlp.LogoutWrapper; import java.io.StringReader; import java.time.Duration; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,7 +38,6 @@ import org.apache.wss4j.common.saml.OpenSAMLUtil; import org.apache.wss4j.common.saml.SamlAssertionWrapper; import org.codehaus.stax2.XMLInputFactory2; -import org.joda.time.DateTime; import org.opensaml.core.config.InitializationException; import org.opensaml.core.config.InitializationService; import org.opensaml.core.xml.XMLObject; @@ -242,7 +242,7 @@ public static Response createResponse( response.setIssuer(issuer); response.setStatus(status); response.setID("_" + UUID.randomUUID().toString()); - response.setIssueInstant(new DateTime()); + response.setIssueInstant(Instant.now()); response.setInResponseTo(requestId); response.setVersion(SAMLVersion.VERSION_20); if (samlAssertion != null) { @@ -283,7 +283,7 @@ public static Status createStatus(String statusValue) { public static Status createStatus(String statusValue, String message) { Status status = createStatus(statusValue); StatusMessage statusMessage = statusMessageBuilder.buildObject(); - statusMessage.setMessage(message); + statusMessage.setValue(message); status.setStatusMessage(statusMessage); return status; @@ -336,7 +336,7 @@ public static EntityDescriptor createIdpMetadata( for (String nameId : nameIds) { NameIDFormat nameIDFormat = nameIdFormatBuilder.buildObject(); - nameIDFormat.setFormat(nameId); + nameIDFormat.setValue(nameId); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); } @@ -369,7 +369,7 @@ public static EntityDescriptor createIdpMetadata( entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); - entityDescriptor.setCacheDuration(getCacheDuration().toMillis()); + entityDescriptor.setCacheDuration(getCacheDuration()); return entityDescriptor; } @@ -413,7 +413,7 @@ public static EntityDescriptor createSpMetadata( for (String nameId : nameIds) { NameIDFormat nameIDFormat = nameIdFormatBuilder.buildObject(); - nameIDFormat.setFormat(nameId); + nameIDFormat.setValue(nameId); spSsoDescriptor.getNameIDFormats().add(nameIDFormat); } @@ -452,7 +452,7 @@ public static EntityDescriptor createSpMetadata( entityDescriptor.getRoleDescriptors().add(spSsoDescriptor); - entityDescriptor.setCacheDuration(getCacheDuration().toMillis()); + entityDescriptor.setCacheDuration(getCacheDuration()); return entityDescriptor; } @@ -467,7 +467,7 @@ public static AttributeQuery createAttributeQuery( Issuer issuer, Subject subject, String destination) { AttributeQuery attributeQuery = attributeQueryBuilder.buildObject(); attributeQuery.setID(UUID.randomUUID().toString()); - attributeQuery.setIssueInstant(new DateTime()); + attributeQuery.setIssueInstant(Instant.now()); attributeQuery.setIssuer(issuer); attributeQuery.setSubject(subject); attributeQuery.setVersion(SAMLVersion.VERSION_20); @@ -487,12 +487,12 @@ public static LogoutWrapper createLogoutRequest( logoutRequest.setID(id); logoutRequest.setIssuer(issuer); logoutRequest.setNameID(nameId); - logoutRequest.setIssueInstant(DateTime.now()); + logoutRequest.setIssueInstant(Instant.now()); logoutRequest.setVersion(SAMLVersion.VERSION_20); SessionIndexBuilder builder = new SessionIndexBuilder(); for (String index : sessionIndexes) { SessionIndex sessionIndexObject = builder.buildObject(); - sessionIndexObject.setSessionIndex(index); + sessionIndexObject.setValue(index); logoutRequest.getSessionIndexes().add(sessionIndexObject); } return new LogoutWrapperImpl<>(logoutRequest); @@ -507,7 +507,7 @@ public static LogoutWrapper createLogoutResponse( if (StringUtils.isNotBlank(inResponseTo)) { logoutResponse.setInResponseTo(inResponseTo); } - logoutResponse.setIssueInstant(DateTime.now()); + logoutResponse.setIssueInstant(Instant.now()); logoutResponse.setVersion(SAMLVersion.VERSION_20); return new LogoutWrapperImpl<>(logoutResponse); } diff --git a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlValidator.java b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlValidator.java index e0f8f9fdf871..ad0455651888 100644 --- a/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlValidator.java +++ b/platform/security/core/security-core-impl/src/main/java/ddf/security/samlp/impl/SamlValidator.java @@ -25,7 +25,6 @@ import java.time.Instant; import javax.validation.constraints.NotNull; import org.codice.ddf.platform.util.HttpUtils; -import org.joda.time.DateTime; import org.opensaml.core.xml.XMLObject; import org.opensaml.saml.common.SAMLVersion; import org.opensaml.saml.common.SignableSAMLObject; @@ -55,18 +54,17 @@ public final void validate() throws ValidationException { } protected void checkTimestamp() throws ValidationException { - DateTime issueInstant = getIssueInstant(); + Instant issueInstant = getIssueInstant(); if (issueInstant == null) { throw new ValidationException("Issue Instant cannot be null!"); } - Instant instant = Instant.ofEpochMilli(issueInstant.getMillis()); Instant now = Instant.now(); - if (instant.minus(builder.clockSkew).isAfter(now)) { + if (issueInstant.minus(builder.clockSkew).isAfter(now)) { throw new ValidationException("Issue Instant cannot be in the future"); } - if (instant.plus(builder.clockSkew).isBefore(now.minus(builder.timeout))) { + if (issueInstant.plus(builder.clockSkew).isBefore(now.minus(builder.timeout))) { throw new ValidationException("Issue Instant was outside valid time range"); } } @@ -91,7 +89,7 @@ protected void checkId() throws ValidationException { // pass, default method } - protected abstract DateTime getIssueInstant(); + protected abstract Instant getIssueInstant(); protected abstract SAMLVersion getSamlVersion(); @@ -317,7 +315,7 @@ protected SAMLVersion getSamlVersion() { } @Override - protected DateTime getIssueInstant() { + protected Instant getIssueInstant() { return logoutRequest.getIssueInstant(); } @@ -362,7 +360,7 @@ protected SAMLVersion getSamlVersion() { } @Override - protected DateTime getIssueInstant() { + protected Instant getIssueInstant() { return logoutResponse.getIssueInstant(); } diff --git a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/MetadataConfigurationParserTest.java b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/MetadataConfigurationParserTest.java index a9f326c14f09..144f2cbd9b32 100644 --- a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/MetadataConfigurationParserTest.java +++ b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/MetadataConfigurationParserTest.java @@ -19,10 +19,12 @@ import static org.mockito.Mockito.doAnswer; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; import java.util.Collections; +import java.util.Date; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -36,7 +38,6 @@ import org.apache.http.impl.bootstrap.ServerBootstrap; import org.apache.http.protocol.HttpRequestHandler; import org.apache.wss4j.common.saml.OpenSAMLUtil; -import org.joda.time.DateTime; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -157,7 +158,8 @@ public void testMetadataStringCallback() throws Exception { private void metadataString(Consumer updateCallback) throws IOException { MetadataConfigurationParser metadataConfigurationParser = new MetadataConfigurationParser( - Collections.singletonList(IOUtils.toString(entityDescriptorPath.toUri())), + Collections.singletonList( + IOUtils.toString(entityDescriptorPath.toUri(), StandardCharsets.UTF_8)), updateCallback); Map entities = metadataConfigurationParser.getEntityDescriptors(); @@ -166,7 +168,7 @@ private void metadataString(Consumer updateCallback) throws IO @Test public void testMetadataHttp() throws Exception { - serverRespondsWith(IOUtils.toString(entityDescriptorPath.toUri())); + serverRespondsWith(IOUtils.toString(entityDescriptorPath.toUri(), StandardCharsets.UTF_8)); MetadataConfigurationParser metadataConfigurationParser = new MetadataConfigurationParser(Collections.singletonList("http://" + serverAddress)); @@ -200,23 +202,23 @@ public void testMetadataBadFile() throws Exception { @Test public void testRootElementNoCacheDuration() throws Exception { - String xml = IOUtils.toString(entityDescriptorPath.toUri()); + String xml = IOUtils.toString(entityDescriptorPath.toUri(), StandardCharsets.UTF_8); String xmlNoCacheDuration = xml.replaceFirst(CACHE_DURATION_REGEX, ""); EntityDescriptor entity = getEntityDescriptor(xmlNoCacheDuration); assertThat( String.format("Expected default cache duration %s milliseconds", SEVEN_DAYS), - entity.getCacheDuration(), + entity.getCacheDuration().toMillis(), is(SEVEN_DAYS)); } @Test public void testRootElementValidUntil() throws Exception { - String xml = IOUtils.toString(entityDescriptorPath.toUri()); - DateTime validUntil = DateTime.now().plusYears(1); - String validUntilXmlString = String.format("validUntil=\"%tF\"", validUntil.toDate()); + String xml = IOUtils.toString(entityDescriptorPath.toUri(), StandardCharsets.UTF_8); + Date validUntil = new Date(1000000L); + String validUntilXmlString = String.format("validUntil=\"%tF\"", validUntil); String xmlNoCacheDuration = xml.replaceFirst(CACHE_DURATION_REGEX, validUntilXmlString); EntityDescriptor entity = getEntityDescriptor(xmlNoCacheDuration); - boolean isSameDate = entity.getValidUntil().toLocalDate().isEqual(validUntil.toLocalDate()); + boolean isSameDate = validUntil.toInstant().compareTo(entity.getValidUntil()) >= 0; assertThat("Expected different valid-until date", isSameDate, is(true)); } diff --git a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SPMetadataParserTest.java b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SPMetadataParserTest.java index 297dc3ff7ab5..7dfc6215b57f 100644 --- a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SPMetadataParserTest.java +++ b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SPMetadataParserTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableSet; import ddf.security.samlp.impl.SamlProtocol.Binding; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -65,16 +66,19 @@ public static void setupClass() throws Exception { // read Certificate file into certificate certificate = IOUtils.toString( - SPMetadataParserTest.class.getClassLoader().getResourceAsStream(CERTIFICATE_NAME)); + SPMetadataParserTest.class.getClassLoader().getResourceAsStream(CERTIFICATE_NAME), + StandardCharsets.UTF_8); // read SPMetadata file into spMetadata List spMetadata = new ArrayList<>(); spMetadata.add( IOUtils.toString( - SPMetadataParserTest.class.getClassLoader().getResourceAsStream(METADATA_FILE))); + SPMetadataParserTest.class.getClassLoader().getResourceAsStream(METADATA_FILE), + StandardCharsets.UTF_8)); spMetadata.add( IOUtils.toString( - SPMetadataParserTest.class.getClassLoader().getResourceAsStream(METADATA_FILE_2))); + SPMetadataParserTest.class.getClassLoader().getResourceAsStream(METADATA_FILE_2), + StandardCharsets.UTF_8)); // set up binding set bindingSet = ImmutableSet.of(Binding.HTTP_POST, Binding.HTTP_REDIRECT, Binding.SOAP); diff --git a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SimpleSignTest.java b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SimpleSignTest.java index 5038b4516b96..87abe4688a80 100644 --- a/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SimpleSignTest.java +++ b/platform/security/core/security-core-impl/src/test/java/ddf/security/samlp/impl/SimpleSignTest.java @@ -29,6 +29,7 @@ import java.nio.charset.StandardCharsets; import java.security.Security; import java.security.cert.Certificate; +import java.time.Instant; import java.util.Base64; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; @@ -44,7 +45,6 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemWriter; -import org.joda.time.DateTime; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -157,7 +157,7 @@ public void testSignSamlObjectModifyAndResign() throws Exception { simpleSign.signSamlObject(response); final SubjectConfirmationData scd = new SubjectConfirmationDataBuilder().buildObject(); - scd.setNotOnOrAfter(DateTime.now().plusMinutes(30)); + scd.setNotOnOrAfter(Instant.now().plusSeconds(1800)); for (Assertion assertion : response.getAssertions()) { assertion .getSubject() diff --git a/platform/security/core/security-core-services/src/main/java/org/codice/ddf/security/jaxrs/impl/SamlSecurity.java b/platform/security/core/security-core-services/src/main/java/org/codice/ddf/security/jaxrs/impl/SamlSecurity.java index 95a8b7b236d4..2acfc7c6fc36 100644 --- a/platform/security/core/security-core-services/src/main/java/org/codice/ddf/security/jaxrs/impl/SamlSecurity.java +++ b/platform/security/core/security-core-services/src/main/java/org/codice/ddf/security/jaxrs/impl/SamlSecurity.java @@ -61,7 +61,7 @@ public String inflateBase64(String base64EncodedValue) throws IOException { InputStream is = new InflaterInputStream( new ByteArrayInputStream(deflatedValue), new Inflater(GZIP_COMPATIBLE)); - return IOUtils.toString(is, StandardCharsets.UTF_8.name()); + return IOUtils.toString(is, StandardCharsets.UTF_8); } /** diff --git a/platform/security/core/security-core-services/src/test/groovy/ddf/security/samlp/impl/LogoutMessageSpec.groovy b/platform/security/core/security-core-services/src/test/groovy/ddf/security/samlp/impl/LogoutMessageSpec.groovy index 75933cc0aadd..243ece832c1c 100644 --- a/platform/security/core/security-core-services/src/test/groovy/ddf/security/samlp/impl/LogoutMessageSpec.groovy +++ b/platform/security/core/security-core-services/src/test/groovy/ddf/security/samlp/impl/LogoutMessageSpec.groovy @@ -84,7 +84,7 @@ class LogoutMessageSpec extends Specification { SAMLVersion.VERSION_20.equals(logoutRequest.getMessage().version) logoutRequest.getMessage().sessionIndexes.size() == 1 SESSION_INDEX.equals(logoutRequest.getMessage().sessionIndexes.get(0).getSessionIndex()); - now().isAfter(Instant.ofEpochMilli(logoutRequest.getMessage().issueInstant.millis)) + now().isAfter(logoutRequest.getMessage().issueInstant) } def "build logout request with invalid info"() { @@ -121,7 +121,7 @@ class LogoutMessageSpec extends Specification { IN_RESPONSE_TO.equals(logoutResponse.getMessage().inResponseTo) SAMLVersion.VERSION_20.equals(logoutResponse.getMessage().version) !now(). - isBefore(Instant.ofEpochMilli(logoutResponse.getMessage().issueInstant.millis)) + isBefore(logoutResponse.getMessage().issueInstant) } def "build logout response with no inResponseTo"() { diff --git a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/AssertionConsumerService.java b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/AssertionConsumerService.java index 0af25add20b8..758d1b8e6904 100644 --- a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/AssertionConsumerService.java +++ b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/AssertionConsumerService.java @@ -154,7 +154,8 @@ public Response postSamlResponse( @Consumes({"text/xml", "application/soap+xml"}) public Response processSoapResponse(InputStream body, @Context HttpServletRequest request) { try { - SOAPPart soapMessage = SamlProtocol.parseSoapMessage(IOUtils.toString(body)); + SOAPPart soapMessage = + SamlProtocol.parseSoapMessage(IOUtils.toString(body, StandardCharsets.UTF_8)); String relayState = getRelayState(soapMessage); org.opensaml.saml.saml2.core.Response samlpResponse = getSamlpResponse(soapMessage); boolean validateResponse = validateResponse(samlpResponse, false); diff --git a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpHandler.java b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpHandler.java index ea7057224843..fbf335bbdf03 100644 --- a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpHandler.java +++ b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpHandler.java @@ -39,6 +39,7 @@ import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Base64; import java.util.List; import java.util.Map; @@ -73,7 +74,6 @@ import org.codice.ddf.security.handler.api.HandlerResult; import org.codice.ddf.security.jaxrs.SamlSecurity; import org.codice.ddf.security.util.SAMLUtils; -import org.joda.time.DateTime; import org.opensaml.core.config.ConfigurationService; import org.opensaml.core.xml.XMLObject; import org.opensaml.core.xml.XMLObjectBuilderFactory; @@ -590,7 +590,7 @@ private String createAndSignAuthnRequest(boolean isPost, boolean wantSigned) authnRequest.setID("_" + UUID.randomUUID().toString()); authnRequest.setVersion(SAMLVersion.VERSION_20); - authnRequest.setIssueInstant(new DateTime()); + authnRequest.setIssueInstant(Instant.now()); authnRequest.setDestination(idpMetadata.getSingleSignOnLocation()); @@ -606,7 +606,7 @@ private String createAndSignAuthnRequest(boolean isPost, boolean wantSigned) for (String authContextClass : authContextClasses) { if (StringUtils.isNotEmpty(authContextClass)) { AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(); - authnContextClassRef.setAuthnContextClassRef(authContextClass); + authnContextClassRef.setValue(authContextClass); requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef); } } diff --git a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpMetadata.java b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpMetadata.java index ecd3ff8d64dd..6bcd367afa4b 100644 --- a/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpMetadata.java +++ b/platform/security/handler/security-handler-saml/src/main/java/org/codice/ddf/security/idp/client/IdpMetadata.java @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; -import org.joda.time.DateTime; import org.opensaml.saml.saml2.metadata.Endpoint; import org.opensaml.saml.saml2.metadata.EntityDescriptor; import org.opensaml.saml.saml2.metadata.IDPSSODescriptor; @@ -310,10 +309,8 @@ protected class EntityData { created = null; } else { created = Instant.now(); - Long entityDuration = getEntityDescriptor().getCacheDuration(); - DateTime entityValidity = getEntityDescriptor().getValidUntil(); - this.cacheDuration = (entityDuration != null) ? Duration.ofMillis(entityDuration) : null; - this.validUntil = (entityValidity != null) ? entityValidity.toDate().toInstant() : null; + this.cacheDuration = getEntityDescriptor().getCacheDuration(); + this.validUntil = getEntityDescriptor().getValidUntil(); } } diff --git a/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/IdpMetadataTest.java b/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/IdpMetadataTest.java index 2ee8c3b93755..f2fe7c149dc3 100644 --- a/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/IdpMetadataTest.java +++ b/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/IdpMetadataTest.java @@ -24,6 +24,7 @@ import ddf.security.samlp.impl.SamlProtocol; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -50,7 +51,9 @@ public class IdpMetadataTest { @Before public void setup() throws IOException { metadata = new IdpMetadata(); - entityXml = IOUtils.toString(getClass().getResourceAsStream("/entityDescriptor.xml"), "UTF-8"); + entityXml = + IOUtils.toString( + getClass().getResourceAsStream("/entityDescriptor.xml"), StandardCharsets.UTF_8); System.setProperty("ddf.home", "./"); } diff --git a/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/LogoutRequestServiceTest.java b/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/LogoutRequestServiceTest.java index 49bef351817b..a5569d9bfbe5 100644 --- a/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/LogoutRequestServiceTest.java +++ b/platform/security/handler/security-handler-saml/src/test/java/org/codice/ddf/security/idp/client/LogoutRequestServiceTest.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.Instant; import java.util.Collections; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -65,7 +66,6 @@ import org.codice.ddf.platform.session.api.HttpSessionInvalidator; import org.codice.ddf.platform.util.uuidgenerator.UuidGenerator; import org.codice.ddf.security.jaxrs.impl.SamlSecurity; -import org.joda.time.DateTime; import org.junit.Before; import org.junit.Test; import org.opensaml.saml.common.SAMLVersion; @@ -224,9 +224,9 @@ public void testSendLogoutRequestInvalidNumberOfParams() throws Exception { String encryptedNameIdWithTime = nameId + "\n" + time; when(encryptionService.decrypt(any(String.class))).thenReturn(nameId); LogoutRequest logoutRequest = mock(LogoutRequest.class); - when(logoutRequest.getIssueInstant()).thenReturn(DateTime.now()); + when(logoutRequest.getIssueInstant()).thenReturn(Instant.now()); SessionIndex sessionIndex = mock(SessionIndex.class); - when(sessionIndex.getSessionIndex()).thenReturn(SESSION_INDEX); + when(sessionIndex.getValue()).thenReturn(SESSION_INDEX); when(logoutRequest.getSessionIndexes()).thenReturn(Collections.singletonList(sessionIndex)); logoutRequestService.setLogoutMessage(logoutMessage); Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime); @@ -268,9 +268,9 @@ public void testPostLogoutRequest() throws Exception { String encodedSamlRequest = "encodedSamlRequest"; String issuerStr = "issuer"; LogoutRequest logoutRequest = mock(LogoutRequest.class); - when(logoutRequest.getIssueInstant()).thenReturn(DateTime.now()); + when(logoutRequest.getIssueInstant()).thenReturn(Instant.now()); SessionIndex sessionIndex = mock(SessionIndex.class); - when(sessionIndex.getSessionIndex()).thenReturn(SESSION_INDEX); + when(sessionIndex.getValue()).thenReturn(SESSION_INDEX); when(logoutRequest.getSessionIndexes()).thenReturn(Collections.singletonList(sessionIndex)); LogoutWrapper requestLogoutWrapper = new LogoutWrapperImpl<>(logoutRequest); when(logoutMessage.extractSamlLogoutRequest(any(String.class))) @@ -279,7 +279,7 @@ public void testPostLogoutRequest() throws Exception { OpenSAMLUtil.initSamlEngine(); LogoutResponse logoutResponse = new LogoutResponseBuilder().buildObject(); when(logoutRequest.getIssuer()).thenReturn(issuer); - when(logoutRequest.getIssueInstant()).thenReturn(new DateTime()); + when(logoutRequest.getIssueInstant()).thenReturn(Instant.now()); when(logoutRequest.getVersion()).thenReturn(SAMLVersion.VERSION_20); when(logoutRequest.getID()).thenReturn("id"); when(issuer.getValue()).thenReturn(issuerStr); @@ -359,9 +359,9 @@ public void testSoapLogoutRequestNullLogoutMessage() throws Exception { public void testPostLogoutRequestNotParsable() throws Exception { String encodedSamlRequest = "encodedSamlRequest"; LogoutRequest logoutRequest = mock(LogoutRequest.class); - when(logoutRequest.getIssueInstant()).thenReturn(DateTime.now()); + when(logoutRequest.getIssueInstant()).thenReturn(Instant.now()); SessionIndex sessionIndex = mock(SessionIndex.class); - when(sessionIndex.getSessionIndex()).thenReturn(SESSION_INDEX); + when(sessionIndex.getValue()).thenReturn(SESSION_INDEX); when(logoutRequest.getSessionIndexes()).thenReturn(Collections.singletonList(sessionIndex)); insertLogoutRequest(); logoutRequestService.setLogoutMessage(logoutMessage); @@ -396,7 +396,7 @@ public void testPostLogoutRequestResponse() throws Exception { .thenReturn(responseLogoutWrapper); logoutRequestService.setLogoutMessage(logoutMessage); when(logoutResponse.getIssuer()).thenReturn(issuer); - when(logoutResponse.getIssueInstant()).thenReturn(new DateTime()); + when(logoutResponse.getIssueInstant()).thenReturn(Instant.now()); when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20); when(logoutResponse.getID()).thenReturn("id"); when(issuer.getValue()).thenReturn(issuerStr); @@ -413,9 +413,9 @@ public void testPostLogoutRequestResponse() throws Exception { @Test public void testPostLogoutRequestResponseNotParsable() throws Exception { LogoutRequest logoutRequest = mock(LogoutRequest.class); - when(logoutRequest.getIssueInstant()).thenReturn(DateTime.now()); + when(logoutRequest.getIssueInstant()).thenReturn(Instant.now()); SessionIndex sessionIndex = mock(SessionIndex.class); - when(sessionIndex.getSessionIndex()).thenReturn(SESSION_INDEX); + when(sessionIndex.getValue()).thenReturn(SESSION_INDEX); when(logoutRequest.getSessionIndexes()).thenReturn(Collections.singletonList(sessionIndex)); String encodedSamlResponse = "encodedSamlRequest"; when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(null); @@ -457,9 +457,9 @@ private void insertLogoutRequest() throws XMLStreamException, LogoutSecurityExce LogoutWrapper logoutRequestWrapper = mock(LogoutWrapper.class); doReturn(logoutRequest).when(logoutRequestWrapper).getMessage(); SessionIndex sessionIndex = mock(SessionIndex.class); - doReturn(SESSION_INDEX).when(sessionIndex).getSessionIndex(); + doReturn(SESSION_INDEX).when(sessionIndex).getValue(); doReturn((Collections.singletonList(sessionIndex))).when(logoutRequest).getSessionIndexes(); - doReturn(DateTime.now()).when(logoutRequest).getIssueInstant(); + doReturn(Instant.now()).when(logoutRequest).getIssueInstant(); doReturn(SAMLVersion.VERSION_20).when(logoutRequest).getVersion(); doReturn(ID).when(logoutRequest).getID(); doReturn(logoutRequestWrapper) @@ -519,7 +519,7 @@ public void testGetLogoutRequestResponse() throws Exception { SamlSecurity samlSecurity = new SamlSecurity(); String deflatedSamlResponse = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_RESPONSE); LogoutResponse logoutResponse = mock(LogoutResponse.class); - when(logoutResponse.getIssueInstant()).thenReturn(new DateTime()); + when(logoutResponse.getIssueInstant()).thenReturn(Instant.now()); when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20); when(logoutResponse.getID()).thenReturn("id"); LogoutWrapper responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse); @@ -570,7 +570,7 @@ public void testGetLogoutRequestNoSessionIndex() throws Exception { // No session index doReturn(Collections.EMPTY_LIST).when(logoutRequest).getSessionIndexes(); - doReturn(DateTime.now()).when(logoutRequest).getIssueInstant(); + doReturn(Instant.now()).when(logoutRequest).getIssueInstant(); doReturn(SAMLVersion.VERSION_20).when(logoutRequest).getVersion(); doReturn(ID).when(logoutRequest).getID(); doReturn(logoutRequestWrapper) diff --git a/platform/security/pep/security-pep-interceptor/src/main/java/ddf/security/pep/interceptor/SecurityAssertionStore.java b/platform/security/pep/security-pep-interceptor/src/main/java/ddf/security/pep/interceptor/SecurityAssertionStore.java index 236e3dbeb44d..43f0acfb6c6f 100644 --- a/platform/security/pep/security-pep-interceptor/src/main/java/ddf/security/pep/interceptor/SecurityAssertionStore.java +++ b/platform/security/pep/security-pep-interceptor/src/main/java/ddf/security/pep/interceptor/SecurityAssertionStore.java @@ -88,14 +88,8 @@ public static SecurityAssertion getSecurityAssertion(Message message) { new SecurityToken( id, samlAssertionWrapper.getElement(), - Instant.ofEpochMilli( - samlAssertionWrapper.getSaml2().getIssueInstant().getMillis()), - Instant.ofEpochMilli( - samlAssertionWrapper - .getSaml2() - .getConditions() - .getNotOnOrAfter() - .getMillis())); + samlAssertionWrapper.getSaml2().getIssueInstant(), + samlAssertionWrapper.getSaml2().getConditions().getNotOnOrAfter()); } else { // we don't know how long this should last or when it was created, so just // set it to 1 minute diff --git a/platform/security/rest/security-rest-cxfwrapper/src/main/java/org/codice/ddf/cxf/paos/PaosInInterceptor.java b/platform/security/rest/security-rest-cxfwrapper/src/main/java/org/codice/ddf/cxf/paos/PaosInInterceptor.java index d88265ab44c2..e3b6a05968f3 100644 --- a/platform/security/rest/security-rest-cxfwrapper/src/main/java/org/codice/ddf/cxf/paos/PaosInInterceptor.java +++ b/platform/security/rest/security-rest-cxfwrapper/src/main/java/org/codice/ddf/cxf/paos/PaosInInterceptor.java @@ -127,10 +127,10 @@ public PaosInInterceptor(String phase, SamlSecurity samlSecurity) { PaosInInterceptor.class.getResourceAsStream("/templates/security.handlebars"); InputStream userTokenStream = PaosInInterceptor.class.getResourceAsStream("/templates/username.handlebars")) { - soapMessage = IOUtils.toString(soapMessageStream); - soapfaultMessage = IOUtils.toString(soapfaultMessageStream); - securityHeader = IOUtils.toString(securityHeaderStream); - usernameToken = IOUtils.toString(userTokenStream); + soapMessage = IOUtils.toString(soapMessageStream, StandardCharsets.UTF_8); + soapfaultMessage = IOUtils.toString(soapfaultMessageStream, StandardCharsets.UTF_8); + securityHeader = IOUtils.toString(securityHeaderStream, StandardCharsets.UTF_8); + usernameToken = IOUtils.toString(userTokenStream, StandardCharsets.UTF_8); this.samlSecurity = samlSecurity; } catch (IOException e) { LOGGER.info("Unable to load templates for PAOS"); diff --git a/platform/security/saml/saml-assertion-validator-impl/src/main/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImpl.java b/platform/security/saml/saml-assertion-validator-impl/src/main/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImpl.java index fb45b35b331c..c7689a97d01e 100644 --- a/platform/security/saml/saml-assertion-validator-impl/src/main/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImpl.java +++ b/platform/security/saml/saml-assertion-validator-impl/src/main/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImpl.java @@ -24,6 +24,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.time.Instant; import java.util.Arrays; import java.util.Base64; import java.util.Collection; @@ -52,7 +53,6 @@ import org.codice.ddf.platform.util.properties.PropertiesLoader; import org.codice.ddf.security.handler.SAMLAuthenticationToken; import org.codice.ddf.security.saml.assertion.validator.SamlAssertionValidator; -import org.joda.time.DateTime; import org.opensaml.core.xml.XMLObjectBuilderFactory; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; import org.opensaml.saml.common.SAMLObjectBuilder; @@ -61,7 +61,6 @@ import org.opensaml.saml.saml2.core.Response; import org.opensaml.saml.saml2.core.Status; import org.opensaml.saml.saml2.core.StatusCode; -import org.opensaml.saml.saml2.core.StatusMessage; import org.opensaml.saml.saml2.core.SubjectConfirmation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,8 +95,6 @@ public class SamlAssertionValidatorImpl implements SamlAssertionValidator { private static SAMLObjectBuilder statusCodeBuilder; - private static SAMLObjectBuilder statusMessageBuilder; - private static SAMLObjectBuilder issuerBuilder; private static XMLObjectBuilderFactory builderFactory = @@ -142,10 +139,7 @@ public void validate(SAMLAuthenticationToken token) throws AuthenticationFailure // get the crypto junk Crypto crypto = getSignatureCrypto(); Response samlResponse = - createSamlResponse( - token.getRequestURI(), - assertion.getIssuerString(), - createStatus(SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null)); + createSamlResponse(token.getRequestURI(), assertion.getIssuerString(), createStatus()); BUILDER.get().reset(); Document doc = BUILDER.get().newDocument(); @@ -172,9 +166,7 @@ public void validate(SAMLAuthenticationToken token) throws AuthenticationFailure assertion.verifySignature(wsssamlKeyInfoProcessor, crypto); assertion.parseSubject( - new WSSSAMLKeyInfoProcessor(requestData), - requestData.getSigVerCrypto(), - requestData.getCallbackHandler()); + new WSSSAMLKeyInfoProcessor(requestData), requestData.getSigVerCrypto()); } assertionValidator.validate(credential, requestData); @@ -204,7 +196,7 @@ private static Response createSamlResponse(String inResponseTo, String issuer, S Response response = responseBuilder.buildObject(); response.setID(UUID.randomUUID().toString()); - response.setIssueInstant(new DateTime()); + response.setIssueInstant(Instant.now()); response.setInResponseTo(inResponseTo); response.setIssuer(createIssuer(issuer)); response.setStatus(status); @@ -216,11 +208,9 @@ private static Response createSamlResponse(String inResponseTo, String issuer, S /** * Creates the status object for the response. * - * @param statusCodeValue - * @param statusMessage * @return Status */ - private static Status createStatus(String statusCodeValue, String statusMessage) { + private static Status createStatus() { if (statusBuilder == null) { statusBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Status.DEFAULT_ELEMENT_NAME); @@ -230,24 +220,13 @@ private static Status createStatus(String statusCodeValue, String statusMessage) (SAMLObjectBuilder) builderFactory.getBuilder(StatusCode.DEFAULT_ELEMENT_NAME); } - if (statusMessageBuilder == null) { - statusMessageBuilder = - (SAMLObjectBuilder) - builderFactory.getBuilder(StatusMessage.DEFAULT_ELEMENT_NAME); - } Status status = statusBuilder.buildObject(); StatusCode statusCode = statusCodeBuilder.buildObject(); - statusCode.setValue(statusCodeValue); + statusCode.setValue(SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS); status.setStatusCode(statusCode); - if (statusMessage != null) { - StatusMessage statusMessageObject = statusMessageBuilder.buildObject(); - statusMessageObject.setMessage(statusMessage); - status.setStatusMessage(statusMessageObject); - } - return status; } diff --git a/platform/security/saml/saml-assertion-validator-impl/src/test/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImplTest.java b/platform/security/saml/saml-assertion-validator-impl/src/test/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImplTest.java index c7ad29b79561..5dbaa3f88efc 100644 --- a/platform/security/saml/saml-assertion-validator-impl/src/test/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImplTest.java +++ b/platform/security/saml/saml-assertion-validator-impl/src/test/java/org/codice/ddf/security/saml/assertion/validator/impl/SamlAssertionValidatorImplTest.java @@ -26,6 +26,8 @@ import java.security.PrivateKey; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.UUID; import org.apache.commons.io.IOUtils; import org.apache.cxf.helpers.DOMUtils; @@ -38,7 +40,6 @@ import org.codice.ddf.platform.filter.AuthenticationFailureException; import org.codice.ddf.security.handler.SAMLAuthenticationToken; import org.codice.ddf.security.util.SAMLUtils; -import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -148,7 +149,8 @@ public void setUp() throws Exception { @Test public void testValidateBearerAssertion() throws Exception { - Assertion assertion = createAssertion(true, true, ISSUER, new DateTime().plusDays(3)); + Assertion assertion = + createAssertion(true, true, ISSUER, Instant.now().plus(3, ChronoUnit.DAYS)); Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion)); @@ -184,7 +186,8 @@ public void testValidateWithHolderOfKeyAssertion() throws Exception { @Test(expected = AuthenticationFailureException.class) public void testValidateUnsignedAssertion() throws Exception { - Assertion assertion = createAssertion(false, true, ISSUER, new DateTime().plusDays(3)); + Assertion assertion = + createAssertion(false, true, ISSUER, Instant.now().plus(3, ChronoUnit.DAYS)); Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion)); @@ -215,7 +218,7 @@ public void testValidateIncorrectSamlVersion() throws Exception { @Test(expected = AuthenticationFailureException.class) public void testValidateExpiredAssertion() throws Exception { - Assertion assertion = createAssertion(false, true, ISSUER, new DateTime().minusSeconds(10)); + Assertion assertion = createAssertion(false, true, ISSUER, Instant.now().minusSeconds(10)); Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion)); @@ -230,7 +233,7 @@ public void testValidateExpiredAssertion() throws Exception { @Test(expected = AuthenticationFailureException.class) public void testValidateInvalidIssuer() throws Exception { - Assertion assertion = createAssertion(false, true, "WRONG", new DateTime().minusSeconds(10)); + Assertion assertion = createAssertion(false, true, "WRONG", Instant.now().minusSeconds(10)); Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion)); @@ -245,7 +248,7 @@ public void testValidateInvalidIssuer() throws Exception { @Test(expected = AuthenticationFailureException.class) public void testValidateInvalidSignature() throws Exception { - Assertion assertion = createAssertion(false, false, "WRONG", new DateTime().minusSeconds(10)); + Assertion assertion = createAssertion(false, false, "WRONG", Instant.now().minusSeconds(10)); Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion)); @@ -259,11 +262,11 @@ public void testValidateInvalidSignature() throws Exception { } private Assertion createAssertion( - boolean sign, boolean validSignature, String issuerString, DateTime notOnOrAfter) + boolean sign, boolean validSignature, String issuerString, Instant notOnOrAfter) throws Exception { Assertion assertion = new AssertionBuilder().buildObject(); assertion.setID(UUID.randomUUID().toString()); - assertion.setIssueInstant(new DateTime()); + assertion.setIssueInstant(Instant.now()); Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue(issuerString); @@ -283,16 +286,15 @@ private Assertion createAssertion( assertion.setSubject(subject); Conditions conditions = new ConditionsBuilder().buildObject(); - conditions.setNotBefore(new DateTime().minusDays(3)); + conditions.setNotBefore(Instant.now().minus(3, ChronoUnit.DAYS)); conditions.setNotOnOrAfter(notOnOrAfter); assertion.setConditions(conditions); AuthnStatement authnStatement = new AuthnStatementBuilder().buildObject(); - authnStatement.setAuthnInstant(new DateTime()); + authnStatement.setAuthnInstant(Instant.now()); AuthnContext authnContext = new AuthnContextBuilder().buildObject(); AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefBuilder().buildObject(); - authnContextClassRef.setAuthnContextClassRef( - "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"); + authnContextClassRef.setValue("urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"); authnContext.setAuthnContextClassRef(authnContextClassRef); authnStatement.setAuthnContext(authnContext); assertion.getAuthnStatements().add(authnStatement); @@ -342,7 +344,7 @@ private Assertion createAssertion( private Assertion createHolderOfKeyAssertion() throws Exception { Assertion assertion = new AssertionBuilder().buildObject(); assertion.setID(UUID.randomUUID().toString()); - assertion.setIssueInstant(new DateTime()); + assertion.setIssueInstant(Instant.now()); Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue(ISSUER); @@ -384,16 +386,15 @@ private Assertion createHolderOfKeyAssertion() throws Exception { assertion.setSubject(subject); Conditions conditions = new ConditionsBuilder().buildObject(); - conditions.setNotBefore(new DateTime().minusDays(3)); - conditions.setNotOnOrAfter(new DateTime().plusDays(3)); + conditions.setNotBefore(Instant.now().minus(3, ChronoUnit.DAYS)); + conditions.setNotOnOrAfter(Instant.now().plus(3, ChronoUnit.DAYS)); assertion.setConditions(conditions); AuthnStatement authnStatement = new AuthnStatementBuilder().buildObject(); - authnStatement.setAuthnInstant(new DateTime()); + authnStatement.setAuthnInstant(Instant.now()); AuthnContext authnContext = new AuthnContextBuilder().buildObject(); AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefBuilder().buildObject(); - authnContextClassRef.setAuthnContextClassRef( - "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"); + authnContextClassRef.setValue("urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"); authnContext.setAuthnContextClassRef(authnContextClassRef); authnStatement.setAuthnContext(authnContext); assertion.getAuthnStatements().add(authnStatement); diff --git a/pom.xml b/pom.xml index 1dcaf6f198fb..f4928f414d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ 1.13.0 1.6 4.7.0 - 0.1.8 + 0.2.0 1.5.2 3.5.3 2.25.0 @@ -256,7 +256,7 @@ 3.1 1.2.0 1.3.3 - 3.4.6 + 4.0.1 3.4.5_2 8.14.1 8.22 @@ -307,7 +307,7 @@ 6.5.1 4.2.1 3.1.1 - 2.3.4 + 3.0.4 2.7.3_3 2.7.3 2.12.2