Search in sources :

Example 1 with BasicPreemptiveSecurityConnector

use of org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector in project geo-platform by geosdi.

the class CSWServiceDelegate method createGetRecordsRequest.

private CatalogGetRecordsRequest<GetRecordsResponseType> createGetRecordsRequest(String serverUrl) throws Exception {
    GPCatalogConnectorStore serverConnector = null;
    try {
        URL url = new URL(serverUrl);
        GPCSWConnectorBuilder builder = GPCSWConnectorBuilder.newConnector().withServerUrl(url).withProxyConfiguration(cswProxyConfiguration);
        if (serverUrl.contains("snipc.protezionecivile.it")) {
            GPSecurityConnector securityConnector = new BasicPreemptiveSecurityConnector(snipcProvider.getSnipcUsername(), snipcProvider.getSnipcPassword());
            builder.withClientSecurity(securityConnector);
        }
        serverConnector = builder.build();
    } catch (MalformedURLException ex) {
        logger.error("### MalformedURLException: {}", ex.getMessage());
        throw new IllegalParameterFault("Malformed URL");
    }
    CatalogGetRecordsRequest<GetRecordsResponseType> request = serverConnector.createGetRecordsRequest();
    return request;
}
Also used : GPCatalogConnectorStore(org.geosdi.geoplatform.connector.GPCatalogConnectorStore) MalformedURLException(java.net.MalformedURLException) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPSecurityConnector(org.geosdi.geoplatform.connector.server.security.GPSecurityConnector) GPCSWConnectorBuilder(org.geosdi.geoplatform.connector.GPCSWConnectorBuilder) BasicPreemptiveSecurityConnector(org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector) URL(java.net.URL)

Example 2 with BasicPreemptiveSecurityConnector

use of org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector in project geo-platform by geosdi.

the class CatalogGetRecordsTest method testSecureGetRecords.

@Ignore("Require to add the SNIPC certificate into default keystore")
@Test
public void testSecureGetRecords() throws Exception {
    GPCatalogConnectorStore snipcServerConnector = newConnector().withServerUrl(new URL(snipcUrl)).withClientSecurity(new BasicPreemptiveSecurityConnector(snipcUsername, snipcPassword)).build();
    CatalogGetRecordsRequest<GetRecordsResponseType> request = snipcServerConnector.createGetRecordsRequest();
    request.setTypeName(RECORD_V202);
    request.setOutputSchema(CSW_V202);
    request.setElementSetName(ElementSetType.FULL.toString());
    request.setResultType(ResultType.RESULTS.toString());
    request.setStartPosition(BigInteger.ONE);
    request.setMaxRecords(BigInteger.valueOf(25));
    GetRecordsResponseType response = request.getResponse();
    SearchResultsType result = response.getSearchResults();
    logger.info("RECORD MATCHES @@@@@@@@@@@@@@@@@@@@@ {}", result.getNumberOfRecordsMatched());
    logger.info("RECORDS FOUND @@@@@@@@@@@@@@@@@@@@@@ {}", result.getNumberOfRecordsReturned());
    logger.info("NEXT RECORD @@@@@@@@@@@@@@@@@@@@@@ {}", result.getNextRecord());
    List<JAXBElement<? extends AbstractRecordType>> metadata = result.getAbstractRecord();
    if (!metadata.isEmpty()) {
        logger.info("FIRST SECURE METADATA @@@@@@@@@@@@@@@@@@@@@ {}", (RecordType) (metadata.get(0).getValue()));
    }
}
Also used : BasicPreemptiveSecurityConnector(org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector) JAXBElement(javax.xml.bind.JAXBElement) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with BasicPreemptiveSecurityConnector

use of org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector in project geo-platform by geosdi.

the class CSWServiceDelegate method createServerConnector.

private GPCatalogConnectorStore createServerConnector(String serverUrl) throws Exception {
    GPCatalogConnectorStore serverConnector;
    try {
        URL url = new URL(serverUrl);
        GPCSWConnectorBuilder builder = GPCSWConnectorBuilder.newConnector().withServerUrl(url).withProxyConfiguration(cswProxyConfiguration);
        if (serverUrl.contains("snipc.protezionecivile.it")) {
            GPSecurityConnector securityConnector = new BasicPreemptiveSecurityConnector(snipcProvider.getSnipcUsername(), snipcProvider.getSnipcPassword());
            builder.withClientSecurity(securityConnector);
        }
        serverConnector = builder.build();
    } catch (MalformedURLException ex) {
        logger.error("### MalformedURLException: {}", ex.getMessage());
        throw new IllegalParameterFault("Malformed URL");
    }
    return serverConnector;
}
Also used : GPCatalogConnectorStore(org.geosdi.geoplatform.connector.GPCatalogConnectorStore) MalformedURLException(java.net.MalformedURLException) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPSecurityConnector(org.geosdi.geoplatform.connector.server.security.GPSecurityConnector) GPCSWConnectorBuilder(org.geosdi.geoplatform.connector.GPCSWConnectorBuilder) BasicPreemptiveSecurityConnector(org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector) URL(java.net.URL)

Example 4 with BasicPreemptiveSecurityConnector

use of org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method p_itGrandiDigheTest.

