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;
}
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()));
}
}
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;
}
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);
}
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);
}
Aggregations