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 @@ -91,6 +91,31 @@ public ClientPolicyVote applyPolicy(ClientPolicyContext context) throws ClientPo
}
}

/**
* Checks if a client ID matches a configuration of this condition, in the same way as on the
* {@code PRE_AUTHORIZATION_REQUEST} event, without considering the negative logic of the configuration.
* Unlike evaluating the condition on the event, 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 (configuration.getClientIdUriSchemes().stream().noneMatch(i -> i.equals(uri.getScheme())) || uri.getHost() == null) {
return false;
}
return convertContentFilledList(configuration.getTrustedDomains()).stream().anyMatch(i -> checkTrustedDomain(uri.getHost(), i));
}

private boolean isUriSchemeMatched(URI uri) {
return configuration.getClientIdUriSchemes().stream().anyMatch(i->i.equals(uri.getScheme()));
Comment on lines +104 to 120
}
Expand All @@ -116,15 +141,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