Skip to content

JdbcOAuth2AuthorizationService in postgresql cannot casting type blob #467

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

Closed
phuongdpham opened this issue Oct 24, 2021 · 6 comments
Closed
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@phuongdpham
Copy link

Caused by: org.postgresql.util.PSQLException: Cannot cast an instance of [B to type Types.BLOB

When I set datasource to Postgres, then

private OAuth2Authorization findBy(String filter, List<SqlParameterValue> parameters) { PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray()); List<OAuth2Authorization> result = this.jdbcOperations.query(LOAD_AUTHORIZATION_SQL + filter, pss, this.authorizationRowMapper); return !result.isEmpty() ? result.get(0) : null; }
throw exeption abount casting Types.BLOB to bytea in postgres table oauth2_authorization column access_token_value

Thanks,

@phuongdpham phuongdpham added the type: bug A general bug label Oct 24, 2021
@xialugui
Copy link

There is no type BLOB in Postgres,try bytea:
image

@phuongdpham
Copy link
Author

image

Yep, I declared type of that column is bytea but in code of JdbcOAuth2AuthorizationService method public OAuth2Authorization findByToken(String token, @Nullable OAuth2TokenType tokenType) are bind type java.sql.Types.BLOB to column ACCESS_TOKEN. Then, the jdbc produce exception above.

@sjohnr
Copy link
Member

sjohnr commented Oct 26, 2021

@phuongdpham, as mentioned in this comment:

It is very difficult to provide an implementation that works out of the box for all databases. This implementation strives to use standard sql datatypes and is a simplified JDBC implementation. However, it is designed to be customizable so user's can provide customizations for database vendors that deviate from the standard sql types.

Take a look at JdbcOAuth2AuthorizationServiceTests.tableDefinitionWhenCustomThenAbleToOverride(), which provides a test on how to override the table definition altogether. There are tests in that class that demonstrate how to customize further.

You may also find this comment helpful, as the same technique would apply to the OAuth2AuthorizationParametersMapper.

Lastly, you may be interested in this gist which implements a JpaOAuth2AuthorizationService.

I'm going to close this for now, but if you are still having issues after you have tried out the proposed solutions we can re-open and discuss further.

@sjohnr sjohnr closed this as completed Oct 26, 2021
@sjohnr sjohnr added status: declined A suggestion or change that we don't feel we should currently apply status: invalid An issue that we don't feel is valid and removed type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply labels Oct 26, 2021
@phuongdpham
Copy link
Author

Oh nice, thanks @sjohnr and @xialugui.

I'm very interesting about OAuth2 but rarely example in github. Can you @sjohnr give me a completed simple example about OAuth2 authorization server, resource server and client? Thank you so much.

@sjohnr
Copy link
Member

sjohnr commented Oct 26, 2021

Hi @phuongdpham. We have OAuth 2.0 samples in the spring-security-samples repo. Additionally, some team members presented at SpringOne this year and produced a full sample with all three roles represented. There's a link to a video on that page as well.

Hope that helps!

@phuongdpham
Copy link
Author

Hi @sjohnr, thank you so much. That really helps me a lot 👯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants