-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Expose lookup of realm domain config by realm id #106424
Changes from all commits
738ad64
68513ba
6a786d3
31c1a88
a31f86a
3eeb630
9e1e427
91c4985
f69de93
736434f
7d6985f
2781395
2aa73cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -49,6 +49,7 @@ | |||
import java.util.List; | ||||
import java.util.Map; | ||||
import java.util.Map.Entry; | ||||
import java.util.Objects; | ||||
import java.util.Set; | ||||
import java.util.concurrent.atomic.AtomicBoolean; | ||||
import java.util.function.Function; | ||||
|
@@ -110,7 +111,13 @@ public Realms( | |||
// initRealms will add default file and native realm config if they are not explicitly configured | ||||
final List<Realm> initialRealms = initRealms(realmConfigs); | ||||
realmRefs = calculateRealmRefs(realmConfigs, realmToDomainConfig); | ||||
initialRealms.forEach(realm -> realm.initRealmRef(realmRefs)); | ||||
for (Realm realm : initialRealms) { | ||||
Authentication.RealmRef realmRef = Objects.requireNonNull( | ||||
realmRefs.get(new RealmConfig.RealmIdentifier(realm.type(), realm.name())), | ||||
"realmRef can not be null" | ||||
); | ||||
realm.setRealmRef(realmRef); | ||||
} | ||||
|
||||
this.allConfiguredRealms = initialRealms; | ||||
this.allConfiguredRealms.forEach(r -> r.initialize(this.allConfiguredRealms, licenseState)); | ||||
|
@@ -155,6 +162,12 @@ private Map<RealmConfig.RealmIdentifier, Authentication.RealmRef> calculateRealm | |||
new Authentication.RealmRef(realmIdentifier.getName(), realmIdentifier.getType(), nodeName, realmDomain) | ||||
); | ||||
} | ||||
assert realmRefs.values().stream().filter(realmRef -> ReservedRealm.TYPE.equals(realmRef.getType())).toList().size() == 1 | ||||
: "there must be exactly one reserved realm configured"; | ||||
assert realmRefs.values().stream().filter(realmRef -> NativeRealmSettings.TYPE.equals(realmRef.getType())).toList().size() == 1 | ||||
: "there must be exactly one native realm configured"; | ||||
assert realmRefs.values().stream().filter(realmRef -> FileRealmSettings.TYPE.equals(realmRef.getType())).toList().size() == 1 | ||||
: "there must be exactly one file realm configured"; | ||||
return Map.copyOf(realmRefs); | ||||
} | ||||
|
||||
|
@@ -368,8 +381,52 @@ public Map<String, Object> domainUsageStats() { | |||
} | ||||
} | ||||
|
||||
public Map<RealmConfig.RealmIdentifier, Authentication.RealmRef> getRealmRefs() { | ||||
return realmRefs; | ||||
/** | ||||
* Retrieves the {@link Authentication.RealmRef}, which contains the {@link DomainConfig}, if configured, | ||||
* for the passed in {@link RealmConfig.RealmIdentifier}. | ||||
* If the realm is not currently configured, {@code null} is returned. | ||||
*/ | ||||
public @Nullable Authentication.RealmRef getRealmRef(RealmConfig.RealmIdentifier realmIdentifier) { | ||||
// "file", "native", and "reserved" realms may be renamed, but they refer to the same corpus of users | ||||
if (FileRealmSettings.TYPE.equals(realmIdentifier.getType())) { | ||||
return getFileRealmRef(); | ||||
} else if (NativeRealmSettings.TYPE.equals(realmIdentifier.getType())) { | ||||
return getNativeRealmRef(); | ||||
Comment on lines
+391
to
+394
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The kink here is that the name of the native or file realms is irrelevant, when considering the domain configuration, see also Line 664 in c1d0e8e
|
||||
} else if (ReservedRealm.TYPE.equals(realmIdentifier.getType())) { | ||||
return getReservedRealmRef(); | ||||
Comment on lines
+395
to
+396
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reserved realm is less relevant in the domain context, because it cannot be assigned to any. |
||||
} else { | ||||
// but for other realms, it is assumed that a different realm name or realm type signifies a different corpus of users | ||||
return realmRefs.get(realmIdentifier); | ||||
} | ||||
} | ||||
|
||||
public Authentication.RealmRef getNativeRealmRef() { | ||||
return realmRefs.values() | ||||
.stream() | ||||
.filter(realmRef -> NativeRealmSettings.TYPE.equals(realmRef.getType())) | ||||
.findFirst() | ||||
.orElseThrow(() -> new IllegalStateException("native realm realm ref not found")); | ||||
} | ||||
|
||||
public Authentication.RealmRef getFileRealmRef() { | ||||
return realmRefs.values() | ||||
.stream() | ||||
.filter(realmRef -> FileRealmSettings.TYPE.equals(realmRef.getType())) | ||||
.findFirst() | ||||
.orElseThrow(() -> new IllegalStateException("file realm realm ref not found")); | ||||
} | ||||
|
||||
public Authentication.RealmRef getReservedRealmRef() { | ||||
return realmRefs.values() | ||||
.stream() | ||||
.filter(realmRef -> ReservedRealm.TYPE.equals(realmRef.getType())) | ||||
.findFirst() | ||||
.orElseThrow(() -> new IllegalStateException("reserved realm realm ref not found")); | ||||
} | ||||
|
||||
// should only be useful for testing | ||||
int getRealmRefsCount() { | ||||
return realmRefs.size(); | ||||
} | ||||
|
||||
@Override | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the goal of this PR.
It exposes the domain configuration (the set of realm ids) for a given realm id.
The plan is to use the realm id of the API Key owner to retrieve the domain using this method. Then retrieve the profiles associated to any of the realms in the domain.