Class DatabaseLoginPrincipal
- java.lang.Object
-
- org.apache.catalina.realm.GenericPrincipal
-
- io.rtdi.appcontainer.databaseloginrealm.DatabaseLoginPrincipal
-
- All Implemented Interfaces:
IDatabaseLoginPrincipal,java.io.Serializable,java.security.Principal,org.apache.catalina.TomcatPrincipal
public abstract class DatabaseLoginPrincipal extends org.apache.catalina.realm.GenericPrincipal implements IDatabaseLoginPrincipal
- See Also:
- Serialized Form
-
-
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.ConnectiongetConnection()Call the Tomcat's DataSource getConnection() method to retrieve a currently idle connection from the pool.java.lang.StringgetDBUser()java.lang.StringgetDBVersion()java.lang.StringgetDriver()java.lang.StringgetDriverVersion()java.util.Optional<java.lang.String>getLoginWarnings()java.lang.StringgetSchema()voidlogout()abstract java.lang.StringreadDatabaseVersion(java.sql.Connection c)abstract java.lang.StringreadExactUserName(java.sql.Connection c)protected voidsetAdditionalJDBCPoolProperties(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 io.rtdi.appcontainer.databaseloginrealm.IDatabaseLoginPrincipal
getRoles
-
-
-
-
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 namepassword- database passwordjdbcurl- database JDBC connection URLjdbcdriver- class name of the JDBC driver to useroleSql- 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
-
getDriver
public java.lang.String getDriver()
- Specified by:
getDriverin interfaceIDatabaseLoginPrincipal- Returns:
- the FQN class name used
-
getDBVersion
public java.lang.String getDBVersion()
- Specified by:
getDBVersionin interfaceIDatabaseLoginPrincipal- Returns:
- the version string of the connected database as retrieved at login
-
getDBUser
public java.lang.String getDBUser()
- Specified by:
getDBUserin interfaceIDatabaseLoginPrincipal- 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:
getLoginWarningsin interfaceIDatabaseLoginPrincipal- 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.SQLExceptionDescription copied from interface:IDatabaseLoginPrincipalCall the Tomcat's DataSource getConnection() method to retrieve a currently idle connection from the pool.- Specified by:
getConnectionin interfaceIDatabaseLoginPrincipal- Returns:
- a JDBC connection from the pool for temporary use
- Throws:
java.sql.SQLException- in case the connection cannot be established
-
getDriverVersion
public java.lang.String getDriverVersion()
- Specified by:
getDriverVersionin interfaceIDatabaseLoginPrincipal- Returns:
- the JDBC driver version being used
-
getSchema
public java.lang.String getSchema()
- Specified by:
getSchemain interfaceIDatabaseLoginPrincipal- Returns:
- the user's default schema
-
validateLogin
public abstract java.util.Optional<java.lang.String> validateLogin(java.sql.Connection c) throws LoginSQLExceptionThis 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:
logoutin interfaceIDatabaseLoginPrincipal- Specified by:
logoutin interfaceorg.apache.catalina.TomcatPrincipal- Overrides:
logoutin classorg.apache.catalina.realm.GenericPrincipal- Throws:
java.lang.Exception
-
-