Top Fields Constructors Methods
com.mysql.cj.protocol.a

public Class NativeAuthenticationProvider

extends Object
implements AuthenticationProvider<NativePacketPayload>
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.AuthenticationProvider
Imports
java.util.ArrayList, .Collections, .HashMap, .LinkedList, .List, .Map, com.mysql.cj.Constants, .Messages, com.mysql.cj.callback.MysqlCallbackHandler, .UsernameCallback, com.mysql.cj.conf.PropertyDefinitions.SslMode, .PropertyKey, .PropertySet, .RuntimeProperty, com.mysql.cj.exceptions.ExceptionFactory, .ExceptionInterceptor, .UnableToConnectException, .WrongArgumentException, com.mysql.cj.protocol.AuthenticationPlugin, .AuthenticationProvider, .Protocol, .ServerSession, com.mysql.cj.protocol.a.NativeConstants.IntegerDataType, .NativeConstants.StringLengthDataType, .NativeConstants.StringSelfDataType, com.mysql.cj.protocol.a.authentication.AuthenticationKerberosClient, .AuthenticationLdapSaslClientPlugin, .AuthenticationOciClient, .AuthenticationOpenidConnectClient, .AuthenticationWebAuthnClient, .CachingSha2PasswordPlugin, .MysqlClearPasswordPlugin, .MysqlNativePasswordPlugin, .MysqlOldPasswordPlugin, .Sha256PasswordPlugin, com.mysql.cj.protocol.a.result.OkPacket, com.mysql.cj.util.StringUtils, .Util

Field Summary

Modifier and TypeField and Description
private static final int
private Map<String, AuthenticationPlugin<NativePacketPayload>>
authenticationPlugins

Contains instances of authentication plugins that implements AuthenticationPlugin interface.

private MysqlCallbackHandler
callbackHandler

A callback for updating the username from the authentication plugin.

private boolean
clientDefaultAuthenticationPluginExplicitelySet

Was the client default authentication plugin explicitly set?

private String
clientDefaultAuthenticationPluginName

Protocol name of default authentication plugin in client

private String
private ExceptionInterceptor
private static final String
private String
private PropertySet
private Protocol<NativePacketPayload>
private String
private String
serverDefaultAuthenticationPluginName

Protocol name of default authentication plugin in server

private boolean
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
changeUser(String
user name
user
,
String
password
pass
,
String
database name
db
)

Implements com.mysql.cj.protocol.AuthenticationProvider.changeUser.

Re-authenticates as the given user and password

private void
checkConfidentiality(AuthenticationPlugin<?> plugin)

Check if given plugin requires confidentiality, but connection is without SSL

public void
connect(String
user name
user
,
String
password
pass
,
String
database name
db
)

Implements com.mysql.cj.protocol.AuthenticationProvider.connect.

Initialize communications with the MySQL server.

private NativePacketPayload
createChangeUserPacket(ServerSession serverSession, String pluginName, NativePacketPayload authData)

private NativePacketPayload
private AuthenticationPlugin<NativePacketPayload>

Returns:

null if plugin is not found or authentication plugin instance initialized with current connection properties
getAuthenticationPlugin
(String
mysql protocol plugin names, for example "caching_sha2_password" and "mysql_native_password" for built-in plugins
pluginName
)

Get an authentication plugin instance from the authentication plugins map by pluginName key.

private Map<String, String>
public ExceptionInterceptor
private String
getNthFactorPassword(int nthFactor)

public void
private void
loadAuthenticationPlugins()

Fill the authentication plugins map.

private void
proceedHandshakeWithPluggableAuthentication(final NativePacketPayload
the Auth Challenge Packet received from server if this method is used during the initial connection. Otherwise null.
challenge
)

Performs an authentication handshake to authorize connection to a given database as a given MySQL user.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTH_411_OVERHEADback to summary
private static final int AUTH_411_OVERHEAD
authenticationPluginsback to summary
private Map<String, AuthenticationPlugin<NativePacketPayload>> authenticationPlugins

Contains instances of authentication plugins that implements AuthenticationPlugin interface. Key values are MySQL protocol plugin names, for example "caching_sha2_password" and "mysql_native_password" for built-in plugins.

callbackHandlerback to summary
private MysqlCallbackHandler callbackHandler

A callback for updating the username from the authentication plugin.

clientDefaultAuthenticationPluginExplicitelySetback to summary
private boolean clientDefaultAuthenticationPluginExplicitelySet

Was the client default authentication plugin explicitly set?

clientDefaultAuthenticationPluginNameback to summary
private String clientDefaultAuthenticationPluginName

