8000 fix: allowing the general use of synthetic wildcards by shawkins · Pull Request #48223 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix: allowing the general use of synthetic wildcards - #48223

Merged
vmuzikar merged 1 commit into
keycloak:mainfrom
shawkins:datasources
May 22, 2026
Merged

vmuzikar merged 1 commit into
keycloak:mainfrom
shawkins:datasources

Conversation

@shawkins
Copy link
Copy Markdown
Contributor

also simplifying datasources logic

closes: #48214

@shawkins
Copy link
Copy Markdown
Contributor Author

@mabartos @pruivo this turned more into be a simplification of our datasource logic handling than about the specific wildcard issue.

@pruivo pruivo left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failures look related. I found a missing throw :)

@shawkins
shawkins marked this pull request as ready for review April 21, 2026 15:31
@shawkins
shawkins requested review from a team as code owners April 21, 2026 15:31
@shawkins
shawkins force-pushed the datasources branch 2 times, most recently from 0183809 to c4c7f3b Compare April 21, 2026 17:02
@shawkins
shawkins marked this pull request as draft April 21, 2026 18:50
@shawkins
shawkins marked this pull request as ready for review April 21, 2026 22:30
@shawkins
shawkins marked this pull request as draft April 22, 2026 01:20
@shawkins
shawkins marked this pull request as ready for review April 22, 2026 02:23
@shawkins
shawkins requested a review from pruivo April 22, 2026 02:24
@pruivo pruivo left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just have a suggestion and a question 👍

@@ -458,31 +407,33 @@ private static String transformPoolMaxLifetime(String db, ConfigSourceIntercepto
};
}

public static final class Datasources {
public static final class Datasources extends org.keycloak.config.DatabaseOptions.Datasources {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the reason this and the DatabaseOptions class still exist is just to keep the Option.setWildcardKey method as protected and directly mutating the Option - which we otherwise try to avoid.

I did try though to minimize the public surface area.


Map<String, Option<?>> cachedDatasourceOptions = new HashMap<>();
cachedDatasourceOptions.put(DB.getKey(), DB_KIND);
mappers.stream().map(PropertyMapper::getOption).forEach(o -> getDatasourceOption(o, cachedDatasourceOptions));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unnecessary to populate the map as you can do getDatasourceOption(o, cachedDatasourceOptions) inside the loop below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I didn't fully finish decoupling the logic. Should be better now.

pruivo
pruivo previously approved these changes Apr 23, 2026

Map<String, Option<?>> cachedDatasourceOptions = new HashMap<>();
cachedDatasourceOptions.put(DB.getKey(), DB_KIND);
mappers.stream().map(PropertyMapper::getOption).forEach(o -> cachedDatasourceOptions.computeIfAbsent(o.getKey(), k -> getDatasourceOption(o)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this line can be removed and the cachedDatasourceOptions.get(String) below replaced with cachedDatasourceOptions.computeIfAbsent(Option.getKey(), ignored -> getDatasourceOption(Option));

@shawkins shawkins Apr 23, 2026 •
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but I'm willing to have an extra iteration over the mappers to keep the knowledge of adding entries to the cache localized.

@michalvavrik michalvavrik left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -412,7 +413,7 @@ void checkPersistenceUnits(List<PersistenceXmlDescriptorBuildItem> descriptors)
.filter(descriptor -> !descriptor.getName().equals(DEFAULT_PERSISTENCE_UNIT)) // not default persistence unit
.map(KeycloakProcessor::getDatasourceNameFromPersistenceXml)
.filter(this::missingDbKind)
.map(datasourceName -> DatabaseOptions.Datasources.getNamedKey(DatabaseOptions.DB, datasourceName).orElseThrow()).toList();
.map(datasourceName -> PropertyMappers.getWildcardPropertyMapper(DatabaseOptions.DB_KIND).orElseThrow().getFrom(datasourceName)).toList();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have problem with this, but I don't think previous state where db-kind-<datasource> https://www.keycloak.org/server/all-config?q=db-kind was shown was fine. IIUC kc.db-kind-<datasource> is used in app props, sys props or as KC_... in env vars, but the db-kind-<datasource> is used in keycloak.conf and with -- as CLI option. So db-kind<datasource> is the part that is shared and documented.

@shawkins
shawkins force-pushed the datasources branch 2 times, most recently from e027bb9 to 3d827f4 Compare May 13, 2026 17:15
Comment on lines +596 to +597
DatabasePropertyMappers.getDatasourceOptionValue(DatabaseOptions.DB_SQL_JPA_DEBUG, datasourceName)
.ifPresent(f -> unitProperties.put(AvailableSettings.USE_SQL_COMMENTS, f));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shawkins just to quickly check previously USE_SQL_COMMENTS was only set when the value was true. Now any explicitly set value is passed through to Hibernate. Is this semantic change intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is the appropriate behavior. I would expect for example that I explictly set --db-debug-jpql-datasource=false, that debugging would be turned off.

The line of thinking before may have been not to override the presistence xml if the first-class option were set to its default (false). However that really implies there isn't a default, or the meaning of false needs to be documented clearly.

vmuzikar
vmuzikar previously approved these changes May 22, 2026
@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, looks good.

Comment on lines +220 to +225
(getter, namedProperty, alias) -> "jdbc:oracle:thin:%s//%s:%s/%s".formatted(
DatabaseOptions.DatabaseTlsMode.fromCliValue(getProperty(DatabaseOptions.DB_TLS_MODE, getter,
DatabaseOptions.DatabaseTlsMode.DISABLED.toCliValue())) == DatabaseTlsMode.DISABLED ? "@" : "@tcps:",
getProperty(DatabaseOptions.DB_URL_HOST, getter, "localhost"),
getProperty(DatabaseOptions.DB_URL_PORT, getter, "1521"),
getProperty(DatabaseOptions.DB_URL_DATABASE, getter, "keycloak")),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an old problem but Oracle is missing handling of DatabaseOptions.DB_URL_PROPERTIES. But it's not a regression, it was like that before too, so approving regardless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that was noted in another pr, but I don't think a follow-up was created - adding now so we don't forget this time: #49256

also simplifying datasources logic

closes: keycloak#48214

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
@vmuzikar
vmuzikar enabled auto-merge (squash) May 22, 2026 16:21
@vmuzikar
vmuzikar merged commit aea6b24 into keycloak:main May 22, 2026
95 of 97 checks passed
@stianst stianst mentioned this pull request Jun 1, 2026
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
also simplifying datasources logic

closes: keycloak#48214

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow usage of from with synthetic wildcards

5 participants

0