Package org.openxri.xml

Examples of org.openxri.xml.XRD


      log.trace("resolveViaProxy - constructed proxy query URI '"
          + uriBuf + "'");

      newURI = new URI(uriBuf.toString());
    } catch (java.net.URISyntaxException oEx) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.INVALID_INPUT,
          "Unable to construct URI to access proxy resolution service");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    } catch (UnsupportedEncodingException e) {
      // thrown from URLEncoder.encode() - this should never happen since the
      // US-ASCII encoding should be supported on every computer or so we hope :)
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.INVALID_INPUT, "Charset not supported");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    } catch (Exception e) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.PERM_FAIL,
          "Unexpected error while constructing proxy URI: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    InputStream in = null;
    try {
      // try to get the data from it
      in = getDataFromURI(newURI, qxri.toURINormalForm(), flags, state).getInputStream();
      XRDS xrds = readXRDS(in);
      XRD finalXRD = xrds.getFinalXRD();

      String code = finalXRD.getStatusCode();
      if ((flags.isRefs() && !code.equals(Status.SUCCESS) && !code
          .equals(Status.REF_NOT_FOLLOWED))
          || !code.equals(Status.SUCCESS)) {
        // got either a non-SUCCESS code or
        // followRefs is on but we got non-SUCCESS and non-REF_NOT_FOLLOWED
        throw new PartialResolutionException(xrds);
      }
      return xrds;
    } catch (PartialResolutionException e) {
      // re-throw
      throw e;
    } catch (Exception e) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.PERM_FAIL, "Error fetching XRDS from proxy: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }
View Full Code Here


        response.sendRedirect(this.bareXRINotFoundRedirect + URLEncoder.encode(qxri, "UTF-8"));
        return;
      }
    }
    response.setStatus(HttpServletResponse.SC_OK);
    XRD xrd = partialXRDS.getFinalXRD();
    String errMsg = "";
    if (xrd != null) {
      Status stat = xrd.getStatus();
      errMsg = "Error code: " + stat.getCode() + " - " + stat.getText();
    }

    if (resMediaType == null) {
      sendError(request, response, qxri, Integer.parseInt(xrd.getStatus().getCode()), errMsg, pre);
    }
    else {
      if (this.onPartialResolutionSuccess(qxri, request, response, Integer.parseInt(xrd.getStatus().getCode()), errMsg, pre)) {
        log.trace("sendPartialResponse - onPartialResolutionSuccess returned true, assuming request is fully handled, returning");
        return;
      }
      if (resMediaType.isType(MimeType.URI_LIST)) {
        sendResponse(response, HTTP_ERROR_CONTENT_TYPE, "# " + errMsg, trustType);
      }
      else if (resMediaType.isType(MimeType.XRDS_XML)) {
        sendResponse(response, isDebug, resMediaType.getType(), partialXRDS.toString(), trustType);
      }
      else if (resMediaType.isType(MimeType.XRD_XML)) {
        sendResponse(response, isDebug, resMediaType.getType(), xrd.toString(), trustType);
      }
      else {
        // else - we should have taken care of it in checkSupportedMediaTypes
        log.error("processProxyRequest - should not reach here (exception)");
      }
View Full Code Here

   
    try {
      XRI ceidX = XRI.fromURINormalForm(ceid.getValue());

      log.info("verifyCEID - resolving CEID");
      XRD ceidXRD = resolveAuthToXRD(ceidX, flags, state);
      Status s = ceidXRD.getStatus();
      if (!s.getCID().equals(Status.CID_VERIFIED)) {
        log.debug("verifyCEID - XRD for CEID is not CID verified");
        return Status.CID_FAILED;
      }
     
      CanonicalID cid2 = ceidXRD.getCanonicalID();
      if (cid2 == null) {
        log.debug("verifyCEID - no CID in the XRD in CEID");
        return Status.CID_FAILED;       
      }
     
      XRI cidX2 = XRI.fromURINormalForm(cid2.getValue());
      if (!cidX2.toURINormalForm().equals(ceidX.toURINormalForm())) {
        log.debug("verifyCEID - CEID's XRD's CID is not equivalent to the original CEID");
        return Status.CID_FAILED;
      }
     
      /// look for an EquivID or CanonicalEquivID backpointer to the original CID
      CanonicalEquivID ceid2 = ceidXRD.getCanonicalEquivID();
      if (ceid2 != null) {
        XRI ceidX2 = XRI.fromURINormalForm(ceid2.getValue());
        if (ceidX2.toURINormalForm().equals(cidX.toURINormalForm())) {
          log.debug("verifyCEID - CEID backpointer found");
          return Status.CID_VERIFIED;
        }
      }

      for (int i = 0; i < ceidXRD.getNumEquivIDs(); i++) {
        EquivID e = ceidXRD.getEquivIDAt(i);
        XRI eX = XRI.fromURINormalForm(e.getValue());
        if (eX.toURINormalForm().equals(cidX.toURINormalForm())) {
          log.debug("verifyCEID - EquivID backpointer found");
          return Status.CID_VERIFIED;         
        }
View Full Code Here

    // insert element into XRD

    try {
     
      xrdElement.appendChild(element);
      xrd = new XRD(xrdElement, false);
    } catch (Exception ex) {
     
      throw new StageException("Unable to parse modified XRD.", ex);
    }
View Full Code Here

    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);
        }
View Full Code Here

    }

    // 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.
View Full Code Here

   * @throws PartialResolutionException
   */
  protected XRDS fetchAuthXRDS(XRI qxri, XRD parent, List authResServices, XRISegment segment, ResolverFlags flags, ResolverState state, String parentXRI) throws PartialResolutionException
  {
    XRDS xrdsOut = null;
    XRD errXRD = null;
    String query = segment.getSubSegmentAt(0).toURINormalForm(true);
   
    ///// Try each URI in each selected service in turn
    Exception savedException = null;
    Iterator srvIterator = authResServices.iterator();
View Full Code Here

 
  protected void checkMaxRequests(XRDS xrdsOut, String query, ResolverState state)
    throws PartialResolutionException
  {
    if (maxRequests >= 0 && state.getNumRequests() >= maxRequests) {
      XRD finalXRD = xrdsOut.getFinalXRD();
      if (finalXRD == null) {
        finalXRD = createErrorXRD(query, Status.LIMIT_EXCEEDED, "Maximum of authority resolution requests exceeded");
        xrdsOut.add(finalXRD);
      } else {
        finalXRD.setStatus(new Status(Status.LIMIT_EXCEEDED,
            "Maximum of authority resolution requests exceeded"));
      }
      throw new PartialResolutionException(xrdsOut);
    }
   
View Full Code Here

 

  private PartialResolutionException
  makeResolutionException(XRDS targetXRDS, String query, String status, String message)
  {
    XRD x = createErrorXRD(query, status, message);
    targetXRDS.add(x);
    return new PartialResolutionException(targetXRDS);
  }
View Full Code Here

    }

    // Describing authority must provide KeyInfo
    KeyInfo oKeyInfo = parentService.getKeyInfo();
    if (oKeyInfo == null) {
                    XRD oXRD = null;
                   
                    if( (isSAMLBypassAuthority(sAuthID)) && ((oXRD = this.getAuthority(sAuthID)) != null) ) {
                            oKeyInfo = oXRD.getServiceAt(0).getKeyInfo();
                    } else {
      log.debug("KeyInfo is missing from describing Authority (or root hint)");
      return false;
    }
                }
View Full Code Here

TOP

Related Classes of org.openxri.xml.XRD

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.