Skip to content

Simplify JDBC service customization #872

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
dciarniello opened this issue Aug 24, 2022 · 2 comments
Closed

Simplify JDBC service customization #872

dciarniello opened this issue Aug 24, 2022 · 2 comments
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@dciarniello
Copy link

dciarniello commented Aug 24, 2022

I understand that it is difficult (impossible?) to come provide implementations that work out of the box with all DBs but it would be helpful if the default implementations were simpler to customize.

For example, I'm finding that customizing JdbcOAuth2AuthorizationService to handle mariadb to be somewhat cumbersome.
The mariadb jdbc driver, for some reason that is not entirely clear to me, sets the BLOB column type to LONGVARBINARY which JdbcOAuth2AuthorizationService does not handle. It seemed that the simplest way to deal with this was to override a method and map LONGVARBINARY to BLOB so that the rest of the code could handle it without further changes.

That is simple enough with JdbcOAuth2AuthorizationService.OAuth2AuthorizationParametersMapper#apply with something like:

@Override
apply(OAuth2Authorization authorization) {
  return super.apply(authorization).stream.map(v -> {
	if(v.getSqlType() == Types.LONGVARBINARY && v.getValue() != null) {
		return new SqlParameterValue(Types.BLOB, ((String)v.getValue()).getBytes(StandardCharsets.UTF_8));
	}
	return v;
}).collect(Collectors.toList());

A similar operation would be required for JdbcOAuth2AuthorizationService#findBy but that method is private so it's not possible to override and overriding the findBy methods that call findBy is not feasible because those method rely heavily on private static members.

The only option that I had, short of completely writing my own implementation, was to make a copy JdbcOAuth2AuthorizationService and make one simple change:

private static SqlParameterValue mapToSqlParameter(String columnName, String value) {
	ColumnMetadata columnMetadata = columnMetadataMap.get(columnName);
	return (Types.BLOB == columnMetadata.getDataType() || Types.LONGVARBINARY == columnMetadata.getDataType()) && StringUtils.hasText(value) ?
			new SqlParameterValue(Types.BLOB, value.getBytes(StandardCharsets.UTF_8)) :
			new SqlParameterValue(columnMetadata.getDataType(), value);
}

To my mind, a wholesale copy of a class just to make such a simple change is a bit of overkill.

@dciarniello dciarniello added the type: enhancement A general enhancement label Aug 24, 2022
@dciarniello dciarniello changed the title Simply JDBC service customization Simplify JDBC service customization Aug 25, 2022
@jgrandja
Copy link
Collaborator

@dciarniello This appears to be a duplicate of gh-774.

Please see this comment as it explains how you can completely override the default schema.

@jgrandja jgrandja self-assigned this Aug 30, 2022
@jgrandja jgrandja added status: duplicate A duplicate of another issue and removed type: enhancement A general enhancement labels Aug 30, 2022
@swurzinger
Copy link

I don't think this is a duplicate of #550. In that ticket the suggestion is to customize the implementation using a custom OAuth2AuthorizationParametersMapper specific to the database in use. That however does not allow to customize all of the database specific code.

The problem is that JdbcOAuth2AuthorizationService uses some database-specific code internally that is not customizable because it's private and/or static.

Ideally the implementation should be as generic as possible and should allow database-specific adaptations to be made without having to duplicate the whole class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants