Package org.openid4java.discovery

Examples of org.openid4java.discovery.DiscoveryException


    boolean isSecure = checkSecurity(xrd, id, authority);

    List<Service> services = getServicesForType(xrd.getXrd(), version);

    if (services == null) {
      throw new DiscoveryException("could not find <Service> of type " +
          version + " in XRDS for " + xrd.getSource());
    }

    List<SecureDiscoveryInformation> result =
        Lists.newArrayListWithCapacity(services.size());

    for (Service service : services) {
      try {
        if (version.equals(DiscoveryInformation.OPENID2)) {
          // look for LocalID and use claimedID, if given.
          result.add(createDiscoveryInfoForSignon(service, id, isSecure));
        } else if (version.equals(DiscoveryInformation.OPENID2_OP)) {
          // for site discovery, just return the URI
          result.add(createDiscoveryInfoForServer(service, isSecure));
        } else {
          throw new DiscoveryException("unkown OpenID version : " + version);
        }
      } catch (MalformedURLException e) {
        logger.log(Level.WARNING, "found malformed URL in discovery document " +
            "at " + xrd.getSource(), e);
        continue;
View Full Code Here


  private XrdRepresentations getXrd(URI uri) throws DiscoveryException {
    XrdRepresentations result;
    try {
      result = fetchXrd(uri);
    } catch (FetchException e) {
      throw new DiscoveryException("could not fetch XRDS from "
          + uri.toASCIIString(), e);
    }
    if (result == null) {
      throw new DiscoveryException("XRDS at " + uri.toASCIIString() + " did " +
          "not contain an XRD");
    }
    return result;
  }
View Full Code Here

        Document document = parseXmlInput(input);

        NodeList XRDs = document.getElementsByTagNameNS(XRD_NS, XRD_ELEM_XRD);
        Node lastXRD;
        if (XRDs.getLength() < 1 || (lastXRD = XRDs.item(XRDs.getLength() - 1)) == null)
            throw new DiscoveryException("No XRD elements found.");

        // get the canonical ID, if any (needed for XRIs)
        String canonicalId = null;
        Node canonicalIdNode;
        NodeList canonicalIDs = document.getElementsByTagNameNS(XRD_NS, XRD_ELEM_CANONICALID);
        for (int i = 0; i < canonicalIDs.getLength(); i++) {
            canonicalIdNode = canonicalIDs.item(i);
            if (canonicalIdNode.getParentNode() != lastXRD) continue;
            if (canonicalId != null)
                throw new DiscoveryException("More than one Canonical ID found.");
            canonicalId = canonicalIdNode.getFirstChild() != null && canonicalIdNode.getFirstChild().getNodeType() == Node.TEXT_NODE ?
                canonicalIdNode.getFirstChild().getNodeValue() : null;
        }

        // extract the services that match the specified target types
View Full Code Here

    }

    private Document parseXmlInput(String input) throws DiscoveryException
    {
        if (input == null)
            throw new DiscoveryException("Cannot read XML message",
                OpenIDException.XRDS_DOWNLOAD_ERROR);

        if (DEBUG)
            _log.debug("Parsing XRDS input: " + input);

        try
        {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setValidating(true);
            dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
            dbf.setAttribute(JAXP_SCHEMA_SOURCE, new Object[] {
                Discovery.class.getResourceAsStream(XRD_SCHEMA),
                Discovery.class.getResourceAsStream(XRDS_SCHEMA),
            });
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new ErrorHandler() {
                public void error(SAXParseException exception) throws SAXException {
                    throw exception;
                }

                public void fatalError(SAXParseException exception) throws SAXException {
                    throw exception;
                }

                public void warning(SAXParseException exception) throws SAXException {
                    throw exception;
                }
            });

            return builder.parse(new ByteArrayInputStream(input.getBytes()));
        }
        catch (ParserConfigurationException e)
        {
            throw new DiscoveryException("Parser configuration error",
                    OpenIDException.XRDS_PARSING_ERROR, e);
        }
        catch (SAXException e)
        {
            throw new DiscoveryException("Error parsing XML document",
                    OpenIDException.XRDS_PARSING_ERROR, e);
        }
        catch (IOException e)
        {
            throw new DiscoveryException("Error reading XRDS document",
                    OpenIDException.XRDS_DOWNLOAD_ERROR, e);
        }
    }
