Framework Professional Edition Package


com.prosyst.util.security
Class SecurityUtil

java.lang.Object
  extended by com.prosyst.util.security.SecurityUtil
All Implemented Interfaces:
PrivilegedRunner.PrivilegedDispatcher

public final class SecurityUtil
extends java.lang.Object
implements PrivilegedRunner.PrivilegedDispatcher

Utility class to execute common privileged code.

Since:
3.1.0
Author:
Valentin Valchev

Constructor Summary
SecurityUtil()
          Constructs a new SecureAction object.
 
Method Summary
 java.lang.Thread createThread(java.lang.Runnable target, java.lang.String name)
          Creates a new Thread from a Runnable.
 boolean delete(java.io.File file)
          Deletes the specified file.
 java.lang.Object dispatchPrivileged(int type, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
           
 java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher, int type, java.lang.Object arg1)
          Performs a privileged action using the current security context.
 java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher, int type, java.lang.Object arg1, java.lang.Object arg2)
          Performs a privileged action using the current security context.
 java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher, int type, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Performs a privileged action using the current security context.
 java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher, int type, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
          Performs a privileged action using the current security context.
 boolean exists(java.io.File file)
          Returns true if a file exists, otherwise false is returned.
 java.lang.Class forName(java.lang.String name)
          Returns a Class.
 boolean getBooleanProperty(java.lang.String property)
          Returns a boolean system property.
 java.io.FileInputStream getFileInputStream(java.io.File file)
          Creates a FileInputStream from a File.
 java.io.FileOutputStream getFileOutputStream(java.io.File file, boolean append)
          Creates a FileInputStream from a File.
 java.util.Dictionary getHeaders(Bundle bundle)
          Gets the bundle headers.
 java.lang.String getLocation(Bundle bundle)
          Gets the location of the bundle.
 java.lang.String getProperty(java.lang.String property)
          Returns a system property.
 java.lang.String getProperty(java.lang.String property, java.lang.String def)
          Returns a system property.
 java.io.RandomAccessFile getRandomAccessFile(java.io.File file, java.lang.String mode)
          Creates a random access file
 java.lang.Object getService(ServiceReference reference, BundleContext context)
          Gets a service object.
 ServiceReference[] getServiceReferences(java.lang.String clazz, java.lang.String filter, BundleContext context)
          Gets a reference for the specified service(s).
 boolean isDirectory(java.io.File file)
          Returns true if a file is a directory, otherwise false is returned.
 long lastModified(java.io.File file)
          Returns a file's last modified stamp.
 long length(java.io.File file)
          Returns the length of a file.
 java.lang.String[] list(java.io.File file)
          Returns a file's list.
 ServiceRegistration registerService(java.lang.String[] classes, java.lang.Object service, java.util.Dictionary properties, BundleContext context)
          Registers a instance that implements many services.
 ServiceRegistration registerService(java.lang.String clazz, java.lang.Object service, java.util.Dictionary properties, BundleContext context)
          Registers a service.
 boolean renameTo(java.io.File source, java.io.File target)
          Renames the source file to the target name.
 java.lang.String setProperty(java.lang.String key, java.lang.String value)
          Sets a system property.
 void start(Bundle bundle)
          Starts the bundle.
 void stop(Bundle bundle)
          Stops the bundle.
 void uninstall(Bundle bundle)
          Un-installs the bundle.
 void update(Bundle bundle)
          Updates the bundle.
 void update(Bundle bundle, java.io.InputStream is)
          Updates the bundle from stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecurityUtil

public SecurityUtil()
Constructs a new SecureAction object. The constructed SecureAction object uses the caller's AccessControlContext to perform security checks

Method Detail

createThread

public java.lang.Thread createThread(java.lang.Runnable target,
                                     java.lang.String name)
Creates a new Thread from a Runnable. Same as calling new Thread(target,name).

Parameters:
target - the Runnable to create the Thread from.
name - The name of the Thread.
Returns:
The new Thread

forName

public java.lang.Class forName(java.lang.String name)
                        throws java.lang.ClassNotFoundException
Returns a Class. Same as calling Class.forName(name)

Parameters:
name - the name of the class.
Returns:
a Class
Throws:
java.lang.ClassNotFoundException

getProperty

public java.lang.String getProperty(java.lang.String property)
Returns a system property. Same as calling System.getProperty(String).

Parameters:
property - the property key.
Returns:
the value of the property or null if it does not exist.

getProperty

public java.lang.String getProperty(java.lang.String property,
                                    java.lang.String def)
Returns a system property. Same as calling System.getProperty(String,String).

Parameters:
property - the property key.
def - the default value if the property key does not exist.
Returns:
the value of the property or the default value if the property does not exist.

getBooleanProperty

