Package org.openxri.xml

Examples of org.openxri.xml.XRDS


  protected XRDS processRedirects(XRI qxri, XRD parent, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    log.trace("processRedirects (qxri=" + qxri + ")");
   
    XRDS xrdsOut = new XRDS();
    XRDS tmpXRDS;
    List redirects = parent.getPrioritizedRedirects();
    Iterator it = redirects.iterator();
   
    // there must be some redirects!
    if (!it.hasNext())
View Full Code Here


   * @throws PartialResolutionException
   */
  protected XRDS fetchAuthXRDSHelper(XRI qxri, URI uri, XRD parent, Service parentService, XRISegment segment, ResolverFlags flags, ResolverState state)
    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");
    }

    XRDS tmpXRDS = null;
    // now that we've constructed the new URI, try to return the stream from it
    try {
      InputStream in = getDataFromURI(newURI, segment.toString(), flags, state);
      tmpXRDS = readXRDS(in);
      log.debug("fetchAuthXRDS - got XRDS = " + tmpXRDS.toString());
    } 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;

    // 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);

      // status is not success
      ServerStatus sstat = xrd.getServerStatus();
      Status stat;
View Full Code Here

   * @return
   * @throws PartialResolutionException
   */
  protected XRDS fetchAuthXRDS(XRI qxri, XRD parent, List authResServices, XRISegment segment, ResolverFlags flags, ResolverState state) throws PartialResolutionException
  {
    XRDS xrdsOut = null;
    XRD errXRD = null;
    String query = segment.getSubSegmentAt(0).toURINormalForm(true);
   
    //// TODO verify synonyms

    ///// Try each URI in each selected service in turn
    Exception savedException = null;
    Iterator srvIterator = authResServices.iterator();
    while (srvIterator.hasNext()) {     
      Service srv = (Service) srvIterator.next();
      Iterator uriIterator = srv.getPrioritizedURIs().iterator();
     
      while (uriIterator.hasNext()) {
        SEPUri sepURI = (SEPUri) uriIterator.next();
        URI uri = sepURI.getURI();

        log.trace("fetchAuthXRDS - trying URI='" + uri + "'");

        // skip non-HTTPS URIs if HTTPS was requested
        if (flags.isHttps() && !uri.getScheme().equals(HTTPS)) {
          log.trace("fetchAuthXRDS - skipping non HTTPS URI");
          continue;
        }

        try {
          xrdsOut = fetchAuthXRDSHelper(qxri, uri, parent, srv, segment, flags, state);
          // if no error, return immediately
          return xrdsOut;
        }
        catch (PartialResolutionException e) {
          xrdsOut = e.getPartialXRDS();
        }
      }
    }

    if (xrdsOut == null) { // no appropriate URI found
      xrdsOut = new XRDS();
      String code = flags.isHttps()? Status.TRUSTED_RES_ERROR : Status.AUTH_RES_ERROR;
      xrdsOut.add(createErrorXRD(query, code, "No URI found for authority resolution"));
    }
    throw new PartialResolutionException(xrdsOut);
  }
