spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

JdbcUserCredentialRepository adds an empty-string transport when loading an empty transport set

Open ryujungkyun opened this issue 1 month ago • 1 comments

Problem

Saving a credential with an empty transport set through JdbcUserCredentialRepository and loading it back returns a set containing one AuthenticatorTransport whose value is an empty string.

  1. Before saving: the transport set is empty ([]).
  2. In the database: the empty set is stored as an empty string ("").
  3. After loading: the set contains one empty-string entry ([""]).

This behavior was reproduced using HSQLDB.

Expected behavior

An empty transport set should remain empty after saving and loading. Currently, loading the credential adds an entry that was not present before saving.

Cause

The repository stores an empty transport set as "". When loading the credential, it splits the stored value using:

rs.getString("authenticator_transports").split(",")

"".split(",") returns an array containing one empty string instead of an empty array. The row mapper then calls AuthenticatorTransport.valueOf(""), adding an object with an empty string value to the set.

Related

ryujungkyun avatar Nov 03 '26 09:11 ryujungkyun

I'd like to take this.

The empty-string split(",") path is clear; I'll add a round-trip test for an empty transport set and fix the load (and save if needed) so []\ stays [].

L00PLeGeNd avatar Nov 07 '26 11:11 L00PLeGeNd