void parseFetchedXRD(XRDS xrdsOut, XRD xrd, XRD prevXRD, XRISubSegment query, Service prevService, ResolverFlags flags) throws PartialResolutionException
{
// status is not success
ServerStatus sstat = xrd.getServerStatus();
Status stat;
if (sstat == null) {
// compatibility: if no ServerStatus, look for Status
stat = xrd.getStatus();
if (stat != null) {
xrd.setServerStatus(new ServerStatus(stat.getCode(), stat.getText()));
}
}
else {
stat = new Status(sstat.getCode(), sstat.getText());
xrd.setStatus(stat);
}
if (stat == null) {
xrd.setStatus(new Status(Status.INVALID_XRDS, "Missing ServerStatus or Status element in XRD"));
throw new PartialResolutionException(xrdsOut);
}
if (!stat.getCode().equals(Status.SUCCESS)) {
throw new PartialResolutionException(xrdsOut);
}
// check the basic properties of the descriptor
if (!xrd.isValid()) {
xrd.setStatus(new Status(Status.UNEXPECTED_RESPONSE, "XRD is not valid (stale?)"));
throw new PartialResolutionException(xrdsOut);
}
if (flags.isCid()) {
Status prevStatus = prevXRD.getStatus();
Status s = xrd.getStatus();
String prevCIDStat = prevStatus.getCID();
if (prevCIDStat.equals(Status.CID_FAILED)) {
s.setCID(Status.CID_FAILED);
}
else {
s.setCID(verifyCID(prevXRD, xrd));
}
}
// if we need to do trusted resolution checking
if (flags.isSaml())
{
XRD xrdCopy = (XRD)xrd.clone();
xrdCopy.clearDOM();
// Each descriptor must be validated independently as well as
// against the one that preceded (described) it in the
// descriptor chain.
boolean valid = isTrustedDescriptor(query, xrdCopy, prevService);
// bail if the descriptor is not valid
if (!valid) {
xrd.setStatus(new Status(Status.UNVERIFIED_SIGNATURE, "Signature verification failed."));
throw new PartialResolutionException(xrdsOut);
}
}