View Full Code Here

      ResolverFlags flags, ResolverState state)
      throws PartialResolutionException
  {
    log.trace("resolveAuthSegment - segment='" + segment + "'");

    XRDS xrdsOut = new XRDS();
    XRDS tmpXRDS = null;
    CanonicalID parentCID = null;
    boolean authResComplete = false;
    ResolverFlags currentFlags = null; // this is only for overriding by HttpsBypassAuthority settings

    String parentXRI = ((XRIAuthority)qxri.getAuthorityPath()).getRootAuthority();
    XRISegment remainingSegment = segment;
   
    while (remainingSegment != null && remainingSegment.getNumSubSegments() > 0) {
      // clone flags
      currentFlags = new ResolverFlags(flags);
     
      // more subsegments to resolve
      String query = remainingSegment.getSubSegmentAt(0).toURINormalForm(true);

      log.debug("resolveAuthSegment - resolving subsegment '" + query + "'");
     
      checkMaxRequests(xrdsOut, query, state);
     
      // if HTTPS is requested and what we are resolving is allowed to bypass HTTPS, we turn off the HTTPS flag
      // for auth-res service selection
      if (currentFlags.isHttps() && isHttpsBypassAuthority(parentXRI)) {
        log.debug("Bypassing HTTPS for " + parentXRI);
        currentFlags.setHttps(false);
      }
     
      //// perform service selection
      String authResMediaType = Tags.CONTENT_TYPE_XRDS + ";" + currentFlags.getTrustParameters();
      List authResServices = selectServices(parent.getServices(), Tags.SERVICE_AUTH_RES, null, authResMediaType, currentFlags);
      if (authResServices.size() < 1) {
        log.debug("resolveAuthSegment - no authority resolution service found!");
        throw makeResolutionException(
          xrdsOut,
          query,
          Status.AUTH_RES_NOT_FOUND,
          "Authority Resolution Service Not Found"
        );
      }

      try {
        // retrieve XRDS documents for the given subsegment
        log.trace("resolveAuthSegment - fetching XRDS");
        tmpXRDS = fetchAuthXRDS(qxri, parent, authResServices, remainingSegment, currentFlags, state);
      }
      catch (PartialResolutionException e) {
        log.trace("got PRE: " + e.getPartialXRDS());
        log.trace("xrdsOut.n = " + xrdsOut.getNumChildren() + ", partialXRDS.n=" + e.getPartialXRDS().getNumChildren());
        xrdsOut.add(e.getPartialXRDS());
        throw new PartialResolutionException(xrdsOut);       
      }
     
      //// add the subsegments
      xrdsOut.addAll(tmpXRDS);
     
      //// replace parent XRD
      parent = tmpXRDS.getFinalXRD();
     
      for (int k = 0; k < tmpXRDS.getNumChildren(); k++) {
        XRISubSegment subseg = remainingSegment.getSubSegmentAt(k);
        parentXRI = parentXRI + subseg;
      }
     
      remainingSegment = remainingSegment.getRemainder(tmpXRDS.getNumChildren());

      tmpXRDS = null;     
      try {
        if (parent.getNumRedirects() > 0) {
          log.debug("resolveAuthSegment - processing Redirect(s)");
          tmpXRDS = processRedirects(qxri, parent, currentFlags, state);
          xrdsOut.addAll(tmpXRDS);
          // replace parent
          parent = tmpXRDS.getFinalXRD();
        }
        else if (parent.getNumRefs() > 0) {
          if (!currentFlags.isRefs()) {
            throw makeResolutionException(
              xrdsOut,
              query,
              Status.REF_NOT_FOLLOWED,
              "Ref not followed");
          }
          log.debug("resolveAuthSegment - processing Ref(s)");
          tmpXRDS = processRefs(parent, currentFlags, state);
          xrdsOut.addAll(tmpXRDS);
          // replace parent
          parent = tmpXRDS.getFinalXRD();
        }       
      }
      catch (PartialResolutionException e) {
        xrdsOut.addAll(e.getPartialXRDS());
        log.debug("resolveAuthSegment - got PRE while processing Ref or Redirect");
View Full Code Here

 
 
  protected XRDS processRefs(XRD parent, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    XRDS xrdsOut = new XRDS();
    //// get all the Refs in the parent XRD
    List refs = parent.getPrioritizedRefs();
    Iterator it = refs.iterator();
   
    //// try each one in turn
    while (it.hasNext()) {
      Ref ref = (Ref)it.next();

      checkMaxRefs(xrdsOut, ref.getValue(), state);

      XRI refXRI;
      try {
        refXRI = parseAbsoluteQXRIOrError(ref.getValue());
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        continue;
      }
     
      // record that we are following a ref
      state.pushFollowingRef(refXRI);
     
      try {
        XRDS tmpXRDS = resolveAuthority(refXRI, flags, state);
        xrdsOut.add(tmpXRDS);
        break;
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
View Full Code Here

          // construct URI
          String constructedURI = constructURI(uri, r.getAppend(), qxri);
          uri = new URI(constructedURI);
        }
      } catch (URISyntaxException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(r.getValue(), Status.INVALID_REDIRECT, "Invalid Redirect URI");
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
        continue;
      }
     
      try {
        XRDS tmpXRDS = fetchRedirectXRDS(uri, parent, qxri, flags, state);
        xrdsOut.add(tmpXRDS);
       
        XRD finalXRD = tmpXRDS.getFinalXRD();
        tmpXRDS = new XRDS();
        List services = selectServiceFromXRD(tmpXRDS, finalXRD, qxri, sepType, sepMediaType, flags, state);
        xrdsOut.addAll(tmpXRDS);
        return services; // we're done!
      } catch (XRIResolutionException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(uri.toString(), Status.REDIRECT_ERROR, "Error fetching XRDS: " + e.getMessage());
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
       
        // fall through to continue to the next
      }
    }
View Full Code Here

     
      // record that we are following a ref
      state.pushFollowingRef(refXRI);
     
      try {
        XRDS tmpXRDS = resolveSEPToXRDS(refXRI, sepType, sepMediaType, flags, state);
        xrdsOut.add(tmpXRDS);
        return tmpXRDS.getFinalXRD().getSelectedServices().getList();
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        // fall through to continue to the next
      }
View Full Code Here

 
 
  protected XRDS fetchRedirectXRDS(URI uri, XRD parent, XRI qxri, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
      XRDS xrdsOut = new XRDS();
      String query = qxri.toURINormalForm();
      xrdsOut.setRedirect(uri.toString());
     
      XRDS tmpXRDS = null;
      try {
        log.info("fetchRedirectXRDS - fetching from URI(" + uri + ")");
        InputStream in = getDataFromURI(uri, query, flags, state);
       
        log.info("fetchRedirectXRDS - reading content from URI(" + uri + ")");
        tmpXRDS = readXRDS(in);

        log.debug("fetchRedirectXRDS - got XRDS = " + tmpXRDS.toString());
      } catch (IOException e) {
        log.error("fetchRedirectXRDS - got IOException from URI " + uri);
        throw makeResolutionException(xrdsOut, query, Status.NETWORK_ERROR, "Networking error encountered");
      } catch (Exception e) {
        log.error("fetchRedirectXRDS - unexpected error: " + e);
        e.printStackTrace();
        throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, e.getMessage());
      }

      //// sanity checks
     
      // there should be exactly one child element
      if (tmpXRDS.getNumChildren() != 1 || !tmpXRDS.isXRDAt(0)) {
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document: single XRD element expected");
      }
     
      if (!tmpXRDS.isXRDAt(0))
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Authority XRDS document should not contain XRDS element");

      XRD xrd = tmpXRDS.getDescriptorAt(0);
      xrdsOut.add(xrd);


      ServerStatus sstat = xrd.getServerStatus();
      Status stat;
View Full Code Here

      return xrdsOut;
  }
 

  protected XRDS readXRDS(InputStream in) throws XRIResolutionException {
    XRDS xrds = null;

    if (in == null) {
      return xrds;
    }

    // Read response into DOM structure
    try {
      log.debug("readXRDS - parsing input stream");
      DOMParser domParser = DOMUtils.getDOMParser();
      domParser.parse(new InputSource(in));
      Document doc = domParser.getDocument();
      Element element = doc.getDocumentElement();
      log.debug("readXRDS - successfully read XML document into DOM");
      xrds = new XRDS(element, true);
      log.debug("readXRDS - successfully parsed XRDS document");
    } catch (IOException e) {
      throw new XRIResolutionException("I/O error while reading XRDS document: " + e, e);
    } catch (SAXException e) {
      throw new XRIResolutionException("Invalid XRDS document: " + e, e);
View Full Code Here

    boolean signed = checkSigned(request);

    // the goal is to get a complete XRDS document

    XRDS xrds = null;

    // let our URIMapper tell us what to do

    URIMapperResult data = this.uriMapper.parseRequest(new URIMapperRequest(request));

    String namespace = (data == null) ? null : data.getNamespace();
    String query = (data == null) ? null : data.getQuery();

    if (namespace != null && namespace.trim().equals("")) namespace = null;
    if (query != null && query.trim().equals("")) query = null;

    String path = request.getRequestURI().substring(request.getContextPath().length() + 1);

    // use the Server to get an XRDS

    try {

      // got a namespace but no query? that means the client wants a self-describing XRDS

      if (namespace != null && query == null) {

        // ask the Server to give us a self-describing XRDS for the namespace

        log.debug("Looking up self-describing descriptor.");

        xrds = this.server.lookupSelfDescribing(namespace, signed);
      }

      // got a namespace and a query? that means the client wants normal authority resolution

      if (namespace != null && query != null) {

        // ask the Server to give us an XRDS for the namespace and query

        log.debug("Looking up descriptor by namespace and query.");

        xrds = this.server.lookupByNamespace(namespace, query, signed);
      }

      // got neither a namespace nor a query? try getting an XRDS by path

      if (namespace == null && query == null) {

        // ask the Server to give us an XRDS for the path

        log.debug("Looking up descriptor by path.");

        xrds = this.server.lookupByPath(path, signed);
      }
    } catch (Exception ex) {

      log.warn("Internal server problem during resolution.", ex);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
      return;
    }

    // if we were not able to get an XRDS, let the plugin handle the request

    if (xrds == null || xrds.getNumXRD() < 1) {

      if (this.plugin == null) {

        log.warn("No plugin installed.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request.");
        return;
      }

      log.debug("Forwarding request to plugin.");

      boolean ret = this.plugin.processCustomRequest(request, response);

      // did the plugin handle the request?

      if (ret == true) {

        log.debug("Plugin successfully handled the request.");
        return;
      } else {

        log.warn("Plugin failed to handle the request.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Plugin failed to handle the request.");
        return;
      }
    }

    // send out the result

    String body = xrds.serializeDescriptorDOM(false, true);

    log.debug("Resolution successful. Sending descriptor.");
    response.setStatus(HttpServletResponse.SC_OK);
   
    if (xrds.getFinalXRD().getSAMLAssertion() != null)
      response.setContentType(Tags.CONTENT_TYPE_XRDS + ";saml=true;charset=UTF-8");
    else
      response.setContentType(Tags.CONTENT_TYPE_XRDS + ";charset=UTF-8");

    response.getOutputStream().write(body.getBytes("UTF-8"));
View Full Code Here

TOP

Related Classes of org.openxri.xml.XRDS

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.