issrg.pba.rbac
Class URLHandler

java.lang.Object
  extended by issrg.pba.rbac.URLHandler
Direct Known Subclasses:
LDAPURLHandler, PMITest.XMLURLHandler, SAMLURLHandler, ShibbolethURLHandler, WebDAVURLHandler

public class URLHandler
extends java.lang.Object

This class is a constructor of various URL-related instances: Subtrees (for domain matching), Principals and Entries (for domain matching). It also maintains a register of URL Handlers for other protocols, so that a relevant URL Handler can be found for a specific URL.

The instances of this class handle all URLs as if they were HTTP URLs. Subclass it and override the methods to handle URLs of other types.

Version:
1.0
Author:
A.Otenko

Field Summary
protected  int defaultPort
           
protected static int FILE_PORT
          This variable is here to allow emulation of file: URLs as HTTP URLs.
static java.lang.String FILE_PROTOCOL
           
static int HTTP_PORT
           
static java.lang.String HTTP_PROTOCOL
           
static int HTTPS_PORT
           
static java.lang.String HTTPS_PROTOCOL
           
protected  java.lang.String protocol
           
static java.lang.String VOMS_SAML_PROTOCOL
           
 
Constructor Summary
protected URLHandler()
           
  URLHandler(java.lang.String protocol, int defaultPort)
          This constructor builds an instance of URLHandler that will be able to handle URLs of given protocol, and listening on given default port.
 
Method Summary
static void addProtocol(URLHandler u)
          This method registers a new protocol URL handler, so if a URL for this protocol has to be parsed, the getPrincipal and getSubtree nodes will know who can handle such URLs.
 int getDefaultPort()
          This method returns the number of the defaul port that the protocol listens on
 Entry getEntry(java.lang.String url)
          This method returns an Entry identified by a given HTTP URL.
static Entry getEntryByURL(java.lang.String url)
          This method returns a Entry object, created by corresponding URLHandler.
 java.security.Principal getPrincipal(java.lang.String url)
          This method returns a Principal for a given HTTP URL string.
static java.security.Principal getPrincipalByURL(java.lang.String url)
          This method returns a Principal, created by corresponding URLHandler.
 java.lang.String getProtocol()
          This method returns the string name of the protocol (without the trailing colon).
static java.lang.String getProtocolName(java.lang.String url)
          This method returns the protocol name, given a URL.
 AttributeRepository getRepository(java.lang.String url)
          This method returns an instance of a repository that would be able to retrieve attributes given the URL.
static AttributeRepository getRepositoryByURL(java.lang.String url)
          This method will find a URLHandler for the protocol and create the AttributeRepository that will provide access to that repository.
 Subtree getSubtree(java.lang.String url, int min, int max, Subtree[] exclude)
          This method returns a Subtree specified using a Base Entry URL and Min and Max level specifications.
static Subtree getSubtreeByURL(java.lang.String url, int min, int max, Subtree[] exclude)
          This method returns a Subtree object, created by corresponding URLHandler.
static URLHandler getURLHandler(java.lang.String protocol)
          This method returns a handler for URLs for a given protocol.
static void removeProtocol(java.lang.String protocol)
          This method removes a protocol handler for a particular protocol name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_PROTOCOL

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

HTTPS_PROTOCOL

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

FILE_PROTOCOL

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

VOMS_SAML_PROTOCOL

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

HTTP_PORT

public static final int HTTP_PORT
See Also:
Constant Field Values

HTTPS_PORT

public static final int HTTPS_PORT
See Also:
Constant Field Values

FILE_PORT

protected static final int FILE_PORT
This variable is here to allow emulation of file: URLs as HTTP URLs.

See Also:
Constant Field Values

protocol

protected java.lang.String protocol

defaultPort

protected int defaultPort
Constructor Detail

URLHandler

protected URLHandler()

URLHandler

public URLHandler(java.lang.String protocol,
                  int defaultPort)
This constructor builds an instance of URLHandler that will be able to handle URLs of given protocol, and listening on given default port.

Parameters:
protocol - the string name of the protocol (without trailing ":"); case of characters is ignored
defaultPort - the number of the default port the protocol listens on
Method Detail

addProtocol

public static void addProtocol(URLHandler u)
This method registers a new protocol URL handler, so if a URL for this protocol has to be parsed, the getPrincipal and getSubtree nodes will know who can handle such URLs.

Parameters:
u - the URLHandler that can handle URLs for a specific protocol

removeProtocol

public static void removeProtocol(java.lang.String protocol)
This method removes a protocol handler for a particular protocol name.

Parameters:
protocol - the protocol name for which handler has to be removed

getURLHandler

public static URLHandler getURLHandler(java.lang.String protocol)
This method returns a handler for URLs for a given protocol.

Parameters:
protocol - the protocol to get the handler for
Returns:
the URLHandler object handling URLs for a given protocol; null, if no handler has been assigned

getProtocolName

public static java.lang.String getProtocolName(java.lang.String url)
                                        throws BadURLException
This method returns the protocol name, given a URL.

Parameters:
url - the URL to get the protocol name from
Returns:
the protocol name as it is in the URL
Throws:
BadURLException - if this is not a URL with a protocol string in it

getPrincipalByURL

public static java.security.Principal getPrincipalByURL(java.lang.String url)
                                                 throws BadURLException
This method returns a Principal, created by corresponding URLHandler.

This is equivalent to getURLHandler(getProtocolName(url)).getPrincipal(url);

Parameters:
url - the URL as the Principal
Returns:
the Principal object, created by corresponding URLHandler; null, if no matching URLHandler has been found
Throws:
BadURLException - if the URL does not have a protocol part, or the URLHandler doesn't like it

getEntryByURL

public static Entry getEntryByURL(java.lang.String url)
                           throws BadURLException
This method returns a Entry object, created by corresponding URLHandler.

This is equivalent to getURLHandler(getProtocolName(url)).getEntry(url);

Parameters:
url - the URL of the Entry
Returns:
the Entry object, created by corresponding URLHandler; null, if no matching URLHandler has been found
Throws:
BadURLException - if the URL does not have a protocol part, or the URLHandler doesn't like it

getSubtreeByURL

public static Subtree getSubtreeByURL(java.lang.String url,
                                      int min,
                                      int max,
                                      Subtree[] exclude)
                               throws BadURLException
This method returns a Subtree object, created by corresponding URLHandler.

This is equivalent to getURLHandler(getProtocolName(url)).getSubtree(url, min, max);

Parameters:
url - the URL of the base Entry
min - the minimum number of levels below the base Entry where the matching entries can be located; pass 0, if no retriction is placed
max - the maximum number of levels below the base Entry where the matching entries can be located; pass -1 if no restriction is placed
exclude - the array of the subtrees specifying what entries to exclude from this subtree
Returns:
the Subtree object, created by corresponding URLHandler; null, if no matching URLHandler has been found
Throws:
BadURLException - if the URL does not have a protocol part, or the URLHandler doesn't like it

getRepositoryByURL

public static AttributeRepository getRepositoryByURL(java.lang.String url)
                                              throws BadURLException
This method will find a URLHandler for the protocol and create the AttributeRepository that will provide access to that repository.

Same as URLHandler.getURLHandler(URLHandler.getProtocolName(url)).getRepository(url);

Parameters:
url - - the URL of the repository
Returns:
AttributeRepository pointed to by the URL, or null, if no repository could be created (e.g. no URLHandler could be found)
Throws:
BadURLException - if the URL is malformed

getProtocol

public java.lang.String getProtocol()
This method returns the string name of the protocol (without the trailing colon). The protocol is in lowercase letters.

Returns:
string name of the protocol in lowercase characters

getDefaultPort

public int getDefaultPort()
This method returns the number of the defaul port that the protocol listens on

Returns:
integer number of the port on which the protocol listens by default

getPrincipal

public java.security.Principal getPrincipal(java.lang.String url)
                                     throws BadURLException
This method returns a Principal for a given HTTP URL string. It checks if the passed URL string matches the protocol this Handler is registered for.

Parameters:
url - the string representation of the HTTP URL (including the protocol name part) (the actual protocol name is checked with the string returned by getProtocol, but the format of the rest of the URL is as specified in HTTP RFC)
Returns:
Principal of the corresponding URL
Throws:
BadURLException - if the URL is malformed

getEntry

public Entry getEntry(java.lang.String url)
               throws BadURLException
This method returns an Entry identified by a given HTTP URL.

This URLHandler does (Entry)getPrincipal(url) - so if your Principal implements the Entry interface, you can leave the getEntry method.

Parameters:
url - the string representation of the HTTP URL (see comments for getPrincipal method)
Returns:
Entry identified by the URL
Throws:
BadURLException - if the URL is malformed

getSubtree

public Subtree getSubtree(java.lang.String url,
                          int min,
                          int max,
                          Subtree[] exclude)
                   throws BadURLException
This method returns a Subtree specified using a Base Entry URL and Min and Max level specifications.

Parameters:
url - the URL of the Base Entry; port may be specified as a range of ports by using nn-mm notation (two numbers separated by hyphen); if no port is specified, any port matches the subtree specification
min - the Min value for the subtree
max - the Max value for the subtree
Throws:
BadURLException - if the URL is malformed
See Also:
Subtree

getRepository

public AttributeRepository getRepository(java.lang.String url)
                                  throws BadURLException
This method returns an instance of a repository that would be able to retrieve attributes given the URL. Some Repositories may use only the host part of the URL to connect to the server, ignoring the path part.

In this version of the URLHandler, no HTTP/HTTPS repositories are implemented, so null is returned for such URLs.

Parameters:
url - - the URL of the repository
Returns:
the AttributeRepository
Throws:
BadURLException