diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java index 7e69b46..1ccfe58 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java @@ -171,17 +171,55 @@ public class GeonetworkResolver { try { - GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope); - //GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, null,null); - - GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope, null, null); - + GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); + logger.info("set scope provider "+scope); ScopeProvider.instance.set(scope); + Account account = gnInstance.getAccount(); + Version version = gnInstance.getVersion(); + String geonetworkUrl = gnInstance.getEndPoint(); + Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null; + + if(account==null || account.getUser()==null || account.getPassword()==null || config==null) { + logger.info("Loading GN istance and configurations via Geonetwork Library..."); + logger.info("set scope provider "+scope); + ScopeProvider.instance.set(scope); + config = gnInstance.getGeonetworkPublisher().getConfiguration(); + account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); + version = config.getGeoNetworkVersion(); + geonetworkUrl = config.getGeoNetworkEndpoint(); + } + logger.info("set scope provider "+scope); + ScopeProvider.instance.set(scope); + logger.info("SCOPE: {}, CKAN user used is: {}",scope, account.getUser(), account.getPassword()); + logger.info("SCOPE: {}, GN EndPoint: {}",scope, geonetworkUrl); + +// GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); +// ScopeProvider.instance.set(scope); HTTPCallsUtils httpUtils = new HTTPCallsUtils(); + + if(visibility.equals(VISIBILITY.PRV.name())){ + if(account.getUser()!=null){ + switch (version) { + case DUE: + boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword()); + logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized); + break; + + default: + httpUtils = new HTTPCallsUtils(account.getUser(), account.getPassword()); + logger.info("Authorized on GN3 via HTTCallsUtils..."); + break; + } + + }else { + logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null"); + } + } + //Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration(); //String geonetworkUrl = config.getGeoNetworkEndpoint(); - String geonetworkUrl = gnInstance.getEndPoint(); +// String geonetworkUrl = gnInstance.getEndPoint(); String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath; logger.info("The base URL is: "+baseURL); String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString(); @@ -418,9 +456,9 @@ public class GeonetworkResolver { //I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN, //THEN THE CONGIGURATIONS LAODED, USER TO PERFORM AUTHENTICATION AND SO ON ARE MANAGE VIA HTTP_CLIENTS. + GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); logger.info("set scope provider "+scope); ScopeProvider.instance.set(scope); - GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope, GeonetworkLoginLevel.CKAN, AccountType.CKAN); Account account = gnInstance.getAccount(); Version version = gnInstance.getVersion(); String geonetworkUrl = gnInstance.getEndPoint(); @@ -635,7 +673,7 @@ public class GeonetworkResolver { * @return the geonetwork instance for scope * @throws Exception the exception */ - protected GeonetworkInstance getGeonetworkInstanceForScope(String scope, GeonetworkLoginLevel loginLevel, AccountType accountType) throws Exception{ + protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception{ logger.info("Trying to read the {} from cache for scope: {}",GeonetworkInstance.class.getSimpleName(), scope); GeonetworkInstance geoInstance;