Protocol name of default authentication plugin in client

databaseback to summary
private String database
exceptionInterceptorback to summary
private ExceptionInterceptor exceptionInterceptor
NONEback to summary
private static final String NONE
passwordback to summary
private String password
propertySetback to summary
private PropertySet propertySet
protocolback to summary
private Protocol<NativePacketPayload> protocol
seedback to summary
private String seed
serverDefaultAuthenticationPluginNameback to summary
private String serverDefaultAuthenticationPluginName

Protocol name of default authentication plugin in server

useConnectWithDbback to summary
private boolean useConnectWithDb
usernameback to summary
private String username

Constructor Detail

NativeAuthenticationProviderback to summary
public NativeAuthenticationProvider()

Method Detail

appendConnectionAttributesback to summary
private void appendConnectionAttributes(NativePacketPayload buf, String attributes, String enc)
changeUserback to summary
public void changeUser(String user, String pass, String db)

Implements com.mysql.cj.protocol.AuthenticationProvider.changeUser.

Re-authenticates as the given user and password

Parameters
user:String

user name

pass:String

password

db:String

database name

Annotations
@Override
checkConfidentialityback to summary
private void checkConfidentiality(AuthenticationPlugin<?> plugin)

Check if given plugin requires confidentiality, but connection is without SSL

Parameters
plugin:AuthenticationPlugin<?>

AuthenticationPlugin

connectback to summary
public void connect(String user, String pass, String db)

Implements com.mysql.cj.protocol.AuthenticationProvider.connect.

Initialize communications with the MySQL server. Handles logging on, and handling initial connection errors.

Parameters
user:String

user name

pass:String

password

db:String

database name

Annotations
@Override
createChangeUserPacketback to summary
private NativePacketPayload createChangeUserPacket(ServerSession serverSession, String pluginName, NativePacketPayload authData)
createHandshakeResponsePacketback to summary
private NativePacketPayload createHandshakeResponsePacket(ServerSession serverSession, String pluginName, NativePacketPayload authData)
getAuthenticationPluginback to summary
private AuthenticationPlugin<NativePacketPayload> getAuthenticationPlugin(String pluginName)

Get an authentication plugin instance from the authentication plugins map by pluginName key. If such plugin is found, its method AuthenticationPlugin#isReusable() is called and if the value returned is false then a new instance of the plugin is returned otherwise the instance that already exists is returned. If plugin is not found method returns null, in such case the subsequent behavior of handshake process depends on type of last packet received from server: if it was Auth Challenge Packet then handshake will proceed with default plugin, if it was Auth Method Switch Request Packet then handshake will be interrupted with exception.

Parameters
pluginName:String

mysql protocol plugin names, for example "caching_sha2_password" and "mysql_native_password" for built-in plugins

Returns:AuthenticationPlugin<NativePacketPayload>

null if plugin is not found or authentication plugin instance initialized with current connection properties

Annotations
@SuppressWarnings:unchecked
getConnectionAttributesMapback to summary
private Map<String, String> getConnectionAttributesMap(String attStr)
getExceptionInterceptorback to summary
public ExceptionInterceptor getExceptionInterceptor()
getNthFactorPasswordback to summary
private String getNthFactorPassword(int nthFactor)
initback to summary
public void init(Protocol<NativePacketPayload> prot, PropertySet propSet, ExceptionInterceptor excInterceptor)

Implements com.mysql.cj.protocol.AuthenticationProvider.init.

Annotations
@Override
loadAuthenticationPluginsback to summary
private void loadAuthenticationPlugins()

Fill the authentication plugins map. Starts by filling the map with instances of the built-in authentication plugins. Then creates instances of plugins listed in the "authenticationPlugins" connection property and adds them to the map too. The plugins map uses the plugin names as keys, which are obtained from AuthenticationPlugin#getProtocolPluginName() thus it is possible to replace built-in plugins with custom implementations as long as the implementations use the same MySQL authentication plugin client-side name, such as, "caching_sha2_password" and "mysql_native_password".

Annotations
@SuppressWarnings:unchecked
proceedHandshakeWithPluggableAuthenticationback to summary
private void proceedHandshakeWithPluggableAuthentication(final NativePacketPayload challenge)

Performs an authentication handshake to authorize connection to a given database as a given MySQL user. This can happen upon initial connection to the server, after receiving Auth Challenge Packet, or at any moment during the connection life-time via a Change User request. This method will use registered authentication plugins as requested by the server.

Parameters
challenge:NativePacketPayload

the Auth Challenge Packet received from server if this method is used during the initial connection. Otherwise null.