public boolean getBooleanProperty(java.lang.String property)
Returns a boolean system property. Same as calling Boolean.getBoolean(String).

Parameters:
property - the property key.
Returns:
the value of the property or false, if not set

setProperty

public java.lang.String setProperty(java.lang.String key,
                                    java.lang.String value)
Sets a system property. Same as System.setProperty()

Parameters:
key - the name of the property
value - the value of the system property
Returns:
the old value of the property, or null

getFileInputStream

public java.io.FileInputStream getFileInputStream(java.io.File file)
                                           throws java.io.FileNotFoundException
Creates a FileInputStream from a File. Same as calling new FileInputStream(File).

Parameters:
file - the File to create a FileInputStream from.
Returns:
The FileInputStream.
Throws:
java.io.FileNotFoundException - if the File does not exist.

getRandomAccessFile

public java.io.RandomAccessFile getRandomAccessFile(java.io.File file,
                                                    java.lang.String mode)
                                             throws java.io.FileNotFoundException
Creates a random access file

Parameters:
file - the file object
mode - the open mode
Returns:
the random seekable file object
Throws:
java.io.FileNotFoundException - if the File does not exist

getFileOutputStream

public java.io.FileOutputStream getFileOutputStream(java.io.File file,
                                                    boolean append)
                                             throws java.io.FileNotFoundException
Creates a FileInputStream from a File. Same as calling new FileOutputStream(File,boolean).

Parameters:
file - the File to create a FileOutputStream from.
append - indicates if the OutputStream should append content.
Returns:
The FileOutputStream.
Throws:
java.io.FileNotFoundException - if the File does not exist.

exists

public boolean exists(java.io.File file)
Returns true if a file exists, otherwise false is returned. Same as calling file.exists().

Parameters:
file - a file object
Returns:
true if a file exists, otherwise false

isDirectory

public boolean isDirectory(java.io.File file)
Returns true if a file is a directory, otherwise false is returned. Same as calling file.isDirectory().

Parameters:
file - a file object
Returns:
true if a file is a directory, otherwise false

length

public long length(java.io.File file)
Returns the length of a file. Same as calling file.length().

Parameters:
file - a file object
Returns:
the length of a file or -1 if file doesn't exists

lastModified

public long lastModified(java.io.File file)
Returns a file's last modified stamp. Same as calling file.lastModified().

Parameters:
file - a file object
Returns:
a file's last modified stamp or -1 if file doesn't exists

list

public java.lang.String[] list(java.io.File file)
Returns a file's list. Same as calling file.list().

Parameters:
file - a file object
Returns:
a file's list.

delete

public boolean delete(java.io.File file)
Deletes the specified file. Same as File.delete()

Parameters:
file - the file object
Returns:
if delete succeeded

renameTo

public boolean renameTo(java.io.File source,
                        java.io.File target)
Renames the source file to the target name. Same as File.renameTo(File)

Parameters:
source - the file object, that will be renamed
target - the target file name
Returns:
if rename succeeded

getService

public java.lang.Object getService(ServiceReference reference,
                                   BundleContext context)
Gets a service object. Same as calling context.getService(reference)

Parameters:
reference - the ServiceReference
context - the BundleContext
Returns:
a service object

getServiceReferences

public ServiceReference[] getServiceReferences(java.lang.String clazz,
                                               java.lang.String filter,
                                               BundleContext context)
                                        throws InvalidSyntaxException
Gets a reference for the specified service(s). Same as calling context.getServiceReferences(class, filter)

Parameters:
clazz - the name of the requested service class
filter - an LDAP filter
context - the BundleContext
Returns:
a list of reference or null
Throws:
InvalidSyntaxException - if filter is not correct

registerService

public ServiceRegistration registerService(java.lang.String clazz,
                                           java.lang.Object service,
                                           java.util.Dictionary properties,
                                           BundleContext context)
Registers a service. Same as BundleContext.register(clazz, service, properties);

Parameters:
clazz - the class name of the service
service - the service instance
properties - the properties.
context - the bundle context
Returns:
a service registration

registerService

public ServiceRegistration registerService(java.lang.String[] classes,
                                           java.lang.Object service,
                                           java.util.Dictionary properties,
                                           BundleContext context)
Registers a instance that implements many services. Same as BundleContext.register(clases, service, properties);

Parameters:
classes - the class names of the service
service - the service instance
properties - the properties.
context - the bundle context
Returns:
a service registration

getLocation

public java.lang.String getLocation(Bundle bundle)
Gets the location of the bundle. Same as Bundle.getLocation().

Parameters:
bundle - the bundle
Returns:
the bundle location

getHeaders

public java.util.Dictionary getHeaders(Bundle bundle)
Gets the bundle headers. Same as Bundle.getHeaders().

Parameters:
bundle - the bundle
Returns:
the bundle location

start

public void start(Bundle bundle)
           throws BundleException
Starts the bundle. Same as Bundle.start()

Parameters:
bundle - the bundle
Throws:
BundleException

stop

public void stop(Bundle bundle)
          throws BundleException
Stops the bundle. Same as Bundle.stop()

Parameters:
bundle - the bundle
Throws:
BundleException

uninstall

public void uninstall(Bundle bundle)
               throws BundleException
Un-installs the bundle. Same as Bundle.uninstall()

Parameters:
bundle - the bundle
Throws:
BundleException

update

public void update(Bundle bundle)
            throws BundleException
Updates the bundle. Same as Bundle.update()

Parameters:
bundle - the bundle
Throws:
BundleException

update

public void update(Bundle bundle,
                   java.io.InputStream is)
            throws BundleException
Updates the bundle from stream. Same as Bundle.update(stream)

Parameters:
bundle - the bundle
is - the stream
Throws:
BundleException

doPrivileged

public java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher,
                                     int type,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2,
                                     java.lang.Object arg3,
                                     java.lang.Object arg4)
                              throws java.lang.Exception
Performs a privileged action using the current security context. The method calls the dispatcher inside the privileged call passing it the same parameters that were passed to this method.

Parameters:
dispatcher - the dispatcher which should be called
type - the type of the action - used in the dispatcher
arg1 - a parameter received by the dispatcher
arg2 - a parameter received by the dispatcher
arg3 - a parameter received by the dispatcher
arg4 - a parameter received by the dispatcher
Returns:
the object returned from the execution
Throws:
java.lang.Exception - if the dispatcher fails
See Also:
PrivilegedRunner.doPrivileged(Object, com.prosyst.util.security.PrivilegedRunner.PrivilegedDispatcher, int, Object, Object, Object, Object)

doPrivileged

public java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher,
                                     int type,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2,
                                     java.lang.Object arg3)
                              throws java.lang.Exception
Performs a privileged action using the current security context. The method calls the dispatcher inside the privileged call passing it the same parameters that were passed to this method.

Parameters:
dispatcher - the dispatcher which should be called
type - the type of the action - used in the dispatcher
arg1 - a parameter received by the dispatcher
arg2 - a parameter received by the dispatcher
arg3 - a parameter received by the dispatcher
Returns:
the object returned from the execution
Throws:
java.lang.Exception - if the dispatcher fails
See Also:
PrivilegedRunner.doPrivileged(Object, com.prosyst.util.security.PrivilegedRunner.PrivilegedDispatcher, int, Object, Object, Object, Object)

doPrivileged

public java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher,
                                     int type,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2)
                              throws java.lang.Exception
Performs a privileged action using the current security context. The method calls the dispatcher inside the privileged call passing it the same parameters that were passed to this method.

Parameters:
dispatcher - the dispatcher which should be called
type - the type of the action - used in the dispatcher
arg1 - a parameter received by the dispatcher
arg2 - a parameter received by the dispatcher
Returns:
the object returned from the execution
Throws:
java.lang.Exception - if the dispatcher fails
See Also:
PrivilegedRunner.doPrivileged(Object, com.prosyst.util.security.PrivilegedRunner.PrivilegedDispatcher, int, Object, Object, Object, Object)

doPrivileged

public java.lang.Object doPrivileged(PrivilegedRunner.PrivilegedDispatcher dispatcher,
                                     int type,
                                     java.lang.Object arg1)
                              throws java.lang.Exception
Performs a privileged action using the current security context. The method calls the dispatcher inside the privileged call passing it the same parameters that were passed to this method.

Parameters:
dispatcher - the dispatcher which should be called
type - the type of the action - used in the dispatcher
arg1 - a parameter received by the dispatcher
Returns:
the object returned from the execution
Throws:
java.lang.Exception - if the dispatcher fails
See Also:
PrivilegedRunner.doPrivileged(Object, com.prosyst.util.security.PrivilegedRunner.PrivilegedDispatcher, int, Object, Object, Object, Object)

dispatchPrivileged

public java.lang.Object dispatchPrivileged(int type,
                                           java.lang.Object arg1,
                                           java.lang.Object arg2,
                                           java.lang.Object arg3,
                                           java.lang.Object arg4)
                                    throws java.lang.Exception
Specified by:
dispatchPrivileged in interface PrivilegedRunner.PrivilegedDispatcher
Parameters:
type - the type of the action
arg1 - parameter 1 - depends on the action type
arg2 - parameter 2 - depends on the action type
arg3 - parameter 3 - depends on the action type
arg4 - parameter 4 - depends on the action type
Returns:
an object which should be returned from the PrivilegedAction.run() method
Throws:
java.lang.Exception - on error
See Also:
PrivilegedRunner.PrivilegedDispatcher.dispatchPrivileged(int, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved