org.openid4java.discovery.yadis
Class YadisResolver

java.lang.Object
  extended by org.openid4java.discovery.yadis.YadisResolver

public class YadisResolver
extends java.lang.Object

Yadis discovery protocol implementation.

Yadis discovery protocol returns a Yadis Resource Descriptor (XRDS) document associated with a Yadis Identifier (YadisID)

YadisIDs can be any type of identifiers that are resolvable to a URL form, and in addition the URL form uses a HTTP or a HTTPS schema. Such an URL is defined by the Yadis speficification as a YadisURL. This functionality is implemented by the YadisURL helper class.

The discovery of the XRDS document is performed by the discover method on a YadisUrl.

Internal parameters used during the discovery process :

Author:
Marius Scurtescu, Johnny Bufu, Sutra Zhou

Field Summary
private  HttpFetcher _httpFetcher
           
private static org.apache.commons.logging.Log _log
           
private  int _maxRedirects
          Maximum number of redirects to be followed for the HTTP calls.
private static boolean DEBUG
           
private static XrdsParser XRDS_PARSER
           
private static java.lang.String XRDS_PARSER_CLASS_NAME_KEY
           
private static java.lang.String YADIS_ACCEPT_HEADER
           
private static java.lang.String YADIS_CONTENT_TYPE
           
private static YadisHtmlParser YADIS_HTML_PARSER
           
private static java.lang.String YADIS_HTML_PARSER_CLASS_NAME_KEY
           
static java.lang.String YADIS_XRDS_LOCATION
           
 
Constructor Summary
YadisResolver(HttpFetcher httpFetcher)
           
YadisResolver(HttpFetcherFactory httpFetcherFactory)
           
 
Method Summary
 java.util.List discover(java.lang.String url)
          Performs Yadis discovery on the YadisURL.
 java.util.List discover(java.lang.String url, HttpFetcher httpFetcher)
          Performs Yadis discovery on the YadisURL.
 java.util.List discover(java.lang.String url, int maxRedirects)
          Performs Yadis discovery on the YadisURL.
 java.util.List discover(java.lang.String url, int maxRedirects, HttpFetcher httpFetcher)
          Performs Yadis discovery on the YadisURL.
 YadisResult discover(java.lang.String url, int maxRedirects, HttpFetcher httpFetcher, java.util.Set serviceTypes)
           
 YadisResult discover(java.lang.String url, int maxRedirects, java.util.Set serviceTypes)
           
 java.util.List discoverRP(java.lang.String url)
          Performs Relyin Party discovery on the supplied URL.
private  java.lang.String getHtmlMeta(java.lang.String input)
          Parses the HTML input stream and scans for the Yadis XRDS location in the HTML HEAD Meta tags.
 HttpFetcher getHttpFetcher()
           
 int getMaxRedirects()
          Gets the internal limit configured for the maximum number of redirects to be followed for the HTTP calls.
private  void retrieveXrdsDocument(YadisResult result, int maxRedirects, java.util.Set serviceTypes)
          Tries to retrieve the XRDS document via a GET call on XRDS location provided in the result parameter.
private  YadisResult retrieveXrdsLocation(YadisUrl url, boolean useGet, int maxRedirects, java.util.Set serviceTypes)
          Tries to retrieve the XRDS location url by performing a cheap HEAD call on the YadisURL.
 void setMaxRedirects(int maxRedirects)
          Sets the maximum number of redirects to be followed for the HTTP calls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private static org.apache.commons.logging.Log _log

DEBUG

private static final boolean DEBUG

YADIS_XRDS_LOCATION

public static final java.lang.String YADIS_XRDS_LOCATION
See Also:
Constant Field Values

YADIS_CONTENT_TYPE

private static final java.lang.String YADIS_CONTENT_TYPE
See Also:
Constant Field Values

YADIS_ACCEPT_HEADER

private static final java.lang.String YADIS_ACCEPT_HEADER
See Also:
Constant Field Values

YADIS_HTML_PARSER_CLASS_NAME_KEY

private static final java.lang.String YADIS_HTML_PARSER_CLASS_NAME_KEY
See Also:
Constant Field Values

YADIS_HTML_PARSER

private static final YadisHtmlParser YADIS_HTML_PARSER

XRDS_PARSER_CLASS_NAME_KEY

private static final java.lang.String XRDS_PARSER_CLASS_NAME_KEY
See Also:
Constant Field Values

XRDS_PARSER

private static final XrdsParser XRDS_PARSER

_maxRedirects

private int _maxRedirects
Maximum number of redirects to be followed for the HTTP calls. Defalut 10.


_httpFetcher

private final HttpFetcher _httpFetcher
Constructor Detail

YadisResolver

@Inject
public YadisResolver(HttpFetcherFactory httpFetcherFactory)

YadisResolver

