Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(r2dbc): enable_iam_auth throws java.lang.ClassCastException #686

Closed
mpeddada1 opened this issue Dec 29, 2021 · 2 comments · Fixed by #688
Closed

bug(r2dbc): enable_iam_auth throws java.lang.ClassCastException #686

mpeddada1 opened this issue Dec 29, 2021 · 2 comments · Fixed by #688
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mpeddada1
Copy link
Contributor

Due to a limitation in R2DBC, extra options specified through the r2dbc url are automatically typed as String. Therefore, setting the enable_iam_auth option in the r2dbc connection url (r2dbc:gcp:postgres://{INSTANCE_CONNECTION_NAME}/{DATABASE_NAME}?ENABLE_IAM_AUTH=true) results in the following error :

Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
	at com.google.cloud.sql.core.GcpConnectionFactoryProvider.createFactory(GcpConnectionFactoryProvider.java:103)
	at com.google.cloud.sql.core.GcpConnectionFactoryProvider.create(GcpConnectionFactoryProvider.java:96)
	at io.r2dbc.spi.ConnectionFactories.find(ConnectionFactories.java:112)
	at io.r2dbc.spi.ConnectionFactories.get(ConnectionFactories.java:142)
	at org.springframework.boot.r2dbc.ConnectionFactoryBuilder$OptionsCapableWrapper.buildAndWrap(ConnectionFactoryBuilder.java:203)
	at org.springframework.boot.r2dbc.ConnectionFactoryBuilder$PoolingAwareOptionsCapableWrapper.buildAndWrap(ConnectionFactoryBuilder.java:216)
	at org.springframework.boot.r2dbc.ConnectionFactoryBuilder.build(ConnectionFactoryBuilder.java:189)
	at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations.createConnectionFactory(ConnectionFactoryConfigurations.java:61)
	at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$Pool.connectionFactory(ConnectionFactoryConfigurations.java:73)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 102 more

Perhaps doing something similar to CoreSocketFactory#create where we call Boolean.parseBoolean() could help address this. Enabling IAM auth through the JDBC connection url (jdbc:postgresql://google/{DATABASE_NAME}?socketFactory=com.google.cloud.sql.postgres.SocketFactory&cloudSqlInstance={INSTANCE_CONNECTION_NAME}?enableIamAuth=true&sslmode=disable works as expected.

@mpeddada1 mpeddada1 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Dec 29, 2021
@kurtisvg kurtisvg added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Dec 29, 2021
@kurtisvg kurtisvg changed the title R2DBC: Support enabling IAM authentication through the connection url bug(r2dbc): enable_iam_auth doesn Dec 29, 2021
@kurtisvg kurtisvg changed the title bug(r2dbc): enable_iam_auth doesn bug(r2dbc): enable_iam_auth throws java.lang.ClassCastException Dec 29, 2021
@kurtisvg kurtisvg added the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Dec 29, 2021
@kurtisvg
Copy link
Contributor

kurtisvg commented Dec 29, 2021

Thanks for taking the time to file a bug. I added a regression test and fix in #688.

@mpeddada1
Copy link
Contributor Author

Thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
2 participants