Skip to content

Bkalashi.basic auth support #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

3 changes: 2 additions & 1 deletion src/gov/nasa/worldwind/avlist/AVKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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_ENCODED_STRING = "gov.nasa.worldwind.avkey.BasicAuthEncodedString";
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";
Expand Down
7 changes: 7 additions & 0 deletions src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ public class WCS100Capabilities extends AbstractXMLEventParser
*/
public static WCS100Capabilities retrieve(URI uri) throws Exception
{
return retrieve(uri, null);
return retrieve(uri, null, 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
* @param basicAuthUsername Username for Basic Authentication
* @param basicAuthPassword 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
public static WCS100Capabilities retrieve(URI uri, String basicAuthUsername, String basicAuthPassword) throws Exception
{
try
{
CapabilitiesRequest request = new CapabilitiesRequest(uri, "WCS");
request.setVersion("1.0.0");

return new WCS100Capabilities(request.toString(), basicAuthenticationEncodedStr);
return new WCS100Capabilities(request.toString(), basicAuthUsername, basicAuthPassword);
}
catch (URISyntaxException e)
{
Expand All @@ -75,20 +75,21 @@ public static WCS100Capabilities retrieve(URI uri, String basicAuthenticationEnc

public WCS100Capabilities(Object docSource)
{
this(docSource, null);
this(docSource, null, null);
}

/**
* Constructs WCS100Capabilities with an optional Base64 Encoded String for Basic Authentication
*
* @param docSource
* @param basicAuthenticationEncodedStr Base 64 Encoded String
* @param basicAuthUsername Username for Basic Authentication
* @param basicAuthUsername Password for Basic Authentication
*/
public WCS100Capabilities(Object docSource, String basicAuthenticationEncodedStr)
public WCS100Capabilities(Object docSource, String basicAuthUsername, String basicAuthPassword)
{
super(OGCConstants.WCS_1_0_0_NAMESPACE_URI);

this.eventReader = this.createReader(docSource, basicAuthenticationEncodedStr);
this.eventReader = this.createReader(docSource, basicAuthUsername, basicAuthPassword);

this.initialize();
}
Expand All @@ -98,9 +99,9 @@ protected void initialize()
this.parserContext = this.createParserContext(this.eventReader);
}

protected XMLEventReader createReader(Object docSource, String basicAuthenticationEncodedStr)
protected XMLEventReader createReader(Object docSource, String basicAuthUsername, String basicAuthPassword)
{
return WWXML.openEventReader(docSource, basicAuthenticationEncodedStr);
return WWXML.openEventReader(docSource, basicAuthUsername, basicAuthPassword);
}

protected XMLEventParserContext createParserContext(XMLEventReader reader)
Expand Down
37 changes: 27 additions & 10 deletions src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@ public class WCS100DescribeCoverage extends AbstractXMLEventParser
protected XMLEventParserContext parserContext;
protected List<WCS100CoverageOffering> coverageOfferings = new ArrayList<WCS100CoverageOffering>(1);

public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName) throws URISyntaxException
{
return retrieve(uri, coverageName, null);
/**
* 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);
}

public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName, String basicAuthenticationEncodedStr) throws URISyntaxException
/**
* 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")
{
Expand All @@ -47,19 +64,19 @@ protected void initialize(String service)
}
};

return new WCS100DescribeCoverage(request.toString(), basicAuthenticationEncodedStr);
return new WCS100DescribeCoverage(request.toString(), basicAuthUsername, basicAuthPassword);
}

public WCS100DescribeCoverage(Object docSource)
{
this(docSource, null);
this(docSource, null, null);
}

public WCS100DescribeCoverage(Object docSource, String basicAuthenticationEncodedStr)
public WCS100DescribeCoverage(Object docSource, String basicAuthUsername, String basicAuthPassword)
{
super(OGCConstants.WCS_1_0_0_NAMESPACE_URI);

this.eventReader = this.createReader(docSource, basicAuthenticationEncodedStr);
this.eventReader = this.createReader(docSource, basicAuthUsername, basicAuthPassword);

this.initialize();
}
Expand All @@ -69,9 +86,9 @@ protected void initialize()
this.parserContext = this.createParserContext(this.eventReader);
}

protected XMLEventReader createReader(Object docSource, String basicAuthenticationEncodedStr)
protected XMLEventReader createReader(Object docSource, String basicAuthUsername, String basicAuthPassword)
{
return WWXML.openEventReader(docSource, basicAuthenticationEncodedStr);
return WWXML.openEventReader(docSource, basicAuthUsername, basicAuthPassword);
}

protected XMLEventParserContext createParserContext(XMLEventReader reader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/gov/nasa/worldwind/terrain/BasicElevationModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public BasicElevationModel(AVList params)
if (b != null)
this.setValue(AVKey.DELETE_CACHE_ON_EXIT, true);

basicAuthorizationString = params.getStringValue(AVKey.BASIC_AUTH_ENCODED_STRING);
String basicAuthUsername = params.getStringValue(AVKey.BASIC_AUTH_USERNAME);
String basicAuthPassword = params.getStringValue(AVKey.BASIC_AUTH_PASSWORD);
if(basicAuthUsername != null && basicAuthPassword != null) {
basicAuthorizationString = Base64.getEncoder().encodeToString(
(basicAuthUsername + ":" + basicAuthPassword).getBytes());
}

// Set some fallback values if not already set.
setFallbacks(params);
Expand Down
Loading