Skip to content

Commit

Permalink
geoserver#161 Preserve the SRID of allowed area when retrieving it th…
Browse files Browse the repository at this point in the history
…rough AccessInfo
  • Loading branch information
taba90 committed Dec 14, 2020
1 parent 29c66c1 commit cb75c6e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ public AccessInfo toAccessInfo() {
ret.setAttributes(attributes == null ? null : new HashSet<LayerAttribute>(attributes));
ret.setCqlFilterRead(cqlFilterRead);
ret.setCqlFilterWrite(cqlFilterWrite);
if(area != null)
ret.setAreaWkt(area.toText());
if(area != null) {
String txtArea = area.toText();
if (area.getSRID()!=0){
txtArea="SRID="+area.getSRID()+";"+txtArea;
}
ret.setAreaWkt(txtArea);
}
ret.setCatalogMode(mapCatalogModeDTO(catalogMode));

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

package org.geoserver.geofence.services;

import org.geoserver.geofence.core.model.*;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.geoserver.geofence.core.model.GSUser;
import org.geoserver.geofence.core.model.IPAddressRange;
import org.geoserver.geofence.core.model.LayerAttribute;
import org.geoserver.geofence.core.model.LayerDetails;
import org.geoserver.geofence.core.model.UserGroup;
import org.geoserver.geofence.core.model.Rule;
import org.geoserver.geofence.core.model.enums.AccessType;
import org.geoserver.geofence.core.model.enums.GrantType;
import org.geoserver.geofence.services.dto.AccessInfo;
Expand All @@ -26,7 +22,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.geoserver.geofence.core.model.AdminRule;

import org.geoserver.geofence.core.model.enums.AdminGrantType;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -740,4 +736,53 @@ public void testAdminRules() {
assertTrue(accessInfo.getAdminRights());
}

@Test
public void testRuleLimitsAllowedAreaSRIDIsPreserved() throws NotFoundServiceEx, ParseException {
// test that the original SRID is present in the allowedArea wkt representation,
// when retrieving it from the AccessInfo object
Long id =null;
Long id2=null;
try {
{
Rule r1 = new Rule(10, null, null, null, null, "s1", "r1", "w1", "l1", GrantType.LIMIT);
ruleAdminService.insert(r1);
id = r1.getId();
}

{
Rule r2 = new Rule(11, null, null, null, null, "s1", "r1", "w1", "l1", GrantType.ALLOW);
id2 = ruleAdminService.insert(r2);
}

// save limits and check it has been saved
{
RuleLimits limits = new RuleLimits();
String wkt = "MULTIPOLYGON(((0.0016139656066815888 -0.0006386457758059581,0.0019599705696027314 -0.0006386457758059581,0.0019599705696027314 -0.0008854090051601674,0.0016139656066815888 -0.0008854090051601674,0.0016139656066815888 -0.0006386457758059581)))";
Geometry allowedArea = new WKTReader().read(wkt);
allowedArea.setSRID(3857);
limits.setAllowedArea((MultiPolygon) allowedArea);
ruleAdminService.setLimits(id, limits);
}

{
RuleFilter filter = new RuleFilter(SpecialFilterType.ANY, true);
filter.setWorkspace("w1");
filter.setService("s1");
filter.setRequest("r1");
filter.setLayer("l1");
AccessInfo accessInfo = ruleReaderService.getAccessInfo(filter);
String[] wktAr = accessInfo.getAreaWkt().split(";");
assertEquals("SRID=3857", wktAr[0]);

}
} finally {

if(id!=null)
ruleAdminService.delete(id);
if (id2!=null)
ruleAdminService.delete(id2);

}
}

}

0 comments on commit cb75c6e

Please sign in to comment.