public class PolicyFileHiveFactory extends Object implements HiveFactory
grant[ principal <principal class> "name"] { permission <permission class> "name",[ "actions"]; };where [] denotes an optional block, <> denotes a classname.
Constructor and Description |
---|
PolicyFileHiveFactory(ActionFactory actionFactory)
Constructs a new factory that builds a Hive out of one (1) or more policy files.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addPolicyFile(URL file)
Adds a new Hive policy file to this factory.
|
boolean |
addReader(Reader input)
Adds a new Hive policy to this factory.
|
boolean |
addStream(InputStream stream)
Adds a new Hive policy to this factory.
|
protected String |
arrayToString(Object[] array)
Generates a comma (,) separated string of all the items in the array
|
protected BasicHive |
constructHive()
Changeable by subclasses to return there own hive subclass.
|
Hive |
createHive()
This method is not thread safe.
|
protected ActionFactory |
getActionFactory()
Gets actionFactory.
|
String |
getAlias(String key)
Returns the value of the alias.
|
protected int |
getCurrentLineNr()
The current line being read.
|
protected Set<URL> |
getPolicyFiles()
A readonly view of the policy files added to this factory.
|
protected Set<Reader> |
getReaders()
A readonly view of the readers added to this factory.
|
protected Set<InputStream> |
getStreams()
A readonly view of the streams added to this factory.
|
boolean |
isCloseInputStreams()
Gets closeInputStreams.
|
boolean |
isUsingHiveCache()
Flag indicating if caching for the
Hive is enabled or disabled. |
protected void |
notifyFileClose(URL file,
int lineNr)
Notifies when a file is closed, either because the end of the file was reached or because an
uncaught exception was thrown.
|
protected void |
notifyFileStart(URL file)
Notifies when a new file is about to be read.
|
protected void |
notifyOfPrincipal(int lineNr,
Principal principal)
Notifies of a new Principal read in the policy file.
|
protected void |
notifyPermission(int lineNr,
Class<? extends Permission> permissionClass,
Class<?>[] args)
Notifies when a Permission could not be created because no suitable constructor was found.
|
protected void |
notifyPermission(int lineNr,
Principal principal,
Permission permission)
Notifies when a permission is added to a principal.
|
protected void |
notifyReaderEnd(Reader input,
int lineNr)
Notifies that the
Reader will be read no further. |
protected void |
notifyReaderStart(Reader input)
Notifies that a reader is about to be read.
|
protected void |
notifyStreamEnd(InputStream stream,
int lineNr)
Notifies that the stream will be read no further.
|
protected void |
notifyStreamStart(InputStream stream)
Notifies that a stream is about to be read.
|
protected void |
read(Reader input,
BasicHive hive)
Reads principals and permissions from a
Reader , found items are added to the hive. |
protected void |
readInputReader(Reader input,
BasicHive hive)
Reads principals and permissions from a
Reader , found items are added to the hive. |
protected void |
readInputStream(InputStream stream,
BasicHive hive)
Reads principals and permissions from a stream, found items are added to the hive.
|
protected void |
readPolicyFile(URL file,
BasicHive hive)
Reads principals and permissions from a file, found items are added to the hive.
|
protected void |
readReader(Reader input,
BasicHive hive)
Reads principals and permissions from a
Reader , found items are added to the hive. |
protected void |
readStream(InputStream input,
BasicHive hive)
Reads principals and permissions from a
InputStream , found items are added to the
hive. |
String |
setAlias(String key,
String value)
Sets the value for an alias, overwrites any existing alias with the same name
|
void |
setCloseInputStreams(boolean closeInputStreams)
Sets closeInputStreams.
|
protected void |
skipEmptyPrincipal(int lineNr,
Principal principal)
Notifies when a principal is skipped because there are no permissions attached.
|
protected void |
skipIllegalPermission(int lineNr,
Principal principal,
Permission permission)
Notifies of permissions located outside the { and }; block statements but after a valid
principal was found.
|
protected void |
skipIllegalPrincipal(int lineNr,
Principal principal,
Set<Permission> permissions)
Notifies when a
Principal begins at an illegal place in the file. |
protected void |
skipLine(int lineNr,
String line)
Notifies when a line is skipped because it was not understood for any other reason.
|
protected void |
skipPermission(int lineNr,
Class<?> permissionClass)
Notifies when a Class is skipped because it is not a Permission or no valid constructors
could be found.
|
protected void |
skipPermission(int lineNr,
Class<? extends Permission> permissionClass,
Object[] argValues,
Exception e)
Notified when a new instance of the permission could not be created.
|
protected void |
skipPermission(int lineNr,
Principal principal,
Permission permission)
Notifies of duplicate permissions for a principal.
|
protected void |
skipPermission(int lineNr,
String classname,
ClassNotFoundException e)
Notifies when a permission class could not be found.
|
protected void |
skipPrincipal(int lineNr,
Class<? extends Principal> principalClass)
Notifies when the principal does not have an accessible constructor for a single
String argument. |
protected void |
skipPrincipal(int lineNr,
Class<? extends Principal> principalClass,
Exception e)
Notifies when a new instance of the principl could not be created.
|
protected void |
skipPrincipalClass(int lineNr,
Class<?> principalClass)
Notifies when a classname is not a
Principal . |
protected void |
skipPrincipalClass(int lineNr,
String classname,
ClassNotFoundException e)
Notifies when a Principal class could not be found.
|
void |
useHiveCache(boolean useCache)
Sets useHiveCache.
|
protected void |
warnUnclosedPrincipalBlock(Principal principal,
int lineNr)
Warning when the last principal of a file is not properly closed.
|
public PolicyFileHiveFactory(ActionFactory actionFactory)
AllPermissions
.actionFactory
- factory required to create the actions for the permissionsIllegalArgumentException
- if the factory is nullpublic final boolean addPolicyFile(URL file)
createHive()
is executed. Url's are always retained for possible re-use.file
- protected final Set<URL> getPolicyFiles()
URL
'spublic final boolean addStream(InputStream stream)
createHive()
is
executed. Depending on the state of the flag isCloseInputStreams()
the stream is
closed or left untouched after it is read. In all cases the stream is removed from the
factory after being read. The format of the inputstream must be the same as that of a regular
policy file.stream
- protected final Set<InputStream> getStreams()
InputStream
spublic final boolean addReader(Reader input)
createHive()
is
executed. Depending on the state of the flag isCloseInputStreams()
the reader is
closed or left untouched after it is read. In all cases the reader is removed from the
factory after being read. The format of the inputstream must be the same as that of a regular
policy file.input
- protected final Set<Reader> getReaders()
Reader
spublic final String getAlias(String key)
key
- the part between the ${}public final String setAlias(String key, String value)
key
- the part between the ${}value
- the value the alias is replaced with at hive creation time.protected final int getCurrentLineNr()
protected BasicHive constructHive()
createHive()
. Default implementation return either a
SimpleCachingHive
or a BasicHive
depending on isUsingHiveCache()
BasicHive
subclass.public final Hive createHive()
createHive
in interface HiveFactory
HiveFactory.createHive()
protected final void readPolicyFile(URL file, BasicHive hive) throws IOException
file
- the file to readhive
- the hive where found items are appended to.IOException
- if a problem occurs while reading the filereadStream(InputStream, BasicHive)
protected final void readInputStream(InputStream stream, BasicHive hive) throws IOException
isCloseInputStreams()
flag.stream
- the stream to readhive
- the hive where found items are appended to.IOException
- if a problem occurs while reading the fileisCloseInputStreams()
,
setCloseInputStreams(boolean)
,
readStream(InputStream, BasicHive)
protected final void readInputReader(Reader input, BasicHive hive) throws IOException
Reader
, found items are added to the hive.
The reader is closed depending on the isCloseInputStreams()
flag.input
- the reader to readhive
- the hive where found items are appended to.IOException
- if a problem occurs while reading the fileisCloseInputStreams()
,
setCloseInputStreams(boolean)
,
readStream(InputStream, BasicHive)
protected void readReader(Reader input, BasicHive hive) throws IOException
Reader
, found items are added to the hive.
Subclasses should override this method or readStream(InputStream, BasicHive)
if they
want do do something different from the default. No need to call the notifyMethods as that is
handled by readInputReader(Reader, BasicHive)
and
readInputStream(InputStream, BasicHive)
respectively. Default implementation is to
call read(Reader, BasicHive)
. This method never closes the reader.input
- hive
- IOException
protected void notifyStreamEnd(InputStream stream, int lineNr)
stream
- lineNr
- number of lines processedprotected void notifyReaderStart(Reader input)
input
- the readerprotected void notifyReaderEnd(Reader input, int lineNr)
Reader
will be read no further. Typically this is because the end
of the stream is reached but it is also called when an exception occurs while reading the
reader.input
- lineNr
- number of lines processedprotected void notifyStreamStart(InputStream stream)
stream
- the streamprotected void readStream(InputStream input, BasicHive hive) throws IOException
InputStream
, found items are added to the
hive. This method never closes the input stream.input
- hive
- IOException
protected final void read(Reader input, BasicHive hive) throws IOException
Reader
, found items are added to the hive.
This method never closes the reader.input
- hive
- IOException
protected void warnUnclosedPrincipalBlock(Principal principal, int lineNr)
principal
- lineNr
- protected void notifyFileClose(URL file, int lineNr)
file
- the filelineNr
- the last line readprotected void notifyFileStart(URL file)
file
- the fileprotected void skipPermission(int lineNr, String classname, ClassNotFoundException e)
lineNr
- the faulty lineclassname
- the class of the permissione
- the exception thrown when trying to locate the classprotected void notifyPermission(int lineNr, Principal principal, Permission permission)
lineNr
- the currently process lineprincipal
- the current principalpermission
- the permission added to the principalprotected void skipPermission(int lineNr, Principal principal, Permission permission)
lineNr
- the duplicate lineprincipal
- the principalpermission
- the duplicate permissionprotected void skipIllegalPermission(int lineNr, Principal principal, Permission permission)
lineNr
- the line declaring the illegal permissionprincipal
- the declared principalpermission
- the declared permissionprotected void skipPrincipalClass(int lineNr, String classname, ClassNotFoundException e)
lineNr
- the faulty lineclassname
- the class of the Principale
- the exception thrown when the class could not be foundprotected void skipPrincipal(int lineNr, Class<? extends Principal> principalClass)
String
argument. Default is to log the exception.lineNr
- the faulty lineprincipalClass
- the class of the Principalprotected void notifyOfPrincipal(int lineNr, Principal principal)
lineNr
- the line currently processedprincipal
- the principlprotected void skipPrincipal(int lineNr, Class<? extends Principal> principalClass, Exception e)
lineNr
- the line currently readprincipalClass
- the class of the principale
- the exception thrown when trying to create a new instanceprotected void skipPrincipalClass(int lineNr, Class<?> principalClass)
Principal
. Default is to log the exception.lineNr
- the faulty lineprincipalClass
- the class which is not a subclass of Principalprotected void skipLine(int lineNr, String line)
lineNr
- the number of the line in the fileline
- the line that was skippedprotected void skipPermission(int lineNr, Class<? extends Permission> permissionClass, Object[] argValues, Exception e)
lineNr
- the faulty linepermissionClass
- the class trying to instantiateargValues
- the constructor argument(s)e
- the exception thrown when trying to create a new instanceprotected final String arrayToString(Object[] array)
array
- the inputprotected void notifyPermission(int lineNr, Class<? extends Permission> permissionClass, Class<?>[] args)
lineNr
- the faulty linepermissionClass
- the class of the permissionargs
- the number and type of constructor argumentsprotected void skipPermission(int lineNr, Class<?> permissionClass)
lineNr
- the faulty linepermissionClass
- the class (if available)protected void skipEmptyPrincipal(int lineNr, Principal principal)
lineNr
- the line closing the principal.principal
- the skipped principalprotected void skipIllegalPrincipal(int lineNr, Principal principal, Set<Permission> permissions)
Principal
begins at an illegal place in the file. Default is to log
an exception.lineNr
- the faulty lineprincipal
- the principal we are currently working onpermissions
- the permission collected for the current principal so far.public final boolean isUsingHiveCache()
Hive
is enabled or disabled. Default is enabled.public final void useHiveCache(boolean useCache)
useCache
- enable or disable cachingpublic final boolean isCloseInputStreams()
public final void setCloseInputStreams(boolean closeInputStreams)
closeInputStreams
- closeInputStreamsprotected final ActionFactory getActionFactory()
Copyright © 2015. All rights reserved.