question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] AzureIdentityMysqlAuthenticationPlugin doesn't work with MysqlConnectionPoolDataSource

See original GitHub issue

Describe 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:open
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
backwind1233commented, Oct 31, 2022

A workaround to address this issue is: you can try to remove the defaultAuthenticationPlugin configuration when using MysqlConnectionPoolDataSource:

image

one example of the jdbc url:

String url = "jdbc:mysql://{your-database-aacount}.mysql.database.azure.com:3306/{your-db}?sslMode=REQUIRED&serverTimezone=UTC" 
  +  "&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin";
1reaction
saraglunacommented, Nov 1, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JDBC connection pool for MYSQL Database is not working
trying to ping the server it gives this error: An error has occurred Ping Connection Pool failed for MySqlPool. Connection could not be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found