View Full Code Here

            _op1Endpoint = url;
        }
        catch (MalformedURLException e)
        {
            throw new DiscoveryException(
                    "Invalid openid.server URL: " + op1Endpoint);
        }

    }
View Full Code Here

            _op2Endpoint = url;

        } catch (MalformedURLException e)
        {
            throw new DiscoveryException(
                    "Invalid openid2.provider URL: " + op2Endpoint);
        }

    }
View Full Code Here

        HTMLDocumentImpl doc = this.parseDocument(htmlData);

        NodeList heads = doc.getElementsByTagName("head");
        if (heads.getLength() != 1)
            throw new DiscoveryException(
                    "HTML response must have exactly one HEAD element, "
                            + "found " + heads.getLength() + " : "
                            + heads.toString(),
                    OpenIDException.DISCOVERY_HTML_PARSE_ERROR);
View Full Code Here

        {
            parser.parse(OpenID4JavaDOMParser.createInputSource(htmlData));
        }
        catch (Exception e)
        {
            throw new DiscoveryException("Error parsing HTML message",
                OpenIDException.DISCOVERY_HTML_PARSE_ERROR, e);
        }

        if (parser.isIgnoredHeadStartElement())
        {
            throw new DiscoveryException(
                    "HTML response must have exactly one HEAD element.",
                    OpenIDException.DISCOVERY_HTML_PARSE_ERROR);
        }

        return (HTMLDocumentImpl) parser.getDocument();
View Full Code Here

        // openid.server
        if (relations.contains("openid.server"))
        {
            if (result.getOP1Endpoint() != null)
                throw new DiscoveryException(
                        "More than one openid.server entries found",
                        OpenIDException.DISCOVERY_HTML_PARSE_ERROR);

            if (DEBUG)
                _log.debug("Found OpenID1 endpoint: " + href);

            result.setEndpoint1(href);
        }

        // openid.delegate
        if (relations.contains("openid.delegate"))
        {
            if (result.getDelegate1() != null)
                throw new DiscoveryException(
                        "More than one openid.delegate entries found",
                        OpenIDException.DISCOVERY_HTML_PARSE_ERROR);

            if (DEBUG)
                _log.debug("Found OpenID1 delegate: " + href);

            result.setDelegate1(href);
        }

        // openid2.provider
        if (relations.contains("openid2.provider"))
        {
            if (result.getOP2Endpoint() != null)
                throw new DiscoveryException(
                        "More than one openid.server entries found",
                        OpenIDException.DISCOVERY_HTML_PARSE_ERROR);

            if (DEBUG)
                _log.debug("Found OpenID2 endpoint: " + href);

            result.setEndpoint2(href);
        }

        // openid2.local_id
        if (relations.contains("openid2.local_id"))
        {
            if (result.getDelegate2() != null)
                throw new DiscoveryException(
                        "More than one openid2.local_id entries found",
                        OpenIDException.DISCOVERY_HTML_PARSE_ERROR);

            if (DEBUG)
                _log.debug("Found OpenID2 localID: " + href);
View Full Code Here

        try
        {
            HttpResponse resp = cache.get(identifier.toString(), requestOptions);

            if (HttpStatus.SC_OK != resp.getStatusCode())
                throw new DiscoveryException( "GET failed on " +
                    identifier.toString() +
                    " Received status code: " + resp.getStatusCode(),
                    OpenIDException.DISCOVERY_HTML_GET_ERROR);

            result.setClaimed( new UrlIdentifier(resp.getFinalUri()) );

            if (resp.getBody() == null)
                throw new DiscoveryException(
                        "No HTML data read from " + identifier.toString(),
                OpenIDException.DISCOVERY_HTML_NODATA_ERROR);

            HTML_PARSER.parseHtml(resp.getBody(), result);
        }
        catch (IOException e)
        {
            throw new DiscoveryException("Fatal transport error: ",
                    OpenIDException.DISCOVERY_HTML_GET_ERROR, e);
        }

        _log.info("HTML discovery completed on: " + identifier);
View Full Code Here

TOP

Related Classes of org.openid4java.discovery.DiscoveryException

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.