* @throws PartialResolutionException
*/
protected XRDS fetchAuthXRDSHelper(XRI qxri, URI uri, XRD parent, Service parentService, XRISegment segment, ResolverFlags flags, ResolverState state, String parentXRI)
throws PartialResolutionException
{
XRDS xrdsOut = new XRDS();
String query = segment.getSubSegmentAt(0).toURINormalForm(true);
URI newURI;
try {
newURI = constructAuthResURI(uri.toString(), segment.toURINormalForm(true));
log.trace("fetchAuthXRDS - newURI = " + newURI);
}
catch (java.net.URISyntaxException oEx) {
throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, "Invalid URI for authority resolution service");
}
ResolvedHttpResponse resp = null;
XRDS tmpXRDS = null;
// now that we've constructed the new URI, try to return the stream from it
try {
resp = getDataFromURI(newURI, segment.toString(), flags, state);
InputStream in = resp.getInputStream();
tmpXRDS = readXRDS(in);
log.debug("fetchAuthXRDS - got XRDS = " + tmpXRDS.serializeDescriptorDOM(false, true));
} catch (IOException e) {
log.trace("fetchAuthXRDS - got IOException from URI " + newURI);
throw makeResolutionException(xrdsOut, query, Status.NETWORK_ERROR, "Networking error encountered");
} catch (Exception e) {
log.trace("fetchAuthXRDS - " + e);
throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, e.getMessage());
}
//// sanity checks
// there should be at least one child element
if (tmpXRDS.getNumChildren() < 1) {
throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document");
}
if (tmpXRDS.getNumChildren() > segment.getNumSubSegments()) {
throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document: too many XRD elements returned");
}
XRD prevXRD = parent;
Service prevService = parentService;
ResolverFlags currentFlags = null; // this is for overriding by SamlBypassAuthority settings
// check each child
for (int d = 0; d < tmpXRDS.getNumChildren(); d++) {
if (!tmpXRDS.isXRDAt(d))
throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Authority XRDS document should not contain XRDS element");
XRD xrd = tmpXRDS.getDescriptorAt(d);
xrdsOut.add(xrd);
currentFlags = new ResolverFlags(flags); // clone flags
// if SAML WAS requested and what we are resolving is allowed to bypass SAML,
// we turn off the SAML flag to allow SAML failure of any kind for this administrative region
if (currentFlags.isSaml() && isSAMLBypassAuthority(parentXRI)) {
currentFlags.setSaml(false);
}
parseFetchedXRD(xrdsOut, xrd, prevXRD, segment.getSubSegmentAt(d), prevService, currentFlags);
// write to cache if we have one
if (cache != null && d == 0) {
// do our caching here right after we got the first XRD
String xriAuthority = XRI.fromURINormalForm(parentXRI + query).toURINormalForm();
byte[] xrdsBuf = null;
try {
xrdsBuf = xrdsOut.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {}
int cacheTTL = computeCacheTTL(xrd.getExpires(), resp);
log.debug("writing cache entry " + xriAuthority + ", cacheTTL = " + cacheTTL);
if (cacheTTL > 0) {
cache.put(xriAuthority, currentFlags.isHttps(), currentFlags.isSaml(), xrdsBuf, cacheTTL);
}
}
if(flags.isSaml() && d != (tmpXRDS.getNumChildren()-1))
{
//// perform service selection
String authResMediaType = Tags.CONTENT_TYPE_XRDS + ";" + flags.getTrustParameters();
List authResServices = selectServices(prevXRD.getServices(), null, null, authResMediaType, flags);
if (authResServices.size() < 1) {