diff --git a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTBatchOperation.java b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTBatchOperation.java index ff4744d0..b0a8f219 100644 --- a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTBatchOperation.java +++ b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTBatchOperation.java @@ -23,7 +23,8 @@ public enum ServiceName { users, groups, instances, - rules + rules, + adminrules } public enum TypeName { @@ -99,7 +100,8 @@ public void setCascade(Boolean cascade) { @XmlElement(name="user", type=RESTInputUser.class), @XmlElement(name="userGroup", type=RESTInputGroup.class), @XmlElement(name="instance", type=RESTInputInstance.class), - @XmlElement(name="rule", type=RESTInputRule.class) + @XmlElement(name="rule", type=RESTInputRule.class), + @XmlElement(name="adminrule", type=RESTInputAdminRule.class), }) public AbstractRESTPayload getPayload() { return payload; diff --git a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputAdminRule.java b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputAdminRule.java index 933a27e7..69b5b6c0 100644 --- a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputAdminRule.java +++ b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputAdminRule.java @@ -18,7 +18,7 @@ * @author Etj (etj at geo-solutions.it) */ @XmlRootElement(name = "adminrule") -@XmlType(name="Rule", propOrder={"position","grant","username","rolename","instance","workspace"}) +@XmlType(name="AminRule", propOrder={"position","grant","username","rolename","instance","workspace"}) public class RESTInputAdminRule extends AbstractRESTPayload { private RESTRulePosition position; diff --git a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputRule.java b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputRule.java index f30c5319..fc068207 100644 --- a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputRule.java +++ b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTInputRule.java @@ -18,7 +18,7 @@ * @author Etj (etj at geo-solutions.it) */ @XmlRootElement(name = "rule") -@XmlType(name="Rule", propOrder={"position","grant","username","rolename","instance","ipaddress","service","request","workspace","layer","constraints"}) +@XmlType(name="Rule", propOrder={"position","grant","username","rolename","instance","ipaddress","service","request","workspace","layer","limits","constraints"}) public class RESTInputRule extends AbstractRESTPayload { private RESTRulePosition position; @@ -38,6 +38,8 @@ public class RESTInputRule extends AbstractRESTPayload { private GrantType grant; + private RESTRuleLimits limits; + private RESTLayerConstraints constraints; public RESTInputRule() { @@ -118,6 +120,13 @@ public void setWorkspace(String workspace) { } + public RESTRuleLimits getLimits() { + return limits; + } + + public void setLimits(RESTRuleLimits limits) { + this.limits = limits; + } public RESTLayerConstraints getConstraints() { return constraints; diff --git a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTOutputRule.java b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTOutputRule.java index f4ef7b24..323b6272 100644 --- a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTOutputRule.java +++ b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTOutputRule.java @@ -20,7 +20,7 @@ * @author Etj (etj at geo-solutions.it) */ @XmlRootElement(name = "Rule") -@XmlType(propOrder={"id", "priority","grant","username","rolename","instance","ipaddress","service","request","workspace","layer","constraints"}) +@XmlType(propOrder={"id", "priority","grant","username","rolename","instance","ipaddress","service","request","workspace","layer","limits","constraints"}) public class RESTOutputRule implements Serializable { private Long id; @@ -43,6 +43,8 @@ public class RESTOutputRule implements Serializable { private RESTLayerConstraints constraints; + private RESTRuleLimits limits; + public RESTOutputRule() { } @@ -126,10 +128,18 @@ public RESTLayerConstraints getConstraints() { return constraints; } + public RESTRuleLimits getLimits() { + return limits; + } + public void setConstraints(RESTLayerConstraints constraints) { this.constraints = constraints; } + public void setLimits(RESTRuleLimits limits) { + this.limits = limits; + } + public Long getPriority() { return priority; } diff --git a/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTRuleLimits.java b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTRuleLimits.java new file mode 100644 index 00000000..1c6756cf --- /dev/null +++ b/src/services/modules/rest/api/src/main/java/org/geoserver/geofence/services/rest/model/RESTRuleLimits.java @@ -0,0 +1,53 @@ +/* (c) 2022 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.services.rest.model; + +import org.geoserver.geofence.core.model.enums.CatalogMode; +import org.geoserver.geofence.core.model.enums.SpatialFilterType; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlRootElement(name = "Limits") +@XmlType(propOrder={"restrictedAreaWkt","spatialFilterType","catalogMode"}) +public class RESTRuleLimits { + + private String restrictedAreaWkt; + private SpatialFilterType spatialFilterType; + private CatalogMode catalogMode; + + public String getRestrictedAreaWkt() { + return restrictedAreaWkt; + } + + public void setRestrictedAreaWkt(String restrictedAreaWkt) { + this.restrictedAreaWkt = restrictedAreaWkt; + } + + public SpatialFilterType getSpatialFilterType() { + return spatialFilterType; + } + + public void setSpatialFilterType(SpatialFilterType spatialFilterType) { + this.spatialFilterType = spatialFilterType; + } + + public CatalogMode getCatalogMode() { + return catalogMode; + } + + public void setCatalogMode(CatalogMode catalogMode) { + this.catalogMode = catalogMode; + } + + @Override + public String toString() { + return "RESTRuleLimits{" + + "restrictedAreaWkt='" + restrictedAreaWkt + '\'' + + ", spatialFilterType=" + spatialFilterType + + ", catalogMode=" + catalogMode + + '}'; + } +} diff --git a/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImpl.java b/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImpl.java index 89247a2f..3243bd32 100644 --- a/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImpl.java +++ b/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImpl.java @@ -5,6 +5,7 @@ package org.geoserver.geofence.services.rest.impl; +import org.geoserver.geofence.services.rest.RESTAdminRuleService; import org.geoserver.geofence.services.rest.RESTBatchService; import org.geoserver.geofence.services.rest.RESTGSInstanceService; import org.geoserver.geofence.services.rest.RESTRuleService; @@ -17,6 +18,7 @@ import org.geoserver.geofence.services.rest.exception.NotFoundRestEx; import org.geoserver.geofence.services.rest.model.RESTBatch; import org.geoserver.geofence.services.rest.model.RESTBatchOperation; +import org.geoserver.geofence.services.rest.model.RESTInputAdminRule; import org.geoserver.geofence.services.rest.model.RESTInputGroup; import org.geoserver.geofence.services.rest.model.RESTInputInstance; import org.geoserver.geofence.services.rest.model.RESTInputRule; @@ -53,6 +55,7 @@ public class RESTBatchServiceImpl private RESTUserGroupService restUserGroupService; private RESTGSInstanceService restInstanceService; private RESTRuleService restRuleService; + private RESTAdminRuleService restAdminRuleService; @Transactional(value="geofenceTransactionManager") @Override @@ -90,6 +93,10 @@ public void runBatch(RESTBatch batch) throws BadRequestRestEx, NotFoundRestEx, I dispatchRuleOp(op); break; + case adminrules: + dispatchAdminRuleOp(op); + break; + default: throw new BadRequestRestEx("Unhandled service for operation " + op); } @@ -237,6 +244,33 @@ else if(op.getId() != null) } } + protected void dispatchAdminRuleOp(RESTBatchOperation op) throws NotFoundRestEx, BadRequestRestEx { + switch (op.getType()) { + case insert: + ensurePayload(op); + restAdminRuleService.insert((RESTInputAdminRule) op.getPayload()); + break; + + case update: + ensurePayload(op); + if (op.getId() != null) + restAdminRuleService.update(op.getId(), (RESTInputAdminRule) op.getPayload()); + else + throw new BadRequestRestEx("Missing identifier for op " + op); + break; + + case delete: + if (op.getId() != null) + restAdminRuleService.delete(op.getId()); + else + throw new BadRequestRestEx("Missing identifier for op " + op); + break; + + default: + throw new BadRequestRestEx("Operation not bound " + op); + } + } + // ========================================================================== private void ensurePayload(RESTBatchOperation op) throws BadRequestRestEx { @@ -273,4 +307,7 @@ public void setRestUserService(RESTUserService restUserService) { this.restUserService = restUserService; } + public void setRestAdminRuleService(RESTAdminRuleService restAdminRuleService) { + this.restAdminRuleService = restAdminRuleService; + } } diff --git a/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImpl.java b/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImpl.java index ca5f237c..37b83e01 100644 --- a/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImpl.java +++ b/src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImpl.java @@ -5,8 +5,10 @@ package org.geoserver.geofence.services.rest.impl; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -14,6 +16,8 @@ import org.apache.commons.lang.StringUtils; +import org.geoserver.geofence.core.model.RuleLimits; +import org.geoserver.geofence.services.rest.model.RESTRuleLimits; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.io.ParseException; @@ -55,6 +59,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Comparator; +import java.util.stream.Collectors; /** * @@ -115,6 +120,11 @@ public Response insert(RESTInputRule inputRule) throws NotFoundRestEx, BadReques ruleAdminService.setDetails(id, details); } + RuleLimits limits=limitsFromInput(inputRule.getLimits()); + if (limits!=null) { + ruleAdminService.setLimits(id,limits); + } + return Response.status(Status.CREATED).tag(id.toString()).entity(id).build(); } catch (BadRequestServiceEx ex) { LOGGER.error(ex.getMessage()); @@ -125,6 +135,13 @@ public Response insert(RESTInputRule inputRule) throws NotFoundRestEx, BadReques } } + private InsertPosition insertPosition(RESTInputRule inputRule){ + return + inputRule.getPosition().getPosition() == RulePosition.fixedPriority ? InsertPosition.FIXED + : inputRule.getPosition().getPosition() == RulePosition.offsetFromBottom ? InsertPosition.FROM_END + : inputRule.getPosition().getPosition() == RulePosition.offsetFromTop ? InsertPosition.FROM_START : null; + } + @Override public void update(Long id, RESTInputRule rule) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { @@ -579,6 +596,25 @@ protected RESTOutputRule toOutput(Rule rule) { out.setConstraints(constraints); } + if (rule.getRuleLimits()!=null){ + RESTRuleLimits ruleLimits=new RESTRuleLimits(); + RuleLimits limits=rule.getRuleLimits(); + if (limits.getSpatialFilterType()!=null) + ruleLimits.setSpatialFilterType(limits.getSpatialFilterType()); + if (limits.getCatalogMode()!=null) + ruleLimits.setCatalogMode(limits.getCatalogMode()); + if (limits.getAllowedArea()!=null) { + MultiPolygon area = limits.getAllowedArea(); + if (area != null) { + String areaWKT = "SRID=" + area.getSRID() + ";" + area.toText(); + ruleLimits.setRestrictedAreaWkt(areaWKT); + } + if (limits.getSpatialFilterType()!=null) + ruleLimits.setSpatialFilterType(limits.getSpatialFilterType()); + } + out.setLimits(ruleLimits); + } + return out; } @@ -608,6 +644,28 @@ protected Rule fromInput(RESTInputRule in) { return rule; } + protected RuleLimits limitsFromInput(RESTRuleLimits in){ + RuleLimits limits=null; + if (in!=null && (in.getCatalogMode()!=null || in.getRestrictedAreaWkt()!=null)){ + limits=new RuleLimits(); + limits.setCatalogMode(in.getCatalogMode()); + limits.setSpatialFilterType(in.getSpatialFilterType()); + if (StringUtils.isNotBlank(in.getRestrictedAreaWkt())) { + if (in.getRestrictedAreaWkt() != null) { + Geometry g; + try { + g = toGeometryAllowedArea(in.getRestrictedAreaWkt()); + } catch (ParseException ex) { + throw new BadRequestRestEx("Error parsing WKT:" + ex.getMessage()); + } + limits.setAllowedArea((MultiPolygon) g); + } + } + } + return limits; + } + + protected LayerDetails detailsFromInput(RESTInputRule in) { RESTLayerConstraints constraints = in.getConstraints(); if (constraints != null) { diff --git a/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBaseTest.java b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBaseTest.java index 53bb3590..b97170a3 100644 --- a/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBaseTest.java +++ b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBaseTest.java @@ -7,6 +7,8 @@ import org.geoserver.geofence.services.RuleAdminService; import org.geoserver.geofence.services.dto.ShortGroup; +import org.geoserver.geofence.services.rest.RESTAdminRuleService; +import org.geoserver.geofence.services.rest.RESTBatchService; import org.geoserver.geofence.services.rest.RESTRuleService; import org.geoserver.geofence.services.rest.RESTUserGroupService; import org.geoserver.geofence.services.rest.RESTUserService; @@ -39,6 +41,8 @@ public abstract class RESTBaseTest { protected static RESTUserService restUserService; protected static RESTUserGroupService restUserGroupService; protected static RESTRuleService restRuleService; + protected static RESTAdminRuleService restAdminRuleService; + protected static RESTBatchService restBatchService; public RESTBaseTest() { @@ -59,11 +63,15 @@ public RESTBaseTest() { restUserService = (RESTUserService)ctx.getBean("restUserService"); restUserGroupService = (RESTUserGroupService)ctx.getBean("restUserGroupService"); restRuleService = (RESTRuleService)ctx.getBean("restRuleService"); + restAdminRuleService = (RESTAdminRuleService)ctx.getBean("restAdminRuleService"); + restBatchService = (RESTBatchService) ctx.getBean("restBatchService"); } assertNotNull(restUserService); assertNotNull(restUserGroupService); assertNotNull(restRuleService); + assertNotNull(restAdminRuleService); + assertNotNull(restBatchService); } } diff --git a/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImplTest.java b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImplTest.java new file mode 100644 index 00000000..9b1d108e --- /dev/null +++ b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTBatchServiceImplTest.java @@ -0,0 +1,131 @@ +package org.geoserver.geofence.services.rest.impl; + +import org.geoserver.geofence.core.model.enums.AdminGrantType; +import org.geoserver.geofence.core.model.enums.GrantType; +import org.geoserver.geofence.services.rest.exception.BadRequestRestEx; +import org.geoserver.geofence.services.rest.model.RESTBatch; +import org.geoserver.geofence.services.rest.model.RESTBatchOperation; +import org.geoserver.geofence.services.rest.model.RESTInputAdminRule; +import org.geoserver.geofence.services.rest.model.RESTInputGroup; +import org.geoserver.geofence.services.rest.model.RESTInputRule; +import org.geoserver.geofence.services.rest.model.RESTInputUser; +import org.geoserver.geofence.services.rest.model.RESTOutputRule; +import org.geoserver.geofence.services.rest.model.RESTRulePosition; +import org.geoserver.geofence.services.rest.model.util.IdName; +import org.geoserver.geofence.services.rest.model.util.RESTBatchOperationFactory; +import org.junit.Test; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +public class RESTBatchServiceImplTest extends RESTBaseTest { + + + @Test + public void testBatchInsertAdminRule() { + RESTInputAdminRule adminRule=new RESTInputAdminRule(); + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule.setWorkspace("ws99"); + adminRule.setRolename("roleName00"); + adminRule.setGrant(AdminGrantType.ADMIN); + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation.setType(RESTBatchOperation.TypeName.insert); + restBatchOperation.setPayload(adminRule); + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule2.setWorkspace("ws999"); + adminRule2.setRolename("roleName00"); + adminRule2.setGrant(AdminGrantType.USER); + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation2.setType(RESTBatchOperation.TypeName.insert); + restBatchOperation2.setPayload(adminRule2); + RESTBatch restBatch=new RESTBatch(); + restBatch.add(restBatchOperation); + restBatch.add(restBatchOperation2); + assertEquals(200,restBatchService.exec(restBatch).getStatus()); + + long result=restAdminRuleService.count(null,true,"roleName00",false,null,null,false,null,false); + assertEquals(2,result); + } + + @Test + public void testBatchUpdateAdminRule() { + RESTInputAdminRule adminRule=new RESTInputAdminRule(); + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule.setWorkspace("ws99"); + adminRule.setRolename("roleName11"); + adminRule.setGrant(AdminGrantType.ADMIN); + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule2.setWorkspace("ws999"); + adminRule2.setRolename("roleName11"); + adminRule2.setGrant(AdminGrantType.USER); + Long id=(Long)restAdminRuleService.insert(adminRule).getEntity(); + Long id2=(Long)restAdminRuleService.insert(adminRule2).getEntity(); + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation.setType(RESTBatchOperation.TypeName.update); + restBatchOperation.setId(id); + adminRule.setWorkspace("ws00"); + adminRule.setPosition(null); + restBatchOperation.setPayload(adminRule); + + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation2.setType(RESTBatchOperation.TypeName.update); + restBatchOperation2.setId(id2); + adminRule2.setWorkspace("ws000"); + adminRule2.setPosition(null); + restBatchOperation2.setPayload(adminRule2); + + RESTBatch batch=new RESTBatch(); + batch.add(restBatchOperation); + batch.add(restBatchOperation2); + restBatchService.exec(batch); + + assertEquals("ws00",restAdminRuleService.get(id).getWorkspace()); + assertEquals("ws000",restAdminRuleService.get(id2).getWorkspace()); + + } + + + @Test + public void testBatchDeleteAdminRule() { + RESTInputAdminRule adminRule=new RESTInputAdminRule(); + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule.setWorkspace("ws99"); + adminRule.setRolename("roleName22"); + adminRule.setGrant(AdminGrantType.ADMIN); + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); + adminRule2.setWorkspace("ws999"); + adminRule2.setRolename("roleName22"); + adminRule2.setGrant(AdminGrantType.USER); + Long id=(Long)restAdminRuleService.insert(adminRule).getEntity(); + Long id2=(Long)restAdminRuleService.insert(adminRule2).getEntity(); + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation.setType(RESTBatchOperation.TypeName.delete); + restBatchOperation.setId(id); + + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); + restBatchOperation2.setType(RESTBatchOperation.TypeName.delete); + restBatchOperation2.setId(id2); + + RESTBatch batch=new RESTBatch(); + batch.add(restBatchOperation); + batch.add(restBatchOperation2); + restBatchService.exec(batch); + long result=restAdminRuleService.count(null,true,"roleName22",false,null,null,false,null,false); + assertEquals(0,result); + + } +} diff --git a/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImplTest.java b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImplTest.java index a470b3f8..cac8fe2d 100644 --- a/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImplTest.java +++ b/src/services/modules/rest/impl/src/test/java/org/geoserver/geofence/services/rest/impl/RESTRuleServiceImplTest.java @@ -5,7 +5,11 @@ package org.geoserver.geofence.services.rest.impl; +import java.util.List; + import org.geoserver.geofence.core.model.Rule; +import org.geoserver.geofence.core.model.enums.CatalogMode; +import org.geoserver.geofence.core.model.enums.SpatialFilterType; import org.geoserver.geofence.services.RuleAdminService; import org.geoserver.geofence.services.rest.model.RESTInputUser; import org.geoserver.geofence.services.rest.model.RESTInputRule; @@ -16,6 +20,7 @@ import org.geoserver.geofence.core.model.enums.AccessType; import org.geoserver.geofence.core.model.enums.GrantType; import org.geoserver.geofence.services.rest.exception.BadRequestRestEx; +import org.geoserver.geofence.services.rest.model.RESTRuleLimits; import org.geoserver.geofence.services.rest.model.util.IdName; import java.util.ArrayList; import java.util.Arrays; @@ -332,5 +337,38 @@ public void testAllowedAreaSRID() { } + @Test + public void testLimits() { + + RESTInputRule rule = new RESTInputRule(); + rule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.fixedPriority, 42)); + rule.setGrant(GrantType.ALLOW); + rule.setWorkspace("wLimits0"); + rule.setLayer("lLimits0"); + restRuleService.insert(rule); + rule = new RESTInputRule(); + rule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop, 0)); + rule.setGrant(GrantType.LIMIT); + rule.setWorkspace("wLimits0"); + rule.setLayer("lLimits0"); + + RESTRuleLimits limits = new RESTRuleLimits(); + String allowedArea = "MULTIPOLYGON (((4146.5 1301.4, 4147.5 1301.1, 4147.8 1301.4, 4146.5 1301.4)))"; + limits.setRestrictedAreaWkt(allowedArea); + limits.setCatalogMode(CatalogMode.HIDE); + limits.setSpatialFilterType(SpatialFilterType.CLIP); + rule.setLimits(limits); + + Long rid = (Long) restRuleService.insert(rule).getEntity(); + assertNotNull(rid); + RESTOutputRule out = restRuleService.get(rid); + assertNotNull(out); + limits = out.getLimits(); + assertEquals(CatalogMode.HIDE, limits.getCatalogMode()); + assertEquals(SpatialFilterType.CLIP, limits.getSpatialFilterType()); + assertEquals("SRID=4326;" + allowedArea, limits.getRestrictedAreaWkt()); + } + + }