[BUG] AzureIdentityMysqlAuthenticationPlugin doesn't work with MysqlConnectionPoolDataSource
See original GitHub issueDescribe the bug
When running the AzureIdentityMysqlAuthenticationPlugin
with MysqlConnectionPoolDataSource
, there will be an exception says java.sql.SQLException: Access denied for user 'user@company.com@'170.170.170.170' (using password: NO)
Exception or Stack Trace
java.sql.SQLException: Access denied for user 'user@company.com@'170.170.170.170' (using password: NO)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.changeUser(ConnectionImpl.java:564)
at com.mysql.cj.jdbc.ConnectionImpl.resetServerState(ConnectionImpl.java:1791)
at com.mysql.cj.jdbc.MysqlPooledConnection.getConnection(MysqlPooledConnection.java:129)
at com.mysql.cj.jdbc.MysqlPooledConnection.getConnection(MysqlPooledConnection.java:109)
To Reproduce
Add the azure-identity-provider-jdbc-mysql
and run the following code.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity-providers-jdbc-mysql</artifactId>
<version>1.0.0-beta.1</version>
</dependency>
Code Snippet
@Test
public void getServerTimeUmi() throws SQLException {
MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
ds.setUrl(
"jdbc:mysql://xxxx.mysql.database.azure.com/checklist?" +
"useSSL=true&requireSSL=true" +
"&defaultAuthenticationPlugin=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin" +
"&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin"
);
ds.setUser("user@company.com");
ds.setConnectTimeout(60000);
PooledConnection connectionPooled = ds.getPooledConnection();
if (connectionPooled != null) {
Connection connection = connectionPooled.getConnection();
if (connection != null) {
System.out.println("Successfully connected.");
System.out.println(connection.isValid(10));
ResultSet result = connection.prepareStatement("SELECT now() as now").executeQuery();
if (result.next()) {
assertNotNull(result.getString("now"));
}
}
}
}
Expected behavior No exception.
Screenshots N/A
Setup (please complete the following information):
- OS: [MacOS]
- IDE: [IntelliJ]
- Library/Libraries: [azure-identity-provider-jdbc-mysql]
- Java version: [8]
- App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special]
- Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc]
If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError
, NoSuchMethodError
or similar), please check out Troubleshoot dependency version conflict article first. If it doesn’t provide solution for the problem, please provide:
- verbose dependency tree (
mvn dependency:tree -Dverbose
) - exception message, full stack trace, and any available logs
Additional context Add any other context about the problem here.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
A workaround to address this issue is: you can try to remove the defaultAuthenticationPlugin configuration when using MysqlConnectionPoolDataSource:
one example of the jdbc url:
Check this link for more details about the MySQL connection lifecycle: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_lifecycle.html.