Package org.eclipse.jetty.security
Class JDBCLoginService
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.security.AbstractLoginService
-
- org.eclipse.jetty.security.JDBCLoginService
-
- All Implemented Interfaces:
LoginService
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.LifeCycle
public class JDBCLoginService extends AbstractLoginService
HashMapped User Realm with JDBC as data source. TheAbstractLoginService.login(String, Object, ServletRequest)
method checks the inherited Map for the user. If the user is not found, it will fetch details from the database and populate the inherited Map. It then calls the superclassAbstractLoginService.login(String, Object, ServletRequest)
method to perform the actual authentication. Periodically (controlled by configuration parameter), internal hashes are cleared. Caching can be disabled by setting cache refresh interval to zero. Uses one database connection that is initialized at startup. Reconnect on failures.An example properties file for configuration is in
${jetty.home}/etc/jdbcRealm.properties
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
JDBCLoginService.JDBCUserPrincipal
JDBCKnownUser-
Nested classes/interfaces inherited from class org.eclipse.jetty.security.AbstractLoginService
AbstractLoginService.RolePrincipal, AbstractLoginService.UserPrincipal
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
-
Field Summary
Fields Modifier and Type Field Description protected java.sql.Connection
_con
protected java.lang.String
_config
protected java.lang.String
_jdbcDriver
protected java.lang.String
_password
protected java.lang.String
_roleSql
protected java.lang.String
_roleTableRoleField
protected java.lang.String
_url
protected java.lang.String
_userName
protected java.lang.String
_userSql
protected java.lang.String
_userTableKey
protected java.lang.String
_userTablePasswordField
-
Fields inherited from class org.eclipse.jetty.security.AbstractLoginService
_fullValidate, _identityService, _name
-
-
Constructor Summary
Constructors Constructor Description JDBCLoginService()
JDBCLoginService(java.lang.String name)
JDBCLoginService(java.lang.String name, java.lang.String config)
JDBCLoginService(java.lang.String name, IdentityService identityService, java.lang.String config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectDatabase()
(re)Connect to database with parameters setup by loadConfig()protected void
doStart()
protected void
doStop()
java.lang.String
getConfig()
java.lang.String[]
loadRoleInfo(AbstractLoginService.UserPrincipal user)
AbstractLoginService.UserPrincipal
loadUserInfo(java.lang.String username)
void
setConfig(java.lang.String config)
Load JDBC connection configuration from properties file.-
Methods inherited from class org.eclipse.jetty.security.AbstractLoginService
getIdentityService, getName, isFullValidate, login, logout, setFullValidate, setIdentityService, setName, toString, validate
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
_config
protected java.lang.String _config
-
_jdbcDriver
protected java.lang.String _jdbcDriver
-
_url
protected java.lang.String _url
-
_userName
protected java.lang.String _userName
-
_password
protected java.lang.String _password
-
_userTableKey
protected java.lang.String _userTableKey
-
_userTablePasswordField
protected java.lang.String _userTablePasswordField
-
_roleTableRoleField
protected java.lang.String _roleTableRoleField
-
_con
protected java.sql.Connection _con
-
_userSql
protected java.lang.String _userSql
-
_roleSql
protected java.lang.String _roleSql
-
-
Constructor Detail
-
JDBCLoginService
public JDBCLoginService() throws java.io.IOException
- Throws:
java.io.IOException
-
JDBCLoginService
public JDBCLoginService(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
JDBCLoginService
public JDBCLoginService(java.lang.String name, java.lang.String config) throws java.io.IOException
- Throws:
java.io.IOException
-
JDBCLoginService
public JDBCLoginService(java.lang.String name, IdentityService identityService, java.lang.String config) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
getConfig
public java.lang.String getConfig()
-
setConfig
public void setConfig(java.lang.String config)
Load JDBC connection configuration from properties file.- Parameters:
config
- Filename or url of user properties file.
-
connectDatabase
public void connectDatabase()
(re)Connect to database with parameters setup by loadConfig()
-
loadUserInfo
public AbstractLoginService.UserPrincipal loadUserInfo(java.lang.String username)
- Specified by:
loadUserInfo
in classAbstractLoginService
-
loadRoleInfo
public java.lang.String[] loadRoleInfo(AbstractLoginService.UserPrincipal user)
- Specified by:
loadRoleInfo
in classAbstractLoginService
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
- See Also:
AbstractLifeCycle.doStop()
-
-