Package org.jdesktop.swingx.auth
Class JDBCLoginService
- java.lang.Object
-
- org.jdesktop.beans.AbstractBean
-
- org.jdesktop.swingx.auth.LoginService
-
- org.jdesktop.swingx.auth.JDBCLoginService
-
@JavaBean public class JDBCLoginService extends LoginService
A login service for connecting to SQL based databases via JDBC
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.Connection
conn
The connection to the databaseprivate java.lang.String
jndiContext
If used, defines the JNDI context from which to get a connection to the data baseprivate static java.util.logging.Logger
LOG
private java.util.Properties
properties
When using the DriverManager to connect to the database, this specifies any additional properties to use when connecting.
-
Constructor Summary
Constructors Constructor Description JDBCLoginService()
Default JavaBean constructorJDBCLoginService(java.lang.String jndiContext)
Create a new JDBCLoginService and initializes it to connect to a database using the given params.JDBCLoginService(java.lang.String driver, java.lang.String url)
Create a new JDBCLoginService and initializes it to connect to a database using the given params.JDBCLoginService(java.lang.String driver, java.lang.String url, java.util.Properties props)
Create a new JDBCLoginService and initializes it to connect to a database using the given params.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
authenticate(java.lang.String name, char[] password, java.lang.String server)
This method is intended to be implemented by clients wishing to authenticate a user with a given password.private void
connectByDriverManager(java.lang.String userName, char[] password)
Attempts to get a JDBC Connection from a DriverManager.private void
connectByJNDI(java.lang.String userName, char[] password)
Attempts to get a JDBC Connection from a JNDI javax.sql.DataSource, using that connection for interacting with the database.java.sql.Connection
getConnection()
java.util.Properties
getProperties()
java.lang.String
getUrl()
void
setConnection(java.sql.Connection conn)
void
setProperties(java.util.Properties properties)
void
setUrl(java.lang.String url)
-
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 Detail
-
LOG
private static final java.util.logging.Logger LOG
-
conn
private java.sql.Connection conn
The connection to the database
-
jndiContext
private java.lang.String jndiContext
If used, defines the JNDI context from which to get a connection to the data base
-
properties
private java.util.Properties properties
When using the DriverManager to connect to the database, this specifies any additional properties to use when connecting.
-
-
Constructor Detail
-
JDBCLoginService
public JDBCLoginService(java.lang.String driver, java.lang.String url)
Create a new JDBCLoginService and initializes it to connect to a database using the given params.- Parameters:
driver
-url
-
-
JDBCLoginService
public JDBCLoginService(java.lang.String driver, java.lang.String url, java.util.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(java.lang.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 Detail
-
getUrl
public java.lang.String getUrl()
- Returns:
- the JDBC connection url
-
setUrl
public void setUrl(java.lang.String url)
- Parameters:
url
- set the JDBC connection url
-
getProperties
public java.util.Properties getProperties()
- Returns:
- JDBC connection properties
-
setProperties
public void setProperties(java.util.Properties properties)
- Parameters:
properties
- miscellaneous JDBC properties to use when connecting to the database via the JDBC driver
-
getConnection
public java.sql.Connection getConnection()
-
setConnection
public void setConnection(java.sql.Connection conn)
-
connectByJNDI
private void connectByJNDI(java.lang.String userName, char[] password) throws java.lang.Exception
Attempts to get a JDBC Connection from a JNDI javax.sql.DataSource, using that connection for interacting with the database.- Throws:
java.lang.Exception
-
connectByDriverManager
private void connectByDriverManager(java.lang.String userName, char[] password) throws java.lang.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:
java.lang.Exception
-
authenticate
public boolean authenticate(java.lang.String name, char[] password, java.lang.String server) throws java.lang.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 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:
java.lang.Exception
-
-