Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public void init(Config.Scope config) {
s.add("ssf.enabled");
s.add("ssf.stream.id");
}
if (Profile.isFeatureEnabled(Profile.Feature.CIMD)) {
// needed to find clients with audience mappers added by CIMD (AbstractClientIdMetadataDocumentExecutor)
s.add("cimd.resource.indicator.audience.mappers");
}
clientSearchableAttributes = Collections.unmodifiableSet(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,38 @@ public ClientPolicyVote applyPolicy(ClientPolicyContext context) throws ClientPo
logger.debugv("not URL: clientId = {0}", clientId);
return ClientPolicyVote.NO;
}
if (isUriSchemeMatched(uri) && isTrustedDomainMatched(uri)) return ClientPolicyVote.YES;
if (isUriSchemeMatched(configuration.getClientIdUriSchemes(), uri) && isTrustedDomainMatched(uri)) return ClientPolicyVote.YES;

return ClientPolicyVote.NO;
}

private boolean isUriSchemeMatched(URI uri) {
return configuration.getClientIdUriSchemes().stream().anyMatch(i->i.equals(uri.getScheme()));
/**
* Checks if a client ID matches a configuration of this condition, in the same way as on the
* {@code PRE_AUTHORIZATION_REQUEST} and {@code AUTHORIZATION_REQUEST_REDIRECT_URI} events, without considering
* the negative logic of the configuration. Unlike evaluating the condition on the events, it does not log a mismatch.
*
* @param configuration a configuration of this condition
* @param clientId a client ID
* @return {@code true} if the client ID matches the configuration
*/
public static boolean isClientIdMatched(Configuration configuration, String clientId) {
if (configuration == null || clientId == null || configuration.getClientIdUriSchemes() == null || configuration.getClientIdUriSchemes().isEmpty()) {
return false;
}
final URI uri;
try {
uri = new URI(clientId);
} catch (URISyntaxException e) {
return false;
}
if (!isUriSchemeMatched(configuration.getClientIdUriSchemes(), uri) || uri.getHost() == null) {
return false;
}
return convertContentFilledList(configuration.getTrustedDomains()).stream().anyMatch(i -> checkTrustedDomain(uri.getHost(), i));
}

private static boolean isUriSchemeMatched(List<String> clientIdUriSchemes, URI uri) {
return convertContentFilledList(clientIdUriSchemes).stream().anyMatch(i->i.equals(uri.getScheme()));
}

private boolean isTrustedDomainMatched(URI uri) {
Expand All @@ -121,15 +146,15 @@ private boolean isTrustedDomainMatched(URI uri) {
}

// return a list with non-null, non-blank, and distinct values. If the input list is null, return an empty list.
private List<String> convertContentFilledList(List<String> list) {
private static List<String> convertContentFilledList(List<String> list) {
if (list == null) {
return Collections.emptyList();
}
return list.stream().filter(Objects::nonNull).filter(i->!i.isBlank()).distinct().toList();
}

// apply the same logic in TrustedHostClientRegistrationPolicy.
private boolean checkTrustedDomain(String hostname, String trustedDomain) {
private static boolean checkTrustedDomain(String hostname, String trustedDomain) {
if (trustedDomain.startsWith("*.")) {
String domain = trustedDomain.substring(2);
return hostname.equals(domain) || hostname.endsWith("." + domain);
Expand Down
Loading
Loading