Class DatabaseLoginPrincipal

    • Field Summary

      • Fields inherited from class org.apache.catalina.realm.GenericPrincipal

        gssCredential, loginContext, name, roles, userPrincipal
    • Constructor Summary

      Constructors 
      Constructor Description
      DatabaseLoginPrincipal​(java.lang.String name, java.lang.String password, java.lang.String jdbcurl, java.lang.String jdbcdriver, java.lang.String roleSql)  
    • Method Summary

      Modifier and Type Method Description
      java.sql.Connection getConnection()
      Call the Tomcat's DataSource getConnection() method to retrieve a currently idle connection from the pool.
      java.lang.String getDBUser()  
      java.lang.String getDBVersion()  
      java.lang.String getDriver()  
      java.lang.String getDriverVersion()  
      java.util.Optional<java.lang.String> getLoginWarnings()  
      java.lang.String getSchema()  
      void logout()  
      abstract java.lang.String readDatabaseVersion​(java.sql.Connection c)  
      abstract java.lang.String readExactUserName​(java.sql.Connection c)  
      protected void setAdditionalJDBCPoolProperties​(org.apache.tomcat.jdbc.pool.PoolProperties p)
      A hook to set additional values in p, which is then passed to datasource.setPoolProperties(p); Only a last reserve, should be the empty implementation most of the time.
      abstract java.util.Optional<java.lang.String> validateLogin​(java.sql.Connection c)
      This method should validate the connected user and return a string with information useful to the end user.
      Examples of tests and information to be returned may include: Password will expire in one week Password must be changed immediately
      • Methods inherited from class org.apache.catalina.realm.GenericPrincipal

        getGssCredential, getName, getRoles, getUserPrincipal, hasRole, setGssCredential, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.security.Principal

        equals, hashCode, implies
    • Constructor Detail

      • DatabaseLoginPrincipal

        public DatabaseLoginPrincipal​(java.lang.String name,
                                      java.lang.String password,
                                      java.lang.String jdbcurl,
                                      java.lang.String jdbcdriver,
                                      java.lang.String roleSql)
                               throws java.sql.SQLException
        Parameters:
        name - database user name
        password - database password
        jdbcurl - database JDBC connection URL
        jdbcdriver - class name of the JDBC driver to use
        roleSql - a select with a single string column containing all database roles assigned to that user
        Throws:
        java.sql.SQLException - in case the login sequence cannot be performed completely
    • Method Detail

      • getDBVersion

        public java.lang.String getDBVersion()
        Specified by:
        getDBVersion in interface IDatabaseLoginPrincipal
        Returns:
        the version string of the connected database as retrieved at login
      • getDBUser

        public java.lang.String getDBUser()
        Specified by:
        getDBUser in interface IDatabaseLoginPrincipal
        Returns:
        the exact user, e.g. the login might have been user1 but the actual database user name is "USER1"
      • getLoginWarnings

        public java.util.Optional<java.lang.String> getLoginWarnings()
        Specified by:
        getLoginWarnings in interface IDatabaseLoginPrincipal
        Returns:
        a text to be rendered as information for the end user like password is about to expire, must change password
      • setAdditionalJDBCPoolProperties

        protected void setAdditionalJDBCPoolProperties​(org.apache.tomcat.jdbc.pool.PoolProperties p)
        A hook to set additional values in p, which is then passed to datasource.setPoolProperties(p); Only a last reserve, should be the empty implementation most of the time.
        Parameters:
        p - Tomcat prepopulated PoolProperties object the overwrite some
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Description copied from interface: IDatabaseLoginPrincipal
        Call the Tomcat's DataSource getConnection() method to retrieve a currently idle connection from the pool.
        Specified by:
        getConnection in interface IDatabaseLoginPrincipal
        Returns:
        a JDBC connection from the pool for temporary use
        Throws:
        java.sql.SQLException - in case the connection cannot be established
      • validateLogin

        public abstract java.util.Optional<java.lang.String> validateLogin​(java.sql.Connection c)
                                                                    throws LoginSQLException
        This method should validate the connected user and return a string with information useful to the end user.
        Examples of tests and information to be returned may include:
        • Password will expire in one week
        • Password must be changed immediately
        Parameters:
        c - a JDBC connection to retrieve the data
        Returns:
        a text with maybe a HTML link or null
        Throws:
        LoginSQLException - in case of SQL errors
      • readDatabaseVersion

        public abstract java.lang.String readDatabaseVersion​(java.sql.Connection c)
                                                      throws LoginSQLException
        Parameters:
        c - a JDBC connection to retrieve the data
        Returns:
        a string indicating the connected database version
        Throws:
        LoginSQLException - in case of SQL errors
      • readExactUserName

        public abstract java.lang.String readExactUserName​(java.sql.Connection c)
                                                    throws LoginSQLException
        Parameters:
        c - a JDBC connection to retrieve the data
        Returns:
        the exact username as known by the database, e.g. the login was 'user1' but the actual user name is 'USER1'
        Throws:
        LoginSQLException - in case of SQL errors
      • logout

        public void logout()
                    throws java.lang.Exception
        Specified by:
        logout in interface IDatabaseLoginPrincipal
        Specified by:
        logout in interface org.apache.catalina.TomcatPrincipal
        Overrides:
        logout in class org.apache.catalina.realm.GenericPrincipal
        Throws:
        java.lang.Exception