Skip to content

Simplify JDBC service customization #872

Closed
@dciarniello

Description

@dciarniello

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions