From d7616832c0759b17d03ee84517917c1fd437de1b Mon Sep 17 00:00:00 2001 From: bkalashi Date: Thu, 15 Sep 2022 09:12:18 -0400 Subject: [PATCH 1/2] Added optional basic authentication --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ src/gov/nasa/worldwind/avlist/AVKey.java | 1 + .../ogc/wcs/wcs100/WCS100Capabilities.java | 37 +++++- .../wcs/wcs100/WCS100DescribeCoverage.java | 18 ++- .../nasa/worldwind/retrieve/Retriever.java | 2 + .../nasa/worldwind/retrieve/URLRetriever.java | 11 ++ .../terrain/BasicElevationModel.java | 4 + .../worldwind/terrain/WCSElevationModel.java | 1 + src/gov/nasa/worldwind/util/WWXML.java | 69 +++++++++- 9 files changed, 254 insertions(+), 13 deletions(-) create mode 100644 .idea/uiDesigner.xml diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000..2b63946d5b --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/gov/nasa/worldwind/avlist/AVKey.java b/src/gov/nasa/worldwind/avlist/AVKey.java index fc5e961fc5..9daf820df1 100644 --- a/src/gov/nasa/worldwind/avlist/AVKey.java +++ b/src/gov/nasa/worldwind/avlist/AVKey.java @@ -34,6 +34,7 @@ public interface AVKey // TODO: Eliminate unused constants, if any final String BALLOON = "gov.nasa.worldwind.avkey.Balloon"; final String BALLOON_TEXT = "gov.nasa.worldwind.avkey.BalloonText"; final String BACK = "gov.nasa.worldwind.avkey.Back"; + final String BASIC_AUTH_ENCODED_STRING = "gov.nasa.worldwind.avkey.BasicAuthEncodedString"; final String BEGIN = "gov.nasa.worldwind.avkey.Begin"; final String BIG_ENDIAN = "gov.nasa.worldwind.avkey.BigEndian"; final String BOTTOM = "gov.nasa.worldwind.avkey.Bottom"; diff --git a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java index da5e498e24..5cfb2264bd 100644 --- a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java +++ b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java @@ -39,13 +39,31 @@ public class WCS100Capabilities extends AbstractXMLEventParser * if an error occurs retrieving the document. */ public static WCS100Capabilities retrieve(URI uri) throws Exception + { + return retrieve(uri, null); + } + + /** + * Retrieves the WCS capabilities document from a specified WCS server. + * + * @param uri The URI of the server. + * @param basicAuthenticationEncodedStr Base 64 Encoded String holding username/password ("username:password") + * for Basic Authentication + * + * @return The WCS capabilities document for the specified server. + * + * @throws IllegalArgumentException if the specified URI is invalid. + * @throws gov.nasa.worldwind.exception.WWRuntimeException + * if an error occurs retrieving the document. + */ + public static WCS100Capabilities retrieve(URI uri, String basicAuthenticationEncodedStr) throws Exception { try { CapabilitiesRequest request = new CapabilitiesRequest(uri, "WCS"); request.setVersion("1.0.0"); - return new WCS100Capabilities(request.toString()); + return new WCS100Capabilities(request.toString(), basicAuthenticationEncodedStr); } catch (URISyntaxException e) { @@ -56,10 +74,21 @@ public static WCS100Capabilities retrieve(URI uri) throws Exception } public WCS100Capabilities(Object docSource) + { + this(docSource, null); + } + + /** + * Constructs WCS100Capabilities with an optional Base64 Encoded String for Basic Authentication + * + * @param docSource + * @param basicAuthenticationEncodedStr Base 64 Encoded String + */ + public WCS100Capabilities(Object docSource, String basicAuthenticationEncodedStr) { super(OGCConstants.WCS_1_0_0_NAMESPACE_URI); - this.eventReader = this.createReader(docSource); + this.eventReader = this.createReader(docSource, basicAuthenticationEncodedStr); this.initialize(); } @@ -69,9 +98,9 @@ protected void initialize() this.parserContext = this.createParserContext(this.eventReader); } - protected XMLEventReader createReader(Object docSource) + protected XMLEventReader createReader(Object docSource, String basicAuthenticationEncodedStr) { - return WWXML.openEventReader(docSource); + return WWXML.openEventReader(docSource, basicAuthenticationEncodedStr); } protected XMLEventParserContext createParserContext(XMLEventReader reader) diff --git a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java index 70383934a7..ae54022681 100644 --- a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java +++ b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java @@ -29,6 +29,11 @@ public class WCS100DescribeCoverage extends AbstractXMLEventParser protected List coverageOfferings = new ArrayList(1); public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName) throws URISyntaxException + { + return retrieve(uri, coverageName, null); + } + + public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName, String basicAuthenticationEncodedStr) throws URISyntaxException { Request request = new Request(uri, "WCS") { @@ -42,14 +47,19 @@ protected void initialize(String service) } }; - return new WCS100DescribeCoverage(request.toString()); + return new WCS100DescribeCoverage(request.toString(), basicAuthenticationEncodedStr); } public WCS100DescribeCoverage(Object docSource) + { + this(docSource, null); + } + + public WCS100DescribeCoverage(Object docSource, String basicAuthenticationEncodedStr) { super(OGCConstants.WCS_1_0_0_NAMESPACE_URI); - this.eventReader = this.createReader(docSource); + this.eventReader = this.createReader(docSource, basicAuthenticationEncodedStr); this.initialize(); } @@ -59,9 +69,9 @@ protected void initialize() this.parserContext = this.createParserContext(this.eventReader); } - protected XMLEventReader createReader(Object docSource) + protected XMLEventReader createReader(Object docSource, String basicAuthenticationEncodedStr) { - return WWXML.openEventReader(docSource); + return WWXML.openEventReader(docSource, basicAuthenticationEncodedStr); } protected XMLEventParserContext createParserContext(XMLEventReader reader) diff --git a/src/gov/nasa/worldwind/retrieve/Retriever.java b/src/gov/nasa/worldwind/retrieve/Retriever.java index d79247adb9..27e4e5ea8f 100644 --- a/src/gov/nasa/worldwind/retrieve/Retriever.java +++ b/src/gov/nasa/worldwind/retrieve/Retriever.java @@ -64,4 +64,6 @@ public interface Retriever extends WWObject, java.util.concurrent.Callable + *
  • {@link URL}
  • {@link InputStream}
  • {@link File}
  • {@link String} containing a valid URL + * description or a file or resource name available on the classpath.
  • + * + * @param docSource the source of the XML document. + * @param basicAuthenticationEncodedStr Base 64 Encoded String holding username/password ("username:password") + * for Basic Authentication + * + * @return the source document as a {@link javax.xml.stream.XMLEventReader}, or null if the source object is a + * string that does not identify a URL, a file or a resource available on the classpath. + */ + public static XMLEventReader openEventReader(Object docSource, String basicAuthenticationEncodedStr) + { + return openEventReader(docSource, true, basicAuthenticationEncodedStr); } /** @@ -476,6 +517,24 @@ public static XMLEventReader openEventReader(Object docSource) * string that does not identify a URL, a file or a resource available on the classpath. */ public static XMLEventReader openEventReader(Object docSource, boolean isNamespaceAware) + { + return openEventReader(docSource, isNamespaceAware, null); + } + + /** + * Open an XML event stream from a general source. The source type may be one of the following:
    • {@link + * URL}
    • {@link InputStream}
    • {@link File}
    • {@link String} containing a valid URL + * description or a file or resource name available on the classpath.
    + * + * @param docSource the source of the XML document. + * @param isNamespaceAware true to enable namespace-aware processing and false to disable it. + * @param basicAuthenticationEncodedStr Base 64 Encoded String holding username/password ("username:password") + * for Basic Authentication + * + * @return the source document as a {@link javax.xml.stream.XMLEventReader}, or null if the source object is a + * string that does not identify a URL, a file or a resource available on the classpath. + */ + public static XMLEventReader openEventReader(Object docSource, boolean isNamespaceAware, String basicAuthenticationEncodedStr) { if (docSource == null || WWUtil.isEmpty(docSource)) { @@ -512,7 +571,7 @@ else if (!(docSource instanceof String)) URL url = WWIO.makeURL(sourceName); if (url != null) - return openEventReaderURL(url, isNamespaceAware); + return openEventReaderURL(url, isNamespaceAware, basicAuthenticationEncodedStr); return openEventReaderFile(sourceName, null, isNamespaceAware); } From 9763063c1cb4d2ae127441f35b56afdb1c811b47 Mon Sep 17 00:00:00 2001 From: bkalashi Date: Thu, 15 Sep 2022 12:49:39 -0400 Subject: [PATCH 2/2] support basic auth --- src/gov/nasa/worldwind/avlist/AVKey.java | 2 ++ .../worldwind/layers/rpf/RPFRetriever.java | 7 +++++ .../wcs/wcs100/WCS100DescribeCoverage.java | 28 +++++++++++++++++++ .../retrieve/LocalRasterServerRetriever.java | 7 ++++- .../nasa/worldwind/retrieve/Retriever.java | 2 ++ .../nasa/worldwind/retrieve/URLRetriever.java | 11 ++++++++ .../terrain/BasicElevationModel.java | 9 ++++++ 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/gov/nasa/worldwind/avlist/AVKey.java b/src/gov/nasa/worldwind/avlist/AVKey.java index fc5e961fc5..4251c0e499 100644 --- a/src/gov/nasa/worldwind/avlist/AVKey.java +++ b/src/gov/nasa/worldwind/avlist/AVKey.java @@ -34,6 +34,8 @@ public interface AVKey // TODO: Eliminate unused constants, if any final String BALLOON = "gov.nasa.worldwind.avkey.Balloon"; final String BALLOON_TEXT = "gov.nasa.worldwind.avkey.BalloonText"; final String BACK = "gov.nasa.worldwind.avkey.Back"; + final String BASIC_AUTH_USERNAME = "gov.nasa.worldwind.avkey.BasicAuthUsername"; + final String BASIC_AUTH_PASSWORD = "gov.nasa.worldwind.avkey.BasicAuthPassword"; final String BEGIN = "gov.nasa.worldwind.avkey.Begin"; final String BIG_ENDIAN = "gov.nasa.worldwind.avkey.BigEndian"; final String BOTTOM = "gov.nasa.worldwind.avkey.Bottom"; diff --git a/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java b/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java index 63fa5edf4f..ead7618229 100644 --- a/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java +++ b/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java @@ -43,6 +43,8 @@ class RPFRetriever extends WWObjectImpl implements Retriever public static final int RESPONSE_CODE_OK = 1; public static final int RESPONSE_CODE_NO_CONTENT = 2; + protected String basicAuthenticationEncodedString; + public RPFRetriever(RPFGenerator.RPFServiceInstance service, URL url, RetrievalPostProcessor postProcessor) { if (service == null) @@ -174,6 +176,11 @@ public void setStaleRequestLimit(int staleRequestLimit) this.staleRequestLimit = staleRequestLimit; } + @Override + public void setBasicAuthentication(String basicAuthorizationString) { + this.basicAuthenticationEncodedString = basicAuthorizationString; + } + public final RPFGenerator.RPFServiceInstance getService() { return this.service; diff --git a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java index 70383934a7..6081d5a9f0 100644 --- a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java +++ b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java @@ -28,7 +28,30 @@ public class WCS100DescribeCoverage extends AbstractXMLEventParser protected XMLEventParserContext parserContext; protected List coverageOfferings = new ArrayList(1); + /** + * Retrieve WCS 100 Coverage + * + * @param uri uri + * @param coverageName name of coverage + * @return WCS100DescribeCoverage + * @throws URISyntaxException URI Syntax incorrect + */ public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName) throws URISyntaxException + { + return retrieve(uri, coverageName, null, null); + } + + /** + * Retrieve WCS 100 Coverage + * + * @param uri uri + * @param coverageName name of coverage + * @param basicAuthUsername Basic Authentication Username + * @param basicAuthPassword Basic Authentication Password + * @return WCS100DescribeCoverage + * @throws URISyntaxException URI Syntax incorrect + */ + public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName, String basicAuthUsername, String basicAuthPassword) throws URISyntaxException { Request request = new Request(uri, "WCS") { @@ -46,6 +69,11 @@ protected void initialize(String service) } public WCS100DescribeCoverage(Object docSource) + { + this(docSource, null, null); + } + + public WCS100DescribeCoverage(Object docSource, String basicAuthUsername, String basicAuthPassword) { super(OGCConstants.WCS_1_0_0_NAMESPACE_URI); diff --git a/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java b/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java index c3505e7e1b..2e3eb5e5fa 100644 --- a/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java +++ b/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java @@ -34,7 +34,7 @@ public class LocalRasterServerRetriever extends WWObjectImpl implements Retrieve protected long submitTime; protected long beginTime; protected long endTime; - + protected String basicAuthenticationEncodedString; public LocalRasterServerRetriever(AVList params, RasterServer rasterServer, RetrievalPostProcessor postProcessor) { if (null != params) @@ -155,6 +155,11 @@ public void setStaleRequestLimit(int staleRequestLimit) this.staleRequestLimit = staleRequestLimit; } + @Override + public void setBasicAuthentication(String basicAuthorizationString) { + this.basicAuthenticationEncodedString = basicAuthorizationString; + } + public Retriever call() throws Exception { try diff --git a/src/gov/nasa/worldwind/retrieve/Retriever.java b/src/gov/nasa/worldwind/retrieve/Retriever.java index d79247adb9..27e4e5ea8f 100644 --- a/src/gov/nasa/worldwind/retrieve/Retriever.java +++ b/src/gov/nasa/worldwind/retrieve/Retriever.java @@ -64,4 +64,6 @@ public interface Retriever extends WWObject, java.util.concurrent.Callable