Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc.authentication

public abstract Class AuthenticationServiceBase

extends Object
implements AuthenticationService, ModuleControl, ModuleSupportable, PropertySetCallback
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.property.PropertySetCallback, org.apache.derby.iapi.services.monitor.ModuleSupportable, org.apache.derby.iapi.services.monitor.ModuleControl, org.apache.derby.iapi.jdbc.AuthenticationService
Known Direct Subclasses
org.apache.derby.impl.jdbc.authentication.BasicAuthenticationServiceImpl, org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationService, org.apache.derby.impl.jdbc.authentication.NativeAuthenticationServiceImpl, org.apache.derby.impl.jdbc.authentication.NoneAuthenticationServiceImpl, org.apache.derby.impl.jdbc.authentication.SpecificAuthenticationServiceImpl
Imports
org.apache.derby.authentication.UserAuthenticator, org.apache.derby.shared.common.reference.Property, .Limits, .Attribute, .SQLState, org.apache.derby.iapi.jdbc.AuthenticationService, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.Context, .ContextService, org.apache.derby.iapi.services.daemon.Serviceable, org.apache.derby.iapi.services.monitor.ModuleSupportable, .ModuleControl, .Monitor, org.apache.derby.iapi.store.access.AccessFactory, .TransactionController, org.apache.derby.iapi.services.property.PropertyFactory, .PropertySetCallback, .PropertyUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.util.StringUtil, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.DataDictionary, .PasswordHasher, .UserDescriptor, java.security.MessageDigest, .NoSuchAlgorithmException, .SecureRandom, java.io.Serializable, .UnsupportedEncodingException, java.util.Dictionary, .Properties

This is the authentication service base class.

There can be 1 Authentication Service for the whole Derby system and/or 1 authentication per database. In a near future, we intend to allow multiple authentication services per system and/or per database.

It should be extended by the specialized authentication services.

IMPORTANT NOTE:

User passwords are hashed using a message digest algorithm if they're stored in the database. They are not hashed if they were defined at the system level.

The passwords can be hashed using two different schemes:

In order to use the configurable hash authentication scheme, the users have to set the derby.authentication.builtin.algorithm property (on system level or database level) to the name of an algorithm that's available in one of the security providers registered on the system. If this property is not set, or if it's set to NULL or an empty string, the SHA-1 authentication scheme is used.

Which scheme to use is decided when a password is about to be stored in the database. One database may therefore contain passwords stored using different schemes. In order to determine which scheme to use when comparing a user's credentials with those stored in the database, the stored password is prefixed with an identifier that tells which scheme is being used. Passwords stored using the SHA-1 authentication scheme are prefixed with PasswordHasher#ID_PATTERN_SHA1_SCHEME. Passwords that are stored using the configurable hash authentication scheme are prefixed with PasswordHasher#ID_PATTERN_CONFIGURABLE_HASH_SCHEME and suffixed with the name of the message digest algorithm.

Field Summary

Modifier and TypeField and Description
protected UserAuthenticator
public static final String
AuthenticationTrace

Trace flag to trace authentication operations

protected static final int
SECMEC_USRSSBPWD

Userid with Strong password substitute DRDA security mechanism

private AccessFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Serviceable
apply(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.apply.

Apply a property change.

public boolean
authenticate(String
The name of the database
databaseName
,
Properties
Connection properties info.
userInfo
)

Implements org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

Authenticate a User inside JBMS.T his is an overload method.

public void
boot(boolean
True if the database should be created
create
,
Properties
Configuration properties
properties
)

Implements org.apache.derby.iapi.services.monitor.ModuleControl.boot.

Start this module.

private static Context
getContext(final String contextID)

Must be private so that user code can't call this entry point.

private static ContextService
getContextService()

Must be private so that user code can't call this entry point.

pack-priv Properties

Returns:

the database properties, or null if there is no access factory
getDatabaseProperties
()

Get all the database properties.

public String
private static DataDictionary

Returns:

the DataDictionary for the current connection
getDataDictionary
()

Find the data dictionary for the current connection.

public String

Returns:

a property string value.
getProperty
(String key)

Returns a property if it was set at the database or system level.

pack-priv static Object
getServiceModule(final Object serviceModule, final String factoryInterface)

Must be package protected so that user code can't call this entry point.

protected String
getServiceName()

Get the name of the database if we are performing authentication at the database level.

private static String
getServiceName(final Object serviceModule)

Must be private so that user code can't call this entry point.

public String
getSystemCredentialsDatabaseName()

Implements org.apache.derby.iapi.jdbc.AuthenticationService.getSystemCredentialsDatabaseName.

Get the name of the credentials database used to authenticate system-wide operations.

public String
protected TransactionController
getTransaction()

Get a transaction for performing authentication at the database level.

protected String

Returns:

hashed user password (digest) as a String object or null if the plaintext password is null
hashPasswordSHA1Scheme
(String
Plain text user password
plainTxtUserPassword
)

This method hashes a clear user password using a Single Hash algorithm such as SHA-1 (SHA equivalent) (it is a 160 bits digest)

The digest is returned as an object string.

pack-priv String

Returns:

a digest of the user name and password formatted as a string, or null if password is null
hashUsingDefaultAlgorithm
(String
the user whose password to hash
user
,
String
the plain text password
password
,
Dictionary<K, V>
database properties
props
)

Hash a password using the default message digest algorithm for this system before it's stored in the database.

public void
init(boolean
true if only per-database properties are to be looked at
dbOnly
,
Dictionary<K, V>
the complete set of per-database properties.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.init.

Initialize the properties for this callback.

public Serializable
map(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.map.

Map a proposed new value for a property to an official value.

protected Long
parsePasswordLifetime(String passwordLifetimeString)

Parse the value of the password lifetime property.

protected Double
parsePasswordThreshold(String expirationThresholdString)

Parse the value of the password expiration threshold property.

protected final boolean
protected void
public void
protected String

Returns:

a substituted password.
substitutePassword
(String userName, String password, Properties info, boolean databaseUser)

Strong Password Substitution (USRSSBPWD).

private static byte[]

Returns:

the byte[] (with hexadecimal format) form of the string (str)
toHexByte
(String
string
str
)

Convert a string into a byte array in hex format.

public boolean
validate(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Validate a property change.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authenticationSchemeback to summary
protected UserAuthenticator authenticationScheme
AuthenticationTraceback to summary
public static final String AuthenticationTrace

Trace flag to trace authentication operations

SECMEC_USRSSBPWDback to summary
protected static final int SECMEC_USRSSBPWD

Userid with Strong password substitute DRDA security mechanism

storeback to summary
private AccessFactory store

Constructor Detail

AuthenticationServiceBaseback to summary
public AuthenticationServiceBase()

Method Detail

applyback to summary
public Serviceable apply(String key, Serializable value, Dictionary<K, V> p)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.apply.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.apply.

Apply a property change. Will only be called after validate has been called and only if validate returned true. If this method is called then the new value is the value to be used, ie. the property is not set in the overriding JVM system set.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:Serviceable

post commit work for the property change.

See Also
PropertySetCallback#validate
authenticateback to summary
public boolean authenticate(String databaseName, Properties userInfo) throws SQLException

Implements org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

Authenticate a User inside JBMS.T his is an overload method. We're passed-in a Properties object containing user credentials information (as well as database name if user needs to be validated for a certain database access).

Parameters
databaseName:String

Doc from org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

The name of the database

userInfo:Properties

Doc from org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

Connection properties info.

Returns:boolean

Doc from org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

true if authentication succeeded

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.AuthenticationService.authenticate.

on error

See Also
org.apache.derby.iapi.jdbc.AuthenticationService#authenticate
bootback to summary
public void boot(boolean create, Properties properties) throws StandardException

Implements org.apache.derby.iapi.services.monitor.ModuleControl.boot.

Start this module. In this case, nothing needs to be done.

Parameters
create:boolean

Doc from org.apache.derby.iapi.services.monitor.ModuleControl.boot.

True if the database should be created

properties:Properties

Doc from org.apache.derby.iapi.services.monitor.ModuleControl.boot.

Configuration properties

Exceptions
StandardException:
upon failure to load/boot the expected authentication service.
See Also
org.apache.derby.iapi.services.monitor.ModuleControl#boot
getContextback to summary
private static Context getContext(final String contextID)

Must be private so that user code can't call this entry point.

getContextServiceback to summary
private static ContextService getContextService()

Must be private so that user code can't call this entry point.

getDatabasePropertiesback to summary
pack-priv Properties getDatabaseProperties() throws StandardException

Get all the database properties.

Returns:Properties

the database properties, or null if there is no access factory

getDatabasePropertyback to summary
public String getDatabaseProperty(String key)
getDataDictionaryback to summary
private static DataDictionary getDataDictionary()

Find the data dictionary for the current connection.

Returns:DataDictionary

the DataDictionary for the current connection

getPropertyback to summary
public String getProperty(String key)

Returns a property if it was set at the database or system level. Treated as SERVICE property by default.

Returns:String

a property string value.

getServiceModuleback to summary
pack-priv static Object getServiceModule(final Object serviceModule, final String factoryInterface)

Must be package protected so that user code can't call this entry point.

getServiceNameback to summary
protected String getServiceName()

Get the name of the database if we are performing authentication at the database level.

getServiceNameback to summary
private static String getServiceName(final Object serviceModule)

Must be private so that user code can't call this entry point.

getSystemCredentialsDatabaseNameback to summary
public String getSystemCredentialsDatabaseName()

Implements org.apache.derby.iapi.jdbc.AuthenticationService.getSystemCredentialsDatabaseName.

Doc from org.apache.derby.iapi.jdbc.AuthenticationService.getSystemCredentialsDatabaseName.

Get the name of the credentials database used to authenticate system-wide operations. This returns null for all implementations except NATIVE authentication.

Returns:String

the name of the system-wide credentials database

getSystemPropertyback to summary
public String getSystemProperty(String key)
getTransactionback to summary
protected TransactionController getTransaction() throws StandardException

Get a transaction for performing authentication at the database level.

hashPasswordSHA1Schemeback to summary
protected String hashPasswordSHA1Scheme(String plainTxtUserPassword)

This method hashes a clear user password using a Single Hash algorithm such as SHA-1 (SHA equivalent) (it is a 160 bits digest)

The digest is returned as an object string.

This method is only used by the SHA-1 authentication scheme.

Parameters
plainTxtUserPassword:String

Plain text user password

Returns:String

hashed user password (digest) as a String object or null if the plaintext password is null

hashUsingDefaultAlgorithmback to summary
pack-priv String hashUsingDefaultAlgorithm(String user, String password, Dictionary<K, V> props) throws StandardException

Hash a password using the default message digest algorithm for this system before it's stored in the database.

If the data dictionary supports the configurable hash authentication scheme, and the property derby.authentication.builtin.algorithm is a non-empty string, the password will be hashed using the algorithm specified by that property. Otherwise, we fall back to the new authentication scheme based on SHA-1. The algorithm used is encoded in the returned token so that the code that validates a user's credentials knows which algorithm to use.

Parameters
user:String

the user whose password to hash

password:String

the plain text password

props:Dictionary<K, V>

database properties

Returns:String

a digest of the user name and password formatted as a string, or null if password is null

Exceptions
StandardException:
if the specified algorithm is not supported
initback to summary
public void init(boolean dbOnly, Dictionary<K, V> p)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.init.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.init.

Initialize the properties for this callback. Called when addPropertySetNotification() is called with a non-null transaction controller. This allows code to set read its initial property values at boot time.

Code within an init() method should use the 3 argument PropertyUtil method getPropertyFromSet() to obtain a property's value.

Parameters
dbOnly:boolean

true if only per-database properties are to be looked at

p:Dictionary<K, V>

the complete set of per-database properties.

mapback to summary
public Serializable map(String key, Serializable value, Dictionary<K, V> p) throws StandardException

Implements org.apache.derby.iapi.services.property.PropertySetCallback.map.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.map.

Map a proposed new value for a property to an official value. Will only be called after apply() has been called.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:Serializable

new value for the change

Exceptions
StandardException:
Thrown on error.
See Also
PropertySetCallback#map
parsePasswordLifetimeback to summary
protected Long parsePasswordLifetime(String passwordLifetimeString)

Parse the value of the password lifetime property. Return null if it is bad.

parsePasswordThresholdback to summary
protected Double parsePasswordThreshold(String expirationThresholdString)

Parse the value of the password expiration threshold property. Return null if it is bad.

requireAuthenticationback to summary
protected final boolean requireAuthentication(Properties properties)
setAuthenticationServiceback to summary
protected void setAuthenticationService(UserAuthenticator aScheme)
stopback to summary
public void stop()

Implements org.apache.derby.iapi.services.monitor.ModuleControl.stop.

Doc from org.apache.derby.iapi.services.monitor.ModuleControl.stop.

Stop the module. The module may be found via a findModule() method until some time after this method returns. Therefore the factory must be prepared to reject requests to it once it has been stopped. In addition other modules may cache a reference to the module and make requests of it after it has been stopped, these requests should be rejected as well.

See Also
org.apache.derby.iapi.services.monitor.ModuleControl#stop
substitutePasswordback to summary
protected String substitutePassword(String userName, String password, Properties info, boolean databaseUser)

Strong Password Substitution (USRSSBPWD). This method generates a password substitute to authenticate a client which is using a DRDA security mechanism such as SECMEC_USRSSBPWD. Depending how the user is defined in Derby and if BUILTIN is used, the stored password can be in clear-text (system level) or encrypted (hashed - *not decryptable*)) (database level) - If the user has authenticated at the network level via SECMEC_USRSSBPWD, it means we're presented with a password substitute and we need to generate a substitute password coming from the store to compare with the one passed-in. The substitution algorithm used is the same as the one used in the SHA-1 authentication scheme (PasswordHasher#ID_PATTERN_SHA1_SCHEME), so in the case of database passwords stored using that scheme, we can simply compare the received hash with the stored hash. If the configurable hash authentication scheme PasswordHasher#ID_PATTERN_CONFIGURABLE_HASH_SCHEME is used, we have no way to find out if the received hash matches the stored password, since we cannot decrypt the hashed passwords and re-apply another hash algorithm. Therefore, strong password substitution only works if the database-level passwords are stored with the SHA-1 scheme.

Note

A lot of this logic could be shared with the DRDA decryption and client encryption managers - This will be done _once_ code sharing along with its rules are defined between the Derby engine, client and network code (PENDING). Substitution algorithm works as follow: PW_TOKEN = SHA-1(PW, ID) The password (PW) and user name (ID) can be of any length greater than or equal to 1 byte. The client generates a 20-byte password substitute (PW_SUB) as follows: PW_SUB = SHA-1(PW_TOKEN, RDr, RDs, ID, PWSEQs) w/ (RDs) as the random client seed and (RDr) as the server one. See PWDSSB - Strong Password Substitution Security Mechanism (DRDA Vol.3 - P.650)

Returns:String

a substituted password.

toHexByteback to summary
private static byte[] toHexByte(String str)

Convert a string into a byte array in hex format.

For each character (b) two bytes are generated, the first byte represents the high nibble (4 bits) in hexadecimal (b & 0xf0), the second byte represents the low nibble (b & 0x0f).

The character at str.charAt(0) is represented by the first two bytes in the returned String.

New code is encouraged to use String.getBytes(String) or similar methods instead, since this method does not preserve all bits for characters whose codepoint exceeds 8 bits. This method is preserved for compatibility with the SHA-1 authentication scheme.

Parameters
str:String

string

Returns:byte[]

the byte[] (with hexadecimal format) form of the string (str)

validateback to summary
public boolean validate(String key, Serializable value, Dictionary<K, V> p) throws StandardException

Implements org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Validate a property change.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:boolean

true if this object was interested in this property, false otherwise.

Exceptions
StandardException:
Oh well.
See Also
PropertySetCallback#validate