public YadisResolver(HttpFetcher httpFetcher)
Method Detail

getMaxRedirects

public int getMaxRedirects()
Gets the internal limit configured for the maximum number of redirects to be followed for the HTTP calls.


setMaxRedirects

public void setMaxRedirects(int maxRedirects)
Sets the maximum number of redirects to be followed for the HTTP calls.


discoverRP

public java.util.List discoverRP(java.lang.String url)
                          throws DiscoveryException
Performs Relyin Party discovery on the supplied URL.

Parameters:
url - RP's realm or return_to URL
Returns:
List of DiscoveryInformation entries discovered from the RP's endpoints
Throws:
DiscoveryException

discover

public java.util.List discover(java.lang.String url)
                        throws DiscoveryException
Performs Yadis discovery on the YadisURL.

The maximum number of redirects that are followed is determined by the #_maxRedirects member field.

Parameters:
url - YadisURL on which discovery will be performed
Returns:
List of DiscoveryInformation entries discovered obtained from the URL Identifier.
Throws:
DiscoveryException
See Also:
#discover(String, int, HttpCache)

discover

public java.util.List discover(java.lang.String url,
                               HttpFetcher httpFetcher)
                        throws DiscoveryException
Performs Yadis discovery on the YadisURL.

The maximum number of redirects that are followed is determined by the #_maxRedirects member field.

Parameters:
url - YadisURL on which discovery will be performed
httpFetcher - HttpFetcher object to use for the call
Returns:
List of DiscoveryInformation entries discovered obtained from the URL Identifier.
Throws:
DiscoveryException
See Also:
#discover(String, int, HttpCache)

discover

public java.util.List discover(java.lang.String url,
                               int maxRedirects)
                        throws DiscoveryException
Performs Yadis discovery on the YadisURL.

Parameters:
url - YadisURL on which discovery will be performed
maxRedirects - The maximum number of redirects to be followed.
Returns:
List of DiscoveryInformation entries discovered obtained from the URL Identifier.
Throws:
DiscoveryException
See Also:
YadisResult

discover

public java.util.List discover(java.lang.String url,
                               int maxRedirects,
                               HttpFetcher httpFetcher)
                        throws DiscoveryException
Performs Yadis discovery on the YadisURL.

Parameters:
url - YadisURL on which discovery will be performed
maxRedirects - The maximum number of redirects to be followed.
httpFetcher - HttpFetcher object to use for the call.
Returns:
List of DiscoveryInformation entries discovered obtained from the URL Identifier.
Throws:
DiscoveryException
See Also:
YadisResult

discover

public YadisResult discover(java.lang.String url,
                            int maxRedirects,
                            java.util.Set serviceTypes)
                     throws DiscoveryException
Throws:
DiscoveryException

discover

public YadisResult discover(java.lang.String url,
                            int maxRedirects,
                            HttpFetcher httpFetcher,
                            java.util.Set serviceTypes)
                     throws DiscoveryException
Throws:
DiscoveryException

retrieveXrdsDocument

private void retrieveXrdsDocument(YadisResult result,
                                  int maxRedirects,
                                  java.util.Set serviceTypes)
                           throws DiscoveryException
Tries to retrieve the XRDS document via a GET call on XRDS location provided in the result parameter.

Parameters:
result - The YadisResult object containing a valid XRDS location. It will be further populated with the Yadis discovery results.
cache - The HttpClient object to use for placing the call
maxRedirects -
Throws:
DiscoveryException

getHtmlMeta

private java.lang.String getHtmlMeta(java.lang.String input)
                              throws YadisException
Parses the HTML input stream and scans for the Yadis XRDS location in the HTML HEAD Meta tags.

Parameters:
input - input data stream
Returns:
String the XRDS location URL, or null if not found
Throws:
YadisException - on parsing errors or Yadis protocal violations

retrieveXrdsLocation

private YadisResult retrieveXrdsLocation(YadisUrl url,
                                         boolean useGet,
                                         int maxRedirects,
                                         java.util.Set serviceTypes)
                                  throws DiscoveryException
Tries to retrieve the XRDS location url by performing a cheap HEAD call on the YadisURL.

The returned string should be validated before being used as a XRDS-Location URL.

Parameters:
cache - HttpClient object to use for placing the call
maxRedirects -
url - The YadisURL
result - The location of the XRDS document and the normalized Url will be returned in the YadisResult object.

The location of the XRDS document will be null if:

  • the returned status code is different than SC_OK
  • the Yadis header is not present
  • there was an HTTP-level error (allows fallback to GET + HTML response)
Throws:
YadisException - if:
  • there's a (lower level) transport error
  • there are more than one Yadis headers present
DiscoveryException

getHttpFetcher

public HttpFetcher getHttpFetcher()


Copyright 2006-2008 Sxip Identity Corporation