Class JDBCLoginService


@JavaBean public class JDBCLoginService extends LoginService
A login service for connecting to SQL based databases via JDBC
  • Field Details

    • LOG

      private static final Logger LOG
    • conn

      private Connection conn
      The connection to the database
    • jndiContext

      private String jndiContext
      If used, defines the JNDI context from which to get a connection to the data base
    • properties

      private Properties properties
      When using the DriverManager to connect to the database, this specifies any additional properties to use when connecting.
  • Constructor Details

    • JDBCLoginService

      public JDBCLoginService(String driver, String url)
      Create a new JDBCLoginService and initializes it to connect to a database using the given params.
      Parameters:
      driver -
      url -
    • JDBCLoginService

      public JDBCLoginService(String driver, String url, Properties props)
      Create a new JDBCLoginService and initializes it to connect to a database using the given params.
      Parameters:
      driver -
      url -
      props -
    • JDBCLoginService

      public JDBCLoginService(String jndiContext)
      Create a new JDBCLoginService and initializes it to connect to a database using the given params.
      Parameters:
      jndiContext -
    • JDBCLoginService

      public JDBCLoginService()
      Default JavaBean constructor
  • Method Details

    • getUrl

      public String getUrl()
      Returns:
      the JDBC connection url
    • setUrl

      public void setUrl(String url)
      Parameters:
      url - set the JDBC connection url
    • getProperties

      public Properties getProperties()
      Returns:
      JDBC connection properties
    • setProperties

      public void setProperties(Properties properties)
      Parameters:
      properties - miscellaneous JDBC properties to use when connecting to the database via the JDBC driver
    • getConnection

      public Connection getConnection()
    • setConnection

      public void setConnection(Connection conn)
    • connectByJNDI

      private void connectByJNDI(String userName, char[] password) throws Exception
      Attempts to get a JDBC Connection from a JNDI javax.sql.DataSource, using that connection for interacting with the database.
      Throws:
      Exception
    • connectByDriverManager

      private void connectByDriverManager(String userName, char[] password) throws Exception
      Attempts to get a JDBC Connection from a DriverManager. If properties is not null, it tries to connect with those properties. If that fails, it then attempts to connect with a user name and password. If that fails, it attempts to connect without any credentials at all.

      If, on the other hand, properties is null, it first attempts to connect with a username and password. Failing that, it tries to connect without any credentials at all.

      Throws:
      Exception
    • authenticate

      public boolean authenticate(String name, char[] password, String server) throws Exception
      Description copied from class: LoginService
      This method is intended to be implemented by clients wishing to authenticate a user with a given password. Clients should implement the authentication in a manner that the authentication can be cancelled at any time.
      Specified by:
      authenticate in class LoginService
      Parameters:
      name - user name
      password - user password
      server - Must be either a valid JDBC URL for the type of JDBC driver you are using, or must be a valid JNDIContext from which to get the database connection
      Returns:
      true on authentication success
      Throws:
      Exception