Class JDBCLoginService

  • All Implemented Interfaces:
    LoginService, org.eclipse.jetty.util.component.LifeCycle

    public class JDBCLoginService
    extends AbstractLoginService
    HashMapped User Realm with JDBC as data source. The AbstractLoginService.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 superclass AbstractLoginService.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

    • 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 class org.eclipse.jetty.util.component.AbstractLifeCycle
        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()
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.AbstractLifeCycle
        Throws:
        java.lang.Exception
        See Also:
        AbstractLifeCycle.doStop()