@Test
public void p_itGrandiDigheTest() throws Exception {
    String wfsURL = "https://servizi.protezionecivile.it/geoserver/wfs";
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withClientSecurity(new BasicPreemptiveSecurityConnector("MAIDNT78M23G942L", "mdonato")).withServerUrl(new URL(wfsURL)).build();
    QName grandiDighe = new QName("IDROGEOLOGICO:IT_grandi_dighe_MIT2019");
    String localPart = grandiDighe.getLocalPart();
    String name = localPart.substring(localPart.indexOf(":") + 1);
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(grandiDighe));
    Schema response = request.getResponse();
    logger.info("#################SCHEMA : {}\n", response);
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
    if (layerSchema == null) {
        throw new IllegalStateException("The Layer Schema is null.");
    }
    layerSchema.setScope(wfsURL);
    logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setBBox(new BBox(14.131237640976908, 36.56356461583572, 15.821758881211283, 37.143760728459014));
    getFeatureRequest.setQueryDTO(newInstance().unmarshal(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<QueryDTO>\n" + "    <matchOperator>ANY</matchOperator>\n" + "    <queryRestrictionList>\n" + "        <queryRestriction>\n" + "            <attribute>\n" + "                <type>string</type>\n" + "                <name>diga</name>\n" + "                <value></value>\n" + "                <maxOccurs>1</maxOccurs>\n" + "                <minOccurs>0</minOccurs>\n" + "                <nillable>true</nillable>\n" + "            </attribute>\n" + "            <operator>EQUAL</operator>\n" + "            <restriction>SANTA ROSALIA</restriction>\n" + "        </queryRestriction>\n" + "        <queryRestriction>\n" + "            <attribute>\n" + "                <type>string</type>\n" + "                <name>diga</name>\n" + "                <value></value>\n" + "                <maxOccurs>1</maxOccurs>\n" + "                <minOccurs>0</minOccurs>\n" + "                <nillable>true</nillable>\n" + "            </attribute>\n" + "            <operator>EQUAL</operator>\n" + "            <restriction>MONTE CAVALLARO</restriction>\n" + "        </queryRestriction>\n" + "    </queryRestrictionList>\n" + "</QueryDTO>"), QueryDTO.class));
    getFeatureRequest.setGeometryName(layerSchema.getGeometry().getName());
    getFeatureRequest.setResultType(RESULTS.value());
    getFeatureRequest.setMaxFeatures(valueOf(50));
    logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
    InputStream is = getFeatureRequest.getResponseAsStream();
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
    FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
    if (!featureCollection.isFeaturesLoaded()) {
        featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    JAXBElement<FeatureCollectionDTO> root = new JAXBElement<>(grandiDighe, FeatureCollectionDTO.class, featureCollection);
    gpJAXBContextBuilder.marshal(root, new File(of(new File(".").getCanonicalPath(), "target", "GrandiDighe").collect(joining(separator, "", ".xml"))));
    getFeatureRequest.setOutputFormat("json");
    InputStream isJson = getFeatureRequest.getResponseAsStream();
    FeatureCollection featureCollectionJson = JACKSON_SUPPORT.getDefaultMapper().readValue(isJson, FeatureCollection.class);
    JACKSON_SUPPORT.getDefaultMapper().writeValue(new File(of(new File(".").getCanonicalPath(), "target", "GrandiDighe").collect(joining(separator, "", ".json"))), featureCollectionJson);
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) QueryDTO(org.geosdi.geoplatform.connector.wfs.response.QueryDTO) JAXBElement(javax.xml.bind.JAXBElement) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) FeatureCollection(org.geojson.FeatureCollection) BBox(org.geosdi.geoplatform.gui.shared.bean.BBox) BasicPreemptiveSecurityConnector(org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) Test(org.junit.Test)

Example 5 with BasicPreemptiveSecurityConnector

use of org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method m_ospedaliTest.

@Test
public void m_ospedaliTest() throws Exception {
    String wfsURL = "https://servizi.protezionecivile.it/geoserver/wfs";
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withClientSecurity(new BasicPreemptiveSecurityConnector("MAIDNT78M23G942L", "mdonato")).withServerUrl(new URL(wfsURL)).build();
    QName ospedali = new QName("PNSRS:CAL_4_6_ospedali");
    String localPart = ospedali.getLocalPart();
    String name = localPart.substring(localPart.indexOf(":") + 1);
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(ospedali));
    Schema response = request.getResponse();
    logger.info("#################SCHEMA : {}\n", response);
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
    if (layerSchema == null) {
        throw new IllegalStateException("The Layer Schema is null.");
    }
    layerSchema.setScope(wfsURL);
    logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setResultType(RESULTS.value());
    getFeatureRequest.setMaxFeatures(valueOf(2));
    logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
    InputStream is = getFeatureRequest.getResponseAsStream();
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
    FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
    if (!featureCollection.isFeaturesLoaded()) {
        featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    JAXBElement<FeatureCollectionDTO> root = new JAXBElement<>(ospedali, FeatureCollectionDTO.class, featureCollection);
    gpJAXBContextBuilder.marshal(root, new File(of(new File(".").getCanonicalPath(), "target", "Ospedali").collect(joining(separator, "", ".xml"))));
    getFeatureRequest.setOutputFormat("json");
    InputStream isJson = getFeatureRequest.getResponseAsStream();
    FeatureCollection featureCollectionJson = JACKSON_SUPPORT.getDefaultMapper().readValue(isJson, FeatureCollection.class);
    JACKSON_SUPPORT.getDefaultMapper().writeValue(new File(of(new File(".").getCanonicalPath(), "target", "Ospedali").collect(joining(separator, "", ".json"))), featureCollectionJson);
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) JAXBElement(javax.xml.bind.JAXBElement) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) FeatureCollection(org.geojson.FeatureCollection) BasicPreemptiveSecurityConnector(org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) Test(org.junit.Test)

Aggregations

URL (java.net.URL)8 BasicPreemptiveSecurityConnector (org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector)8 Test (org.junit.Test)6 JAXBElement (javax.xml.bind.JAXBElement)4 GPSecurityConnector (org.geosdi.geoplatform.connector.server.security.GPSecurityConnector)4 Ignore (org.junit.Ignore)4 MalformedURLException (java.net.MalformedURLException)2 QName (javax.xml.namespace.QName)2 FeatureCollection (org.geojson.FeatureCollection)2 GPCSWConnectorBuilder (org.geosdi.geoplatform.connector.GPCSWConnectorBuilder)2 GPCatalogConnectorStore (org.geosdi.geoplatform.connector.GPCatalogConnectorStore)2 GPWFSConnectorStore (org.geosdi.geoplatform.connector.GPWFSConnectorStore)2 WFSGetFeatureRequest (org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest)2 FeatureCollectionDTO (org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO)2 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)2 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)2 WFSGetFeatureStaxReader (org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader)2 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)2 FileOutputStream (java.io.FileOutputStream)1 QueryDTO (org.geosdi.geoplatform.connector.wfs.response.QueryDTO)1