Expected Behavior
An application can choose a PostgresDB backend to implement org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService. This would include cloud offerings such as AWS Aurora DSQL.
Current Behavior
Postgres does not support BLOB (sql type 2004) and CLOB (sql type 2005) types, they use BYTEA (sql type -2) instead. The class JdbcOAuth2AuthorizationService does not have any support for the BYTEA column type, and therefore fails to save or retrieve data to and from the db appropriately.
Context
In order to fix this, I copied the class org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService into my project and modified two methods:
- org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService.AbstractOAuth2AuthorizationRowMapper#getLobValue
- org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService.LobCreatorArgumentPreparedStatementSetter#doSetValue
In both methods, I added support for the BYTEA column type, and treated the data similar to a BLOB type.
for getLobValue, I did this:
if (Types.BINARY == columnMetadata.getDataType()) { byte[] columnValueBytes = this.lobHandler.getBlobAsBytes(rs, columnName); if (columnValueBytes != null) { columnValue = new String(columnValueBytes, StandardCharsets.UTF_8); } }
and for doSetValue, I did this:
`
if (paramValue.getSqlType() == Types.BINARY) {
byte[] valueBytes = null;
if (paramValue.getValue() != null) {
Object value = paramValue.getValue();
if (value instanceof byte[] byteArray) {
valueBytes = byteArray;
}
else if (value instanceof String stringValue) {
valueBytes = stringValue.getBytes(StandardCharsets.UTF_8);
}
}
this.lobCreator.setBlobAsBytes(ps, parameterPosition, valueBytes);
return;
}
`
There could be more to do, but I haven't discovered anything else at the moment.
Expected Behavior
An application can choose a PostgresDB backend to implement org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService. This would include cloud offerings such as AWS Aurora DSQL.
Current Behavior
Postgres does not support BLOB (sql type 2004) and CLOB (sql type 2005) types, they use BYTEA (sql type -2) instead. The class JdbcOAuth2AuthorizationService does not have any support for the BYTEA column type, and therefore fails to save or retrieve data to and from the db appropriately.
Context
In order to fix this, I copied the class org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService into my project and modified two methods:
In both methods, I added support for the BYTEA column type, and treated the data similar to a BLOB type.
for getLobValue, I did this:
if (Types.BINARY == columnMetadata.getDataType()) { byte[] columnValueBytes = this.lobHandler.getBlobAsBytes(rs, columnName); if (columnValueBytes != null) { columnValue = new String(columnValueBytes, StandardCharsets.UTF_8); } }and for doSetValue, I did this:
`
if (paramValue.getSqlType() == Types.BINARY) {
byte[] valueBytes = null;
if (paramValue.getValue() != null) {
}
`
There could be more to do, but I haven't discovered anything else at the moment.