net.sf.container.imp
Class AbstractParseListener

java.lang.Object
  extended by net.sf.container.imp.AbstractParseListener
All Implemented Interfaces:
PolicyParseListener
Direct Known Subclasses:
AbstractPolicyFactory

public abstract class AbstractParseListener
extends java.lang.Object
implements PolicyParseListener

Skeleton of policy file parse listener.

It provides default implementation of all parsing callback events including keystore URL resolving, protection domains creation and etc.

If provides with getter methods getAllKeyStores() and getProtectionDomains() to obtain all parsed keystores and protection domains.

One has to implement PolicyParseListener.getContainerFactory() in order to complete the interfaces. created on August 8, 2005

Since:
Version:
$Revision: 1.1 $
Author:
fiykov
See Also:
AbstractPolicyFactory

Nested Class Summary
 class AbstractParseListener.GrantEntry
          grant entry : temporary data object used to store grant information during the parsing process created on August 8, 2005
 
Constructor Summary
AbstractParseListener()
           
 
Method Summary
 void beginParsing()
          callback to indicate that parsing process begins initialize the vectors
 void endGrant()
          callback when grant definition is over add last grant to the collection of protection domains
 void endParsing()
          callback to indicate that parsing process is over builds the list of protection domains out all parsed grant entries
 void endPolicyFile()
          callback when policy file parsing is over clear the url
protected  java.util.Vector getAllKeyStores()
           
protected  java.util.Vector getAllPolicies()
           
 java.security.KeyStore[] getKeyStores()
           
 java.security.ProtectionDomain[] getProtectionDomains()
           
protected  java.security.cert.Certificate lookupCertificate(java.lang.String alias)
          search all currently known keystores for certificate with given alias returns null if does not exists
protected  java.security.cert.Certificate[] lookupCertificatesList(java.lang.String aliases)
          search all currently known keystores for certificates with given aliases returns empty array if no matching found
 void newGrant(java.lang.String signedbyAliases, java.lang.String codebaseUrl)
          callback when new grant definition is encountered
 void newKeystore(java.lang.String ksUrl, java.lang.String ksType)
          callback when new keystore definition is encountered instantiate the keystore and add it to the collection of keystores Treats ksUrl as following: relative URL, adds it to the policy file's URL in place of last component name absolute URL, tries to instantiate a new URL from that string relative file path, tries to instantiate parent File out of policy file URL and add ksUrl as child to it absolute file path, tries to instantiate new File out of ksUrl If all this fails it will throw FileNotFoundException.
 void newPermission(java.lang.String className, java.lang.String target, java.lang.String action, java.lang.String signedbyAliases)
          callback when new permission grant is encountered signedbyAliases is ignored
 void newPolicyFile(java.net.URL url)
          callback when new policy file parsing starts remember the url
protected  java.io.InputStream newUrlInputSteam(java.lang.String strUrl)
          instantiates new InputStream out of given URL
protected  java.lang.String parseEnvVars(java.lang.String str)
          parse given text and substitute all environment variables with their values (marked in in the format ${env-name} ).
protected  java.lang.String replaceCurrentUrlPosition(java.net.URL url, java.lang.String newFile)
          replace last file position in the given URL with new file
protected  java.io.InputStream resolveKsInputSteam(java.lang.String ksUrl)
          locate keystore's input stream or throw FileNotFoundException.
protected  void spreadDefaultGrants()
          this method is called after the parse of a policy file to kind of "spread" default permissions to all grant entries (i.e. protection domains)
protected  java.lang.String toExternalForm(java.net.URL u, java.lang.String newPath)
          Converts a URL of a specific protocol to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.container.PolicyParseListener
getContainerFactory
 

Constructor Detail

AbstractParseListener

public AbstractParseListener()
Method Detail

getAllPolicies

protected java.util.Vector getAllPolicies()
Returns:
all known to the moment factory aware protection domains. one can use this method while parsing is ongoing.

getAllKeyStores

protected java.util.Vector getAllKeyStores()
Returns:
all known to the moment keystores one can use this method while parsing is ongoing.

getProtectionDomains

public java.security.ProtectionDomain[] getProtectionDomains()
Returns:
all parsed protection domains, call this after parsing is over i.e. endParsing() has been called

getKeyStores

public java.security.KeyStore[] getKeyStores()
Returns:
all parsed keystores, call this after parsing is over i.e. endParsing() has been called

newUrlInputSteam

protected java.io.InputStream newUrlInputSteam(java.lang.String strUrl)
instantiates new InputStream out of given URL

Parameters:
strUrl -
Returns:
associated URL InputStream or null in case of exception

toExternalForm

protected java.lang.String toExternalForm(java.net.URL u,
                                          java.lang.String newPath)
Converts a URL of a specific protocol to a String.

Parameters:
u - the URL.
Returns:
a string representation of the URL argument.

replaceCurrentUrlPosition

protected java.lang.String replaceCurrentUrlPosition(java.net.URL url,
                                                     java.lang.String newFile)
replace last file position in the given URL with new file

Parameters:
url -
newFile -
Returns:
new url or null if there is no last '/' delimiter in given url

