Added code to perform no authentication from Ckan Harvester

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@129235 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-06-21 16:09:18 +00:00
parent 361fc91c9f
commit b71aa0c7bb
4 changed files with 46 additions and 11 deletions

View File

@ -14,10 +14,30 @@ public class GeonetworkRequestCriteria {
private String scope;
private final String FILTER_PUBLIC_IDS = "FILTER_PUBLIC_IDS";
private boolean valueOfFilterPublicIds;
private boolean authOnGeonetwork;
private boolean noAuthOnGeonetwork;
GeonetworkRequestCriteria(String scope, boolean valueOfFilterPublicIds){
/**
* Instantiates a new geonetwork request criteria.
*
* @param scope the scope
* @param valueOfFilterPublicIds the value of filter public ids
* @param noAuthOnGeonetowrk the no auth on geonetowrk
*/
GeonetworkRequestCriteria(String scope, boolean valueOfFilterPublicIds, boolean noAuthOnGeonetowrk){
this.scope = scope;
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
this.noAuthOnGeonetwork = noAuthOnGeonetowrk;
}
/**
* @return the noAuthOnGeonetwork
*/
public boolean isNoAuthOnGeonetwork() {
return noAuthOnGeonetwork;
}
@ -57,6 +77,7 @@ public class GeonetworkRequestCriteria {
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@ -64,15 +85,16 @@ public class GeonetworkRequestCriteria {
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeonetworkQueryCriteria [scope=");
builder.append("GeonetworkRequestCriteria [scope=");
builder.append(scope);
builder.append(", FILTER_PUBLIC_IDS=");
builder.append(FILTER_PUBLIC_IDS);
builder.append(", valueOfFilterPublicIds=");
builder.append(valueOfFilterPublicIds);
builder.append(", authOnGeonetwork=");
builder.append(authOnGeonetwork);
builder.append("]");
return builder.toString();
}
}

View File

@ -43,8 +43,9 @@ public class GeonetworkRequestDecoder {
GeonetworkRequestCriteria rc = getGeonetworkRequestCriteria(params[0]);
logger.debug("scope value is: "+rc.getScope());
newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + rc.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+rc.isValueOfFilterPublicIds();
newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + rc.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+rc.isValueOfFilterPublicIds() +"&"+GeonetworkResolver.PARAMETER_NO_AUTHENTICATION+"="+rc.isNoAuthOnGeonetwork();
logger.debug(GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +" is: "+rc.isValueOfFilterPublicIds());
logger.debug(GeonetworkResolver.PARAMETER_NO_AUTHENTICATION +" is: "+rc.isNoAuthOnGeonetwork());
if(params.length>1){
String remainPath = "";
@ -75,14 +76,16 @@ public class GeonetworkRequestDecoder {
int index = request.indexOf(UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR);
String scope = "";
boolean filterPublicIds = false;
boolean authOnGN = false;
logger.trace("Index of "+UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR+ " is "+index);
if(index!=-1){
scope = request.substring(0,index);
filterPublicIds = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS);
authOnGN = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION);
}else
scope = request;
return new GeonetworkRequestCriteria("/"+scope.replaceAll("_", "/"), filterPublicIds);
return new GeonetworkRequestCriteria("/"+scope.replaceAll("_", "/"), filterPublicIds, authOnGN);
}

View File

@ -27,6 +27,7 @@ public class UriResolverRewriteFilter implements Filter{
public static final String SERVLET_GEONETWORK = "/geonetwork";
public static final String PARAMETER_FILTER_PUBLIC_IDS = "filterpublicids";
public static final String PARAMETER_NO_AUTHENTICATION = "noauthentication";
public static final String REQUEST_PARAMETER_SEPARATOR = "#";
protected static final String SMP_ID = "smp-id";
protected static final String SERVLET_RESOLVER_BY_ID = "id";

View File

@ -77,6 +77,7 @@ public class GeonetworkResolver extends HttpServlet{
public static final String RESET_CACHED_SCOPE = "resetcachedscope";
public static final String CSW_SERVER = "srv/en/csw";
public static final String PARAMETER_FILTER_PUBLIC_IDS = UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS;
public static final String PARAMETER_NO_AUTHENTICATION = UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION;
/** The logger. */
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
@ -244,7 +245,9 @@ public class GeonetworkResolver extends HttpServlet{
String scope = req.getParameter(SCOPE);
String remainValue = req.getParameter(REMAIN_PATH);
String filterPublicIDs = req.getParameter(PARAMETER_FILTER_PUBLIC_IDS);
boolean filterPublicMetadataIDs = false;
String noAuthentication = req.getParameter(PARAMETER_NO_AUTHENTICATION);
boolean filterPublicMetadataIDsB = false;
boolean noAuthenticationB = false;
if (scope == null || scope.equals("")) {
logger.debug("Scope not found");
@ -253,11 +256,17 @@ public class GeonetworkResolver extends HttpServlet{
}
if(filterPublicIDs!=null && Boolean.parseBoolean(filterPublicIDs)){
filterPublicMetadataIDs = true;
filterPublicMetadataIDsB = true;
}
if(noAuthentication!=null && Boolean.parseBoolean(noAuthentication)){
noAuthenticationB = true;
}
logger.info("SCOPE is: " + scope);
logger.info(PARAMETER_FILTER_PUBLIC_IDS +" is "+filterPublicMetadataIDs);
logger.info(PARAMETER_FILTER_PUBLIC_IDS +" is "+filterPublicMetadataIDsB);
logger.info(PARAMETER_NO_AUTHENTICATION +" is "+noAuthenticationB);
try {
@ -309,15 +318,15 @@ public class GeonetworkResolver extends HttpServlet{
}
FilterGetRecords filterGetRecords = null;
if(filterPublicMetadataIDs){
if(filterPublicMetadataIDsB){
filterGetRecords = new FilterGetRecords(byteArray.toString());
}
if(account.getUser()!=null){
if(account.getUser()!=null && !noAuthenticationB){
boolean authorized = GNAuthentication.login(httpUtils, geonetworkParams.getUrl(), account.getUser(), account. getPassword());
logger.trace("Authorized on "+geonetworkParams +" ? "+authorized);
}else
logger.info("Skipping authentication ckan user is null");
logger.info("Skipping authentication, either ckan user is null or noAuthentication is required");
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);