enhancement on fixing GN authentication
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@179499 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8f7dbc486e
commit
e44a57bb4e
|
@ -171,17 +171,55 @@ public class GeonetworkResolver {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
|
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
||||||
//GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, null,null);
|
logger.info("set scope provider "+scope);
|
||||||
|
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope, null, null);
|
|
||||||
|
|
||||||
ScopeProvider.instance.set(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();
|
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();
|
//Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||||
//String geonetworkUrl = config.getGeoNetworkEndpoint();
|
//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;
|
String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||||
logger.info("The base URL is: "+baseURL);
|
logger.info("The base URL is: "+baseURL);
|
||||||
String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
|
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,
|
//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.
|
//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);
|
logger.info("set scope provider "+scope);
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope, GeonetworkLoginLevel.CKAN, AccountType.CKAN);
|
|
||||||
Account account = gnInstance.getAccount();
|
Account account = gnInstance.getAccount();
|
||||||
Version version = gnInstance.getVersion();
|
Version version = gnInstance.getVersion();
|
||||||
String geonetworkUrl = gnInstance.getEndPoint();
|
String geonetworkUrl = gnInstance.getEndPoint();
|
||||||
|
@ -635,7 +673,7 @@ public class GeonetworkResolver {
|
||||||
* @return the geonetwork instance for scope
|
* @return the geonetwork instance for scope
|
||||||
* @throws Exception the exception
|
* @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);
|
logger.info("Trying to read the {} from cache for scope: {}",GeonetworkInstance.class.getSimpleName(), scope);
|
||||||
GeonetworkInstance geoInstance;
|
GeonetworkInstance geoInstance;
|
||||||
|
|
Loading…
Reference in New Issue