Skip to content

Commit

Permalink
Enabled Authorization Provider for the raster data adapter plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitney O'Meara authored and rfecher committed Jul 22, 2016
1 parent f4d8740 commit 5d58750
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 31 deletions.
1 change: 1 addition & 0 deletions deploy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<exclude>*:servlet-api:*</exclude>
<exclude>*:*:jsr305</exclude>
<exclude>org.springframework.security:*</exclude>
<exclude>org.springframework:*</exclude>
<exclude>org.geoserver:*</exclude>
<exclude>xpp3:xpp3_min</exclude>
<exclude>xpp3:xpp3</exclude>
Expand Down
29 changes: 29 additions & 0 deletions extensions/adapters/auth/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>geowave-extension-parent</artifactId>
<groupId>mil.nga.giat</groupId>
<relativePath>../../</relativePath>
<version>0.9.2.1</version>
</parent>
<artifactId>geowave-adapter-auth</artifactId>
<name>GeoWave Adapter Auth</name>
<description>Authorization functionality for GeoWave Data Adapters</description>
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.net.URL;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

/**
* A provider that looks up authorizations given a user name.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.util.HashMap;
import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.net.URL;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

/**
* No authorization provided.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.net.URL;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mil.nga.giat.geowave.adapter.auth.JsonFileAuthorizationFactory
mil.nga.giat.geowave.adapter.auth.EmptyAuthorizationFactory
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mil.nga.giat.geowave.adapter.vector.auth;
package mil.nga.giat.geowave.adapter.auth;

import static org.junit.Assert.assertTrue;

Expand All @@ -8,6 +8,8 @@
import java.util.ArrayList;
import java.util.Arrays;

import mil.nga.giat.geowave.adapter.auth.AuthorizationSPI;
import mil.nga.giat.geowave.adapter.auth.JsonFileAuthorizationFactory;
import org.junit.Test;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down
5 changes: 5 additions & 0 deletions extensions/adapters/raster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
</dependency>
<dependency>
<groupId>mil.nga.giat</groupId>
<artifactId>geowave-adapter-auth</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mil.nga.giat</groupId>
<artifactId>geowave-core-mapreduce</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public RasterDataAdapter(
}

private void init() {
int supportedStatsLength = 3;
int supportedStatsLength = 2;

if (histogramConfig != null) {
supportedStatsLength++;
Expand All @@ -440,10 +440,10 @@ private void init() {
supportedStatsIds = new ByteArrayId[supportedStatsLength];
supportedStatsIds[0] = OverviewStatistics.STATS_ID;
supportedStatsIds[1] = BoundingBoxDataStatistics.STATS_ID;
supportedStatsIds[2] = RasterFootprintStatistics.STATS_ID;
// supportedStatsIds[2] = RasterFootprintStatistics.STATS_ID;

if (histogramConfig != null) {
supportedStatsIds[3] = HistogramStatistics.STATS_ID;
supportedStatsIds[2] = HistogramStatistics.STATS_ID;
}
visibilityHandler = new FieldIdStatisticVisibility<GridCoverage>(
DATA_FIELD_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.*;

import javax.media.jai.Interpolation;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import mil.nga.giat.geowave.adapter.auth.AuthorizationFactorySPI;
import mil.nga.giat.geowave.adapter.auth.EmptyAuthorizationFactory;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand All @@ -31,6 +34,7 @@
public class GeoWaveRasterConfig
{

static private final Logger LOGGER = Logger.getLogger(GeoWaveRasterConfig.class);
static private final Map<String, GeoWaveRasterConfig> CONFIG_CACHE = new Hashtable<String, GeoWaveRasterConfig>();

protected static enum ConfigParameter {
Expand All @@ -41,7 +45,11 @@ protected static enum ConfigParameter {
SCALE_TO_8BIT(
"scaleTo8Bit"),
EQUALIZE_HISTOGRAM(
"equalizeHistogramOverride");
"equalizeHistogramOverride"),
AUTHORIZATION_PROVIDER(
"authorizationProvider"),
AUTHORIZATION_URL(
"authorizationUrl");
private String configName;

private ConfigParameter(
Expand All @@ -61,6 +69,8 @@ public String getConfigName() {
private AdapterStore adapterStore;
private DataStatisticsStore dataStatisticsStore;
private AdapterIndexMappingStore adapterIndexMappingStore;
private AuthorizationFactorySPI authorizationFactory;
private URL authorizationURL;

private Boolean equalizeHistogramOverride = null;

Expand All @@ -78,6 +88,8 @@ public static GeoWaveRasterConfig createConfig(
geowaveNamespace,
null,
null,
null,
null,
null);
}

Expand All @@ -86,7 +98,9 @@ public static GeoWaveRasterConfig createConfig(
final String geowaveNamespace,
final Boolean equalizeHistogramOverride,
final Boolean scaleTo8Bit,
final Integer interpolationOverride ) {
final Integer interpolationOverride,
final String authorizationProvider,
final URL authorizationURL ) {
final GeoWaveRasterConfig result = new GeoWaveRasterConfig();
result.equalizeHistogramOverride = equalizeHistogramOverride;
result.interpolationOverride = interpolationOverride;
Expand All @@ -95,9 +109,44 @@ public static GeoWaveRasterConfig createConfig(
result.storeConfigObj = dataStoreConfig;
result.factoryFamily = GeoWaveStoreFinder.findStoreFamily(result.storeConfigObj);
}
result.authorizationFactory = getAuthorizationFactory(authorizationProvider);
result.authorizationURL = authorizationURL;
return result;
}

public static AuthorizationFactorySPI getAuthorizationFactory(
final String authProviderName ) {
if (authProviderName != null) {
final Iterator<AuthorizationFactorySPI> authIt = getAuthorizationFactoryList();
while (authIt.hasNext()) {
AuthorizationFactorySPI authFactory = authIt.next();
if (authProviderName.equals(authFactory.toString())) return authFactory;
}
}
return new EmptyAuthorizationFactory();
}

private static Iterator<AuthorizationFactorySPI> getAuthorizationFactoryList() {
final ServiceLoader<AuthorizationFactorySPI> ldr = ServiceLoader.load(AuthorizationFactorySPI.class);
return ldr.iterator();
}

public static URL getAuthorizationURL(
final String authorizationURL ) {
if (authorizationURL != null) {
try {
return new URL(
authorizationURL.toString());
}
catch (MalformedURLException e) {
LOGGER.warn(
"Accumulo Plugin: malformed Authorization Service URL " + authorizationURL,
e);
}
}
return null;
}

public static GeoWaveRasterConfig readFromConfigParams(
final String configParams )
throws Exception {
Expand Down Expand Up @@ -210,6 +259,19 @@ private static void parseParamsIntoRasterConfig(
if (params.containsKey(ConfigParameter.INTERPOLATION.getConfigName())) {
result.interpolationOverride = Integer.parseInt(params.get(ConfigParameter.INTERPOLATION.getConfigName()));
}

result.authorizationFactory = getAuthorizationFactory(params.get(ConfigParameter.AUTHORIZATION_PROVIDER
.getConfigName()));

result.authorizationURL = getAuthorizationURL(params.get(ConfigParameter.AUTHORIZATION_URL.getConfigName()));
}

protected AuthorizationFactorySPI getAuthorizationFactory() {
return authorizationFactory;
}

protected URL getAuthorizationURL() {
return authorizationURL;
}

public synchronized DataStore getDataStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.media.jai.ImageLayout;
import javax.media.jai.Interpolation;

import mil.nga.giat.geowave.adapter.auth.AuthorizationSPI;
import org.apache.log4j.Logger;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridEnvelope2D;
Expand Down Expand Up @@ -101,6 +102,8 @@ public class GeoWaveRasterReader extends

private AdapterIndexMappingStore geowaveAdapterIndexMappingStore;

private AuthorizationSPI authorizationSPI;

protected final static CoordinateOperationFactory OPERATION_FACTORY = new BufferedCoordinateOperationFactory(
new Hints(
Hints.LENIENT_DATUM_SHIFT,
Expand Down Expand Up @@ -191,6 +194,8 @@ private void init(
geowaveIndexStore = config.getIndexStore();
geowaveAdapterIndexMappingStore = config.getAdapterIndexMappingStore();
crs = GeoWaveGTRasterFormat.DEFAULT_CRS;
authorizationSPI = config.getAuthorizationFactory().create(
config.getAuthorizationURL());
}

/**
Expand Down Expand Up @@ -322,7 +327,8 @@ public GeneralEnvelope getOriginalEnvelope(
final DataStatistics<?> statistics = geowaveStatisticsStore.getDataStatistics(
new ByteArrayId(
coverageName),
BoundingBoxDataStatistics.STATS_ID);
BoundingBoxDataStatistics.STATS_ID,
authorizationSPI.getAuthorizations());
// try to use both the bounding box and the overview statistics to
// determine the width and height at the highest resolution
if (statistics instanceof BoundingBoxDataStatistics) {
Expand Down Expand Up @@ -362,7 +368,8 @@ public GridEnvelope getOriginalGridRange(
DataStatistics<?> statistics = geowaveStatisticsStore.getDataStatistics(
new ByteArrayId(
coverageName),
BoundingBoxDataStatistics.STATS_ID);
BoundingBoxDataStatistics.STATS_ID,
authorizationSPI.getAuthorizations());
int width = 0;
int height = 0;
// try to use both the bounding box and the overview statistics to
Expand All @@ -372,7 +379,8 @@ public GridEnvelope getOriginalGridRange(
statistics = geowaveStatisticsStore.getDataStatistics(
new ByteArrayId(
coverageName),
OverviewStatistics.STATS_ID);
OverviewStatistics.STATS_ID,
authorizationSPI.getAuthorizations());
if (statistics instanceof OverviewStatistics) {
final OverviewStatistics overviewStats = (OverviewStatistics) statistics;
width = (int) Math
Expand Down Expand Up @@ -803,11 +811,12 @@ private CloseableIterator<GridCoverage> queryForTiles(
// resolution
targetIndexStrategy.getIndexStrategy(),
rasterIndex.getIndexModel(),
rasterIndex.getId())), // make sure
rasterIndex.getId()), // make sure
// the
// index ID
// is
// the
authorizationSPI.getAuthorizations()),
// same as the orginal so that we
// are querying the correct table
query);
Expand All @@ -816,7 +825,8 @@ private CloseableIterator<GridCoverage> queryForTiles(
return geowaveDataStore.query(
new QueryOptions(
adapter,
rasterIndex),
rasterIndex,
authorizationSPI.getAuthorizations()),
query);
}
}
Expand Down Expand Up @@ -1033,7 +1043,8 @@ public double[][] getResolutionLevels(
final DataStatistics<?> stats = geowaveStatisticsStore.getDataStatistics(
new ByteArrayId(
coverageName),
OverviewStatistics.STATS_ID);
OverviewStatistics.STATS_ID,
authorizationSPI.getAuthorizations());
if ((stats != null) && (stats instanceof OverviewStatistics)) {
final Resolution[] resolutions = ((OverviewStatistics) stats).getResolutions();
final double[][] retVal = new double[resolutions.length][];
Expand All @@ -1054,7 +1065,8 @@ private Histogram getHistogram(
final DataStatistics<?> stats = geowaveStatisticsStore.getDataStatistics(
new ByteArrayId(
coverageName),
HistogramStatistics.STATS_ID);
HistogramStatistics.STATS_ID,
authorizationSPI.getAuthorizations());
if ((stats != null) && (stats instanceof HistogramStatistics)) {
return ((HistogramStatistics) stats).getHistogram(new Resolution(
new double[] {
Expand Down
5 changes: 5 additions & 0 deletions extensions/adapters/vector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
</dependency>
<dependency>
<groupId>mil.nga.giat</groupId>
<artifactId>geowave-adapter-auth</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mil.nga.giat</groupId>
<artifactId>geowave-core-ingest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import mil.nga.giat.geowave.adapter.vector.FeatureDataAdapter;
import mil.nga.giat.geowave.adapter.vector.GeotoolsFeatureDataAdapter;
import mil.nga.giat.geowave.adapter.vector.auth.AuthorizationSPI;
import mil.nga.giat.geowave.adapter.auth.AuthorizationSPI;
import mil.nga.giat.geowave.adapter.vector.index.IndexQueryStrategySPI;
import mil.nga.giat.geowave.adapter.vector.index.SimpleFeaturePrimaryIndexConfiguration;
import mil.nga.giat.geowave.adapter.vector.plugin.lock.LockingManagement;
Expand Down
Loading

0 comments on commit 5d58750

Please sign in to comment.