More restrictive handle definitions

As per request by pnbecker and tdonahue, reworking supports() method to
be more restrictive in its handle validation while also still allowing
support for multi-instance environments with derived handles. Now, if a
handle does not match one of the currently known DSpace handle provider
formats, it will be rejected.
This commit is contained in:
mjmarttila
2016-08-03 14:02:16 -04:00
parent 12649fe1fe
commit f6bfc491d3
3 changed files with 33 additions and 30 deletions

View File

@@ -62,19 +62,20 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|| identifier.startsWith(canonicalPrefix) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl") || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/") || identifier.matches("^https?://hdl\\.handle\\.net/.*")
|| identifier.matches("^https?://.+/handle/")) || identifier.matches("^https?://.+/handle/.*"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix // return true if base prefix matches in case of multi-instance deployment with derived prefixes demarcated by a dot "."
if(identifier.startsWith("10.") || identifier.matches("^https?://dx.doi.org") || identifier.startsWith("doi:")) if(prefix.contains(".")) {
return false; String[] splitPrefix = prefix.split("\\.");
// return false if identifier does not contain a '/' or is a URL that does not match above patterns if(splitPrefix.length > 1 && identifier.startsWith(splitPrefix[0])) {
if(! identifier.contains("/") || identifier.matches("^https?://.+")) return true;
return false; }
// otherwise, assumed a valid handle }
return true; // otherwise, assume invalid handle
return false;
} }
@Override @Override

View File

@@ -82,19 +82,20 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|| identifier.startsWith(canonicalPrefix) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl") || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/") || identifier.matches("^https?://hdl\\.handle\\.net/.*")
|| identifier.matches("^https?://.+/handle/")) || identifier.matches("^https?://.+/handle/.*"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix // return true if base prefix matches in case of multi-instance deployment with derived prefixes demarcated by a dot "."
if(identifier.startsWith("10.") || identifier.matches("^https?://dx.doi.org") || identifier.startsWith("doi:")) if(prefix.contains(".")) {
return false; String[] splitPrefix = prefix.split("\\.");
// return false if identifier does not contain a '/' or is a URL that does not match above patterns if(splitPrefix.length > 1 && identifier.startsWith(splitPrefix[0])) {
if(! identifier.contains("/") || identifier.matches("^https?://.+")) return true;
return false; }
// otherwise, assumed a valid handle }
return true; // otherwise, assume invalid handle
return false;
} }
@Override @Override

View File

@@ -78,19 +78,20 @@ public class VersionedHandleIdentifierProviderWithCanonicalHandles extends Ident
|| identifier.startsWith(canonicalPrefix) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl") || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/") || identifier.matches("^https?://hdl\\.handle\\.net/.*")
|| identifier.matches("^https?://.+/handle/")) || identifier.matches("^https?://.+/handle/.*"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix // return true if base prefix matches in case of multi-instance deployment with derived prefixes demarcated by a dot "."
if(identifier.startsWith("10.") || identifier.matches("^https?://dx.doi.org") || identifier.startsWith("doi:")) if(prefix.contains(".")) {
return false; String[] splitPrefix = prefix.split("\\.");
// return false if identifier does not contain a '/' or is a URL that does not match above patterns if(splitPrefix.length > 1 && identifier.startsWith(splitPrefix[0])) {
if(! identifier.contains("/") || identifier.matches("^https?://.+")) return true;
return false; }
// otherwise, assumed a valid handle }
return true; // otherwise, assume invalid handle
return false;
} }
@Override @Override