com.sibvisions.rad.server.security
Class AbstractDBSecurityManager

java.lang.Object
  extended by com.sibvisions.rad.server.security.AbstractSecurityManager
      extended by com.sibvisions.rad.server.security.AbstractDBSecurityManager
All Implemented Interfaces:
ISecurityManager, IPasswordValidator
Direct Known Subclasses:
DBSecurityManager

public abstract class AbstractDBSecurityManager
extends AbstractSecurityManager

The AbstractDBSecurityManager is the base class for all security managers that use a database for authentication.


Constructor Summary
AbstractDBSecurityManager()
           
 
Method Summary
protected  void close(java.sql.Statement... pStatement)
          Closes and unregisters the given statements.
protected  void closeConnection()
          Close all statements and the connection.
protected  void closeStatements()
          Close all registered statements.
protected  IAccessController createAccessController(ISession pSession)
          Creates an access controller for a ISession.
protected  void finalize()
          
protected abstract  java.lang.String getAliveQuery()
          Gets the query which should be use for connection check.
 java.sql.Connection getConnection()
          Gets the current connection to the database.
 java.sql.Connection getConnection(ISession pSession)
          Gets the connection to the database.
static DBCredentials getCredentials(IConfiguration pConfig)
          Gets the configured database credentials from a given configuration.
protected  DBCredentials getCredentials(ISession pSession)
          Gets the configured database credentials for the given session.
protected abstract  void initStatements(java.sql.Connection pConnection)
          Initializes all statements after opening a database connection.
protected  boolean isConnectionAlive()
          Checks whether the connection is still alive, means whether the connection can be used.
protected  java.sql.Connection openConnection(ISession pSession)
          Opens a database connection to the database of an application.
protected  java.sql.CallableStatement prepareCall(java.sql.Connection pConnection, java.lang.String pSql)
          Creates a new instance of CallableStatement.
protected  java.sql.PreparedStatement prepareStatement(java.sql.Connection pConnection, java.lang.String pSql)
          Creates a new instance of PreparedStatement.
protected  void register(java.sql.Statement pStatement)
          Registers a statment as closable statement.
 void release()
          Releases all used resources.
protected  boolean unregister(java.sql.Statement pStatement)
          Unregisters a statement.
protected abstract  void updateConfiguration(IConfiguration pConfig)
          Updates relevant information after configuration was changed.
 
Methods inherited from class com.sibvisions.rad.server.security.AbstractSecurityManager
addHiddenPackage, checkPassword, comparePassword, createSecurityManager, createSecurityManager, createSecurityManager, debug, error, getEncryptedPassword, getPasswordValidator, info, isAllowEncryptedUserPassword, isHiddenPackage, isPasswordEncrypted, isPasswordEncryptionEnabled, prepareException, prepareException, removeHiddenPackage, setAllowEncryptedUserPassword, validatePassword
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sibvisions.rad.server.security.ISecurityManager
changePassword, getAccessController, logout, validateAuthentication
 

Constructor Detail

AbstractDBSecurityManager

public AbstractDBSecurityManager()
Method Detail

updateConfiguration

protected abstract void updateConfiguration(IConfiguration pConfig)
                                     throws java.lang.Exception
Updates relevant information after configuration was changed.

Parameters:
pConfig - the session configuration
Throws:
java.lang.Exception - if an exception occurs during statement creation

initStatements

protected abstract void initStatements(java.sql.Connection pConnection)
                                throws java.lang.Exception
Initializes all statements after opening a database connection.

Parameters:
pConnection - the connection to use
Throws:
java.lang.Exception - if an exception occurs during statement creation

getAliveQuery

protected abstract java.lang.String getAliveQuery()
Gets the query which should be use for connection check. A simple query like select 1 from dual is enough.

Returns:
the alive check query

release

public void release()
Releases all used resources.


finalize

protected void finalize()
                 throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

openConnection

protected java.sql.Connection openConnection(ISession pSession)
                                      throws java.lang.Exception
Opens a database connection to the database of an application.

Parameters:
pSession - the session for which the connection should be opened
Returns:
a new or reused connection to the database
Throws:
java.lang.Exception - if the application zone is invalid or the connection can not be opened
java.lang.IllegalArgumentException - if the database configuration is invalid (parameters are missing, ...)

closeConnection

protected void closeConnection()
                        throws java.lang.Exception
Close all statements and the connection.

Throws:
java.lang.Exception - if one statement can not be closed

closeStatements

protected void closeStatements()
Close all registered statements.


close

protected void close(java.sql.Statement... pStatement)
Closes and unregisters the given statements.

Parameters:
pStatement - the statements to close and unregister

getCredentials

protected DBCredentials getCredentials(ISession pSession)
Gets the configured database credentials for the given session.

Parameters:
pSession - the session
Returns:
the configured credentials
See Also:
getCredentials(IConfiguration)

getCredentials

public static DBCredentials getCredentials(IConfiguration pConfig)
Gets the configured database credentials from a given configuration. This method handles credentials, set in the security manager and credentials configured as datasource.

Parameters:
pConfig - the configuration
Returns:
the configured credentials

getConnection

public java.sql.Connection getConnection()
                                  throws java.lang.Exception
Gets the current connection to the database. The connection is validated to ensure that it is usable.

Returns:
the connection for the security manager or null if the security manager did not open a connection
Throws:
java.lang.Exception - if db access fails

getConnection

public java.sql.Connection getConnection(ISession pSession)
                                  throws java.lang.Exception
Gets the connection to the database. The connection is validated to ensure that it is usable.

Parameters:
pSession - the session that wants access to the database
Returns:
the connection
Throws:
java.lang.Exception - if db access fails

createAccessController

protected IAccessController createAccessController(ISession pSession)
Creates an access controller for a ISession.

Parameters:
pSession - the session which requests the access controller
Returns:
the access controller

isConnectionAlive

protected boolean isConnectionAlive()
Checks whether the connection is still alive, means whether the connection can be used.

Returns:
true if the connection is alive/valid
See Also:
getAliveQuery()

register

protected void register(java.sql.Statement pStatement)
Registers a statment as closable statement. All closable statements will be closed if connection will be closed.

Parameters:
pStatement - the statement

unregister

protected boolean unregister(java.sql.Statement pStatement)
Unregisters a statement.

Parameters:
pStatement - the statement
Returns:
true if unregistration was successful, false if statement was not registered as closable
See Also:
register(Statement)

prepareStatement

protected java.sql.PreparedStatement prepareStatement(java.sql.Connection pConnection,
                                                      java.lang.String pSql)
                                               throws java.sql.SQLException
Creates a new instance of PreparedStatement. The statement will be registered for automatic close.

Parameters:
pConnection - the database connection
pSql - the SQL statement, e.g. a query
Returns:
the new statement
Throws:
java.sql.SQLException - if statement creation fails

prepareCall

protected java.sql.CallableStatement prepareCall(java.sql.Connection pConnection,
                                                 java.lang.String pSql)
                                          throws java.sql.SQLException
Creates a new instance of CallableStatement. The statement will be registered for automatic close.

Parameters:
pConnection - the database connection
pSql - the call statement
Returns:
the new statement
Throws:
java.sql.SQLException - if statement creation fails


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.