private void setAccessRightsForLayers(
     int[] layers,
     Map[] layerConstraints,
     SecurityTransaction transaction,
     Role role,
     SecuredObject[] presentLayers)
     throws RPCException, GeneralSecurityException, UnauthorizedException {
   for (int i = 0; i < presentLayers.length; i++) {
     boolean isAccessible = false;
     Map constraintMap = null;
     SecuredObject layer = presentLayers[i];
     for (int j = 0; j < layers.length; j++) {
       if (layer.getID() == layers[j]) {
         isAccessible = true;
         constraintMap = layerConstraints[j];
         break;
       }
     }
     if (isAccessible) {
       Filter filter = null;
       if (constraintMap != null) {
         String xml = buildGetMapFilter(constraintMap);
         if (xml != null) {
           try {
             Document doc = XMLTools.parse(new StringReader(xml));
             filter = AbstractFilter.buildFromDOM(doc.getDocumentElement());
           } catch (Exception e) {
             String s =
                 Messages.getMessage("IGEO_STD_STORERIGHTS_FILTER_PARSING_ERROR", e.getMessage());
             throw new GeneralSecurityException(s);
           }
         }
         if (filter != null) {
           LOG.logInfo("Back to XML: " + filter.toXML());
         }
       }
       Right[] rights =
           new Right[] {
             new Right(layer, RightType.GETMAP, filter),
             new Right(layer, RightType.GETFEATUREINFO),
             new Right(layer, RightType.GETLEGENDGRAPHIC)
           };
       transaction.setRights(layer, role, rights);
     } else {
       transaction.removeRights(
           layer,
           role,
           new RightType[] {
             RightType.GETMAP, RightType.GETFEATUREINFO, RightType.GETLEGENDGRAPHIC
           });
     }
   }
 }
  /**
   * reads a deegree WCS configuration file and performs a GetCoverage request Steps:
   *
   * <ul>
   *   <li>read configuration file
   *   <li>read a GetCoverage request object
   *   <li>perform the request
   * </ul>
   */
  public void _testGetCoverage1() {
    try {
      WCSConfiguration configuration =
          WCSConfiguration.create(Configuration.getWCSConfigurationURL());
      WCService service = new WCService(configuration);
      StringBuffer sb = new StringBuffer();
      sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST)
          .append(':')
          .append(Configuration.PORT)
          .append(Configuration.WCS_WEB_CONTEXT)
          .append('/')
          .append(Configuration.WCS_SERVLET);

      String req =
          "<?xml version='1.0' encoding='UTF-8'?><GetCoverage "
              + "xmlns='http://www.opengis.net/wcs' xmlns:gml='http://www.opengis.net/gml' "
              + "service='WCS' version='1.0.0'><sourceCoverage>Mapneatline</sourceCoverage>"
              + "<domainSubset><spatialSubset><gml:Envelope srsName='EPSG:4326'>"
              + "<gml:pos dimension='2'>-1,-1</gml:pos><gml:pos dimension='2'>1,1"
              + "</gml:pos></gml:Envelope><gml:Grid dimension='2'><gml:limits>"
              + "<gml:GridEnvelope><gml:low>0 0</gml:low><gml:high>300 300</gml:high>"
              + "</gml:GridEnvelope></gml:limits><gml:axisName>x</gml:axisName>"
              + "<gml:axisName>y</gml:axisName></gml:Grid></spatialSubset></domainSubset>"
              + "<output><crs>EPSG:4326</crs><format>jpeg</format></output></GetCoverage>";
      StringReader reader = new StringReader(req);
      Document doc = XMLTools.parse(reader);

      GetCoverage desc = (GetCoverage) OGCRequestFactory.createFromXML(doc);
      ResultCoverage o = (ResultCoverage) service.doService(desc);
      BufferedImage bi = ((AbstractGridCoverage) o.getCoverage()).getAsImage(500, 500);

      FileOutputStream fos =
          new FileOutputStream(Configuration.getWCSBaseDir().getPath() + "/kannweg1.tif");
      ImageUtils.saveImage(bi, fos, "tif", 1);
      fos.close();
    } catch (Exception e) {
      fail(StringTools.stackTraceToString(e));
    }
  }
Esempio n. 3
0
  /**
   * Appends the XML representation of the given <code>Query</code> to an element.
   *
   * @param query
   */
  private static void appendQuery(Element root, Query query)
      throws IOException, XMLParsingException {

    Element queryElem = XMLTools.appendElement(root, WFS, "wfs:Query");
    if (query.getHandle() != null) {
      queryElem.setAttribute("handle", query.getHandle());
    }
    if (query.getFeatureVersion() != null) {
      queryElem.setAttribute("featureVersion", query.getFeatureVersion());
    }
    QualifiedName[] qn = query.getTypeNames();
    String[] na = new String[qn.length];
    for (int i = 0; i < na.length; i++) {
      na[i] = qn[i].getAsString();
      queryElem.setAttribute("xmlns:" + qn[i].getPrefix(), qn[i].getNamespace().toASCIIString());
    }
    String tn = StringTools.arrayToString(na, ',');
    queryElem.setAttribute("typeName", tn);

    PropertyPath[] propertyNames = query.getPropertyNames();
    for (int i = 0; i < propertyNames.length; i++) {
      Element propertyNameElement = XMLTools.appendElement(queryElem, WFS, "wfs:PropertyName");
      appendPropertyPath(propertyNameElement, propertyNames[i]);
    }
    Function[] fn = query.getFunctions();
    // copy function definitions into query node
    if (fn != null) {
      for (int i = 0; i < fn.length; i++) {
        StringReader sr = new StringReader(fn[i].toXML().toString());
        Document doc;
        try {
          doc = XMLTools.parse(sr);
        } catch (SAXException e) {
          throw new XMLParsingException("could not parse filter function", e);
        }
        XMLTools.copyNode(doc.getDocumentElement(), queryElem);
      }
    }
    // copy filter into query node
    if (query.getFilter() != null) {
      StringReader sr = new StringReader(query.getFilter().toXML().toString());
      Document doc;
      try {
        doc = XMLTools.parse(sr);
      } catch (SAXException e) {
        throw new XMLParsingException("could not parse filter", e);
      }
      Element elem = XMLTools.appendElement(queryElem, OGCNS, "ogc:Filter");
      XMLTools.copyNode(doc.getDocumentElement(), elem);
    }

    SortProperty[] sp = query.getSortProperties();
    if (sp != null) {
      Element sortBy = XMLTools.appendElement(queryElem, OGCNS, "ogc:SortBy");
      for (int i = 0; i < sp.length; i++) {
        Element sortProp = XMLTools.appendElement(sortBy, OGCNS, "ogc:SortProperty");
        XMLTools.appendElement(
            sortProp, OGCNS, "ogc:PropertyName", sp[i].getSortProperty().getAsString());
        if (!sp[i].getSortOrder()) {
          XMLTools.appendElement(sortBy, OGCNS, "ogc:SortOrder", "DESC");
        }
      }
    }
  }