* @throws ServiceException
*/
public void verifyAccessLayer(String layerName, ReferencedEnvelope boundingBox) throws ServiceException {
LayerInfo layerInfo = getLayerInfoByName(layerName); //catalog.getLayerByName(layerName);
if (layerInfo == null) {
throw new ServiceException("Could not find layer " + layerName, "LayerNotDefined");
}
if (layerInfo instanceof SecuredLayerInfo && boundingBox != null) {
//test layer bbox limits
SecuredLayerInfo securedLayerInfo = (SecuredLayerInfo) layerInfo;
WrapperPolicy policy = securedLayerInfo.getWrapperPolicy();
AccessLimits limits = policy.getLimits();
if (limits instanceof DataAccessLimits) {
//ensure we are all using the same CRS
CoordinateReferenceSystem dataCrs = layerInfo.getResource().getCRS();
if (boundingBox.getCoordinateReferenceSystem()!=null && !CRS.equalsIgnoreMetadata(dataCrs, boundingBox.getCoordinateReferenceSystem())) {
try {
boundingBox = boundingBox.transform(dataCrs,true);
} catch (Exception e) {
//bboxes not compatible? deny access for all certainty.
boundingBox = null;
}
}
Envelope limitBox = new ReferencedEnvelope(ReferencedEnvelope.EVERYTHING, dataCrs);
Filter filter = ((DataAccessLimits) limits).getReadFilter();
if (filter != null) {
//extract filter envelope from filter
Envelope box = (Envelope) filter.accept(ExtractBoundsFilterVisitor.BOUNDS_VISITOR, null);
if (box != null) {
limitBox = new ReferencedEnvelope(limitBox.intersection(box), dataCrs);
}
}
if (limits instanceof CoverageAccessLimits) {
if (((CoverageAccessLimits) limits).getRasterFilter() != null) {
Envelope box = ((CoverageAccessLimits) limits).getRasterFilter().getEnvelopeInternal();
if (box != null) {
limitBox = new ReferencedEnvelope(limitBox.intersection(box), dataCrs);
}
}
}
if (limits instanceof WMSAccessLimits) {
if (((WMSAccessLimits) limits).getRasterFilter() != null) {
Envelope box = ((WMSAccessLimits) limits).getRasterFilter().getEnvelopeInternal();
if (box != null) {
limitBox = new ReferencedEnvelope(limitBox.intersection(box), dataCrs);
}
}
}
if (!limitBox.covers(ReferencedEnvelope.EVERYTHING) && (boundingBox==null || !limitBox.contains(boundingBox))) {
throw new ServiceException("Access denied to bounding box on layer " + layerName, "AccessDenied");
}
}
}
}