resolveKsInputSteam

protected java.io.InputStream resolveKsInputSteam(java.lang.String ksUrl)
                                           throws java.io.FileNotFoundException
locate keystore's input stream or throw FileNotFoundException.

Treats ksUrl as following:

If all this fails it will throw FileNotFoundException.

Parameters:
ksUrl -
Returns:
input stream of the keystore resource
Throws:
java.io.FileNotFoundException

beginParsing

public void beginParsing()
callback to indicate that parsing process begins

initialize the vectors

Specified by:
beginParsing in interface PolicyParseListener

endParsing

public void endParsing()
callback to indicate that parsing process is over

builds the list of protection domains out all parsed grant entries

Specified by:
endParsing in interface PolicyParseListener

newPolicyFile

public void newPolicyFile(java.net.URL url)
callback when new policy file parsing starts

remember the url

Specified by:
newPolicyFile in interface PolicyParseListener
Parameters:
url - of the policy file

endPolicyFile

public void endPolicyFile()
callback when policy file parsing is over

clear the url

Specified by:
endPolicyFile in interface PolicyParseListener

newKeystore

public void newKeystore(java.lang.String ksUrl,
                        java.lang.String ksType)
                 throws java.io.FileNotFoundException,
                        java.security.KeyStoreException,
                        java.io.IOException,
                        java.security.NoSuchAlgorithmException,
                        java.security.cert.CertificateException
callback when new keystore definition is encountered

instantiate the keystore and add it to the collection of keystores

Treats ksUrl as following:

If all this fails it will throw FileNotFoundException.

Specified by:
newKeystore in interface PolicyParseListener
Parameters:
ksUrl - is mandatory, url is relative to the policy file location
ksType - is optional, null if not present in the policy file
Throws:
java.io.FileNotFoundException - if the keystore does not exists
java.security.KeyStoreException - while opening the keystore
java.io.IOException - while reading the keystore
java.security.NoSuchAlgorithmException - while reading the certificates
java.security.cert.CertificateException - while reading the certificates

newGrant

public void newGrant(java.lang.String signedbyAliases,
                     java.lang.String codebaseUrl)
              throws java.net.MalformedURLException,
                     java.security.KeyStoreException
callback when new grant definition is encountered

Specified by:
newGrant in interface PolicyParseListener
Parameters:
signedbyAliases - is optional, list of certificate aliases separated by semicolon
codebaseUrl - is optional, url pattern compatible with Policy File specification
Throws:
java.net.MalformedURLException
java.security.KeyStoreException

endGrant

public void endGrant()
callback when grant definition is over

add last grant to the collection of protection domains

Specified by:
endGrant in interface PolicyParseListener

newPermission

public void newPermission(java.lang.String className,
                          java.lang.String target,
                          java.lang.String action,
                          java.lang.String signedbyAliases)
                   throws java.lang.ClassNotFoundException,
                          java.lang.NoSuchMethodException,
                          java.lang.SecurityException,
                          java.lang.InstantiationException,
                          java.lang.IllegalAccessException,
                          java.lang.IllegalArgumentException,
                          java.lang.reflect.InvocationTargetException
callback when new permission grant is encountered

signedbyAliases is ignored

Specified by:
newPermission in interface PolicyParseListener
Parameters:
className - is mandatory, fully qualified class name
target - is mandatory depending on the permission type
action - is mandatory depending on the permission type
signedbyAliases - is optional, a list of certificate aliased separated by semicolon
Throws:
java.lang.ClassNotFoundException - if the permission class if not found
java.lang.NoSuchMethodException - if the permission class does not have suitable constructor
java.lang.SecurityException - while instantiating a new permission
java.lang.InstantiationException - while instantiating a new permission
java.lang.IllegalAccessException - while instantiating a new permission
java.lang.IllegalArgumentException - while instantiating a new permission
java.lang.reflect.InvocationTargetException - while instantiating a new permission

lookupCertificate

protected java.security.cert.Certificate lookupCertificate(java.lang.String alias)
                                                    throws java.security.KeyStoreException
search all currently known keystores for certificate with given alias returns null if does not exists

Parameters:
alias -
Returns:
found certificate or null if such does not exists
Throws:
java.security.KeyStoreException

lookupCertificatesList

protected java.security.cert.Certificate[] lookupCertificatesList(java.lang.String aliases)
                                                           throws java.security.KeyStoreException
search all currently known keystores for certificates with given aliases returns empty array if no matching found

Parameters:
aliases -
Returns:
the certificate or null of such does not exists
Throws:
java.security.KeyStoreException - if keystore not initialized or no alias by given name

parseEnvVars

protected java.lang.String parseEnvVars(java.lang.String str)
parse given text and substitute all environment variables with their values (marked in in the format ${env-name} ).

Parameters:
str -
Returns:
parsed text

spreadDefaultGrants

protected void spreadDefaultGrants()
this method is called after the parse of a policy file to kind of "spread" default permissions to all grant entries (i.e. protection domains)



Copyright © 2007 Nikolay Fiykov. All Rights Reserved.