in taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/CredentialManagerImpl.java [885:941]
protected LinkedHashSet<URI> getPossibleServiceURIsToLookup(URI serviceURI,
boolean usePathRecursion) {
try {
serviceURI = serviceURI.normalize();
serviceURI = dnParser.setUserInfoForURI(serviceURI, null);
} catch (URISyntaxException ex) {
logger.warn("Could not strip userinfo from " + serviceURI, ex);
}
/*
* We'll use a LinkedHashSet to avoid checking for duplicates, like if
* serviceURI.equals(withoutQuery) Only the first hit should be added to
* the set.
*/
LinkedHashSet<URI> possibles = new LinkedHashSet<URI>();
possibles.add(serviceURI);
if (!usePathRecursion || !serviceURI.isAbsolute())
return possibles;
/*
* We'll preserve the fragment, as it is used to indicate the realm
*/
String rawFragment = serviceURI.getRawFragment();
if (rawFragment == null)
rawFragment = "";
URI withoutQuery = serviceURI.resolve(serviceURI.getRawPath());
addFragmentedURI(possibles, withoutQuery, rawFragment);
// Immediate parent
URI parent = withoutQuery.resolve(".");
addFragmentedURI(possibles, parent, rawFragment);
URI oldParent = null;
// Top parent (to be added later)
URI root = parent.resolve("/");
while (!parent.equals(oldParent) && !parent.equals(root)
&& parent.getPath().length() > 0) {
// Intermediate parents, but not for "http://bla.org" as we would
// find "http://bla.org.."
oldParent = parent;
parent = parent.resolve("..");
addFragmentedURI(possibles, parent, rawFragment);
}
// In case while-loop did not do so, also include root
addFragmentedURI(possibles, root, rawFragment);
if (rawFragment.length() > 0)
// Add the non-fragment versions in the bottom of the list
for (URI withFragment : new ArrayList<>(possibles))
try {
possibles
.add(dnParser.setFragmentForURI(withFragment, null));
} catch (URISyntaxException e) {
logger.warn("Could not non-fragment URI " + withFragment);
}
return possibles;
}