Package org.jdesktop.swingx.auth
Class JDBCLoginService
java.lang.Object
org.jdesktop.beans.AbstractBean
org.jdesktop.swingx.auth.LoginService
org.jdesktop.swingx.auth.JDBCLoginService
A login service for connecting to SQL based databases via JDBC
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Connection
The connection to the databaseprivate String
If used, defines the JNDI context from which to get a connection to the data baseprivate static final Logger
private Properties
When using the DriverManager to connect to the database, this specifies any additional properties to use when connecting. -
Constructor Summary
ConstructorsConstructorDescriptionDefault JavaBean constructorJDBCLoginService
(String jndiContext) Create a new JDBCLoginService and initializes it to connect to a database using the given params.JDBCLoginService
(String driver, String url) Create a new JDBCLoginService and initializes it to connect to a database using the given params.JDBCLoginService
(String driver, String url, Properties props) Create a new JDBCLoginService and initializes it to connect to a database using the given params. -
Method Summary
Modifier and TypeMethodDescriptionboolean
authenticate
(String name, char[] password, String server) This method is intended to be implemented by clients wishing to authenticate a user with a given password.private void
connectByDriverManager
(String userName, char[] password) Attempts to get a JDBC Connection from a DriverManager.private void
connectByJNDI
(String userName, char[] password) Attempts to get a JDBC Connection from a JNDI javax.sql.DataSource, using that connection for interacting with the database.getUrl()
void
setConnection
(Connection conn) void
setProperties
(Properties properties) void
Methods inherited from class org.jdesktop.swingx.auth.LoginService
addLoginListener, cancelAuthentication, fireLoginCanceled, fireLoginFailed, fireLoginStarted, fireLoginSucceeded, getServer, getSynchronous, getUserRoles, removeLoginListener, setServer, setSynchronous, startAuthentication
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
LOG
-
conn
The connection to the database -
jndiContext
If used, defines the JNDI context from which to get a connection to the data base -
properties
When using the DriverManager to connect to the database, this specifies any additional properties to use when connecting.
-
-
Constructor Details
-
JDBCLoginService
Create a new JDBCLoginService and initializes it to connect to a database using the given params.- Parameters:
driver
-url
-
-
JDBCLoginService
Create a new JDBCLoginService and initializes it to connect to a database using the given params.- Parameters:
driver
-url
-props
-
-
JDBCLoginService
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
- Returns:
- the JDBC connection url
-
setUrl
- Parameters:
url
- set the JDBC connection url
-
getProperties
- Returns:
- JDBC connection properties
-
setProperties
- Parameters:
properties
- miscellaneous JDBC properties to use when connecting to the database via the JDBC driver
-
getConnection
-
setConnection
-
connectByJNDI
Attempts to get a JDBC Connection from a JNDI javax.sql.DataSource, using that connection for interacting with the database.- Throws:
Exception
-
connectByDriverManager
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
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 classLoginService
- Parameters:
name
- user namepassword
- user passwordserver
- 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
-