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:
parent
361fc91c9f
commit
b71aa0c7bb
|
@ -14,10 +14,30 @@ public class GeonetworkRequestCriteria {
|
||||||
private String scope;
|
private String scope;
|
||||||
private final String FILTER_PUBLIC_IDS = "FILTER_PUBLIC_IDS";
|
private final String FILTER_PUBLIC_IDS = "FILTER_PUBLIC_IDS";
|
||||||
private boolean valueOfFilterPublicIds;
|
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.scope = scope;
|
||||||
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
||||||
|
this.noAuthOnGeonetwork = noAuthOnGeonetowrk;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the noAuthOnGeonetwork
|
||||||
|
*/
|
||||||
|
public boolean isNoAuthOnGeonetwork() {
|
||||||
|
|
||||||
|
return noAuthOnGeonetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +77,7 @@ public class GeonetworkRequestCriteria {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
@ -64,15 +85,16 @@ public class GeonetworkRequestCriteria {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("GeonetworkQueryCriteria [scope=");
|
builder.append("GeonetworkRequestCriteria [scope=");
|
||||||
builder.append(scope);
|
builder.append(scope);
|
||||||
builder.append(", FILTER_PUBLIC_IDS=");
|
builder.append(", FILTER_PUBLIC_IDS=");
|
||||||
builder.append(FILTER_PUBLIC_IDS);
|
builder.append(FILTER_PUBLIC_IDS);
|
||||||
builder.append(", valueOfFilterPublicIds=");
|
builder.append(", valueOfFilterPublicIds=");
|
||||||
builder.append(valueOfFilterPublicIds);
|
builder.append(valueOfFilterPublicIds);
|
||||||
|
builder.append(", authOnGeonetwork=");
|
||||||
|
builder.append(authOnGeonetwork);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,9 @@ public class GeonetworkRequestDecoder {
|
||||||
|
|
||||||
GeonetworkRequestCriteria rc = getGeonetworkRequestCriteria(params[0]);
|
GeonetworkRequestCriteria rc = getGeonetworkRequestCriteria(params[0]);
|
||||||
logger.debug("scope value is: "+rc.getScope());
|
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_FILTER_PUBLIC_IDS +" is: "+rc.isValueOfFilterPublicIds());
|
||||||
|
logger.debug(GeonetworkResolver.PARAMETER_NO_AUTHENTICATION +" is: "+rc.isNoAuthOnGeonetwork());
|
||||||
|
|
||||||
if(params.length>1){
|
if(params.length>1){
|
||||||
String remainPath = "";
|
String remainPath = "";
|
||||||
|
@ -75,14 +76,16 @@ public class GeonetworkRequestDecoder {
|
||||||
int index = request.indexOf(UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR);
|
int index = request.indexOf(UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR);
|
||||||
String scope = "";
|
String scope = "";
|
||||||
boolean filterPublicIds = false;
|
boolean filterPublicIds = false;
|
||||||
|
boolean authOnGN = false;
|
||||||
logger.trace("Index of "+UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR+ " is "+index);
|
logger.trace("Index of "+UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR+ " is "+index);
|
||||||
if(index!=-1){
|
if(index!=-1){
|
||||||
scope = request.substring(0,index);
|
scope = request.substring(0,index);
|
||||||
filterPublicIds = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS);
|
filterPublicIds = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS);
|
||||||
|
authOnGN = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION);
|
||||||
}else
|
}else
|
||||||
scope = request;
|
scope = request;
|
||||||
|
|
||||||
return new GeonetworkRequestCriteria("/"+scope.replaceAll("_", "/"), filterPublicIds);
|
return new GeonetworkRequestCriteria("/"+scope.replaceAll("_", "/"), filterPublicIds, authOnGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class UriResolverRewriteFilter implements Filter{
|
||||||
|
|
||||||
public static final String SERVLET_GEONETWORK = "/geonetwork";
|
public static final String SERVLET_GEONETWORK = "/geonetwork";
|
||||||
public static final String PARAMETER_FILTER_PUBLIC_IDS = "filterpublicids";
|
public static final String PARAMETER_FILTER_PUBLIC_IDS = "filterpublicids";
|
||||||
|
public static final String PARAMETER_NO_AUTHENTICATION = "noauthentication";
|
||||||
public static final String REQUEST_PARAMETER_SEPARATOR = "#";
|
public static final String REQUEST_PARAMETER_SEPARATOR = "#";
|
||||||
protected static final String SMP_ID = "smp-id";
|
protected static final String SMP_ID = "smp-id";
|
||||||
protected static final String SERVLET_RESOLVER_BY_ID = "id";
|
protected static final String SERVLET_RESOLVER_BY_ID = "id";
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
public static final String RESET_CACHED_SCOPE = "resetcachedscope";
|
public static final String RESET_CACHED_SCOPE = "resetcachedscope";
|
||||||
public static final String CSW_SERVER = "srv/en/csw";
|
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_FILTER_PUBLIC_IDS = UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS;
|
||||||
|
public static final String PARAMETER_NO_AUTHENTICATION = UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION;
|
||||||
|
|
||||||
/** The logger. */
|
/** The logger. */
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
|
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
|
||||||
|
@ -244,7 +245,9 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
String scope = req.getParameter(SCOPE);
|
String scope = req.getParameter(SCOPE);
|
||||||
String remainValue = req.getParameter(REMAIN_PATH);
|
String remainValue = req.getParameter(REMAIN_PATH);
|
||||||
String filterPublicIDs = req.getParameter(PARAMETER_FILTER_PUBLIC_IDS);
|
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("")) {
|
if (scope == null || scope.equals("")) {
|
||||||
logger.debug("Scope not found");
|
logger.debug("Scope not found");
|
||||||
|
@ -253,11 +256,17 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filterPublicIDs!=null && Boolean.parseBoolean(filterPublicIDs)){
|
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("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 {
|
try {
|
||||||
|
|
||||||
|
@ -309,15 +318,15 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterGetRecords filterGetRecords = null;
|
FilterGetRecords filterGetRecords = null;
|
||||||
if(filterPublicMetadataIDs){
|
if(filterPublicMetadataIDsB){
|
||||||
filterGetRecords = new FilterGetRecords(byteArray.toString());
|
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());
|
boolean authorized = GNAuthentication.login(httpUtils, geonetworkParams.getUrl(), account.getUser(), account. getPassword());
|
||||||
logger.trace("Authorized on "+geonetworkParams +" ? "+authorized);
|
logger.trace("Authorized on "+geonetworkParams +" ? "+authorized);
|
||||||
}else
|
}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);
|
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
||||||
|
|
Loading…
Reference in New Issue