Skip to content

Commit

Permalink
Add OR operator to fn:filter(like) operator
Browse files Browse the repository at this point in the history
Additionally fix some placeholder resolving issues

Signed-off-by: David Schwilk <david.schwilk@bosch.io>
  • Loading branch information
DerSchwilk committed Jan 31, 2022
1 parent ee65cd2 commit e652166
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Expand Up @@ -46,7 +46,7 @@ public final class JwtSubjectIssuersConfig {
* @param protocol the protocol prefix of all URIs of OAuth endpoints.
*/
private JwtSubjectIssuersConfig(final Iterable<JwtSubjectIssuerConfig> configItems, final String protocol) {
this.protocolPrefix = protocol + "://";
protocolPrefix = protocol + "://";
requireNonNull(configItems);
final Map<String, JwtSubjectIssuerConfig> modifiableSubjectIssuerConfigMap = new HashMap<>();

Expand All @@ -66,7 +66,8 @@ public static JwtSubjectIssuersConfig fromOAuthConfig(final OAuthConfig config)
// merge the default and extension config
Stream.concat(config.getOpenIdConnectIssuers().entrySet().stream(),
config.getOpenIdConnectIssuersExtension().entrySet().stream())
.map(entry -> new JwtSubjectIssuerConfig(entry.getKey(), entry.getValue().getIssuer(), entry.getValue().getAuthorizationSubjectTemplates()))
.map(entry -> new JwtSubjectIssuerConfig(entry.getKey(), entry.getValue().getIssuer(),
entry.getValue().getAuthorizationSubjectTemplates()))
.collect(Collectors.toSet());
return new JwtSubjectIssuersConfig(configItems, config.getProtocol());
}
Expand All @@ -90,7 +91,14 @@ public String getProtocolPrefix() {
* for this issuer
*/
public Optional<JwtSubjectIssuerConfig> getConfigItem(final String issuer) {
return Optional.ofNullable(subjectIssuerConfigMap.get(issuer));
return Optional.ofNullable(getConfigItemByIssuer(issuer).orElse(subjectIssuerConfigMap.get(issuer)));
}

private Optional<JwtSubjectIssuerConfig> getConfigItemByIssuer(final String issuer) {
return subjectIssuerConfigMap.values()
.stream()
.filter(jwtSubjectIssuerConfig -> jwtSubjectIssuerConfig.getIssuer().equals(issuer))
.findFirst();
}

/**
Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.util.HashSet;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -200,6 +201,8 @@ static Stream<PipelineElement> substituteArray(
final Stream<PipelineElement> elements = substitutionFunction.apply(placeholderExpression);

final AtomicInteger counter = new AtomicInteger();
final AtomicReference<StringBuffer> appendingBuffer = new AtomicReference<>(new StringBuffer());

resultBuilder = elements
.filter(element -> !element.getType().equals(PipelineElement.Type.UNRESOLVED))
.flatMap(element -> {
Expand All @@ -208,10 +211,11 @@ static Stream<PipelineElement> substituteArray(
.peek(builder -> {
if (counter.get() == 0) {
counter.getAndIncrement();
matcher.appendReplacement(builder, "");
matcher.appendReplacement(appendingBuffer.get(), "");
}
})
.map(string -> new StringBuffer(string).append(element.toOptional().get()));
.map(string -> new StringBuffer(string).append(appendingBuffer.get())
.append(element.toOptional().get()));
}).collect(Collectors.toSet());
}
return resultBuilder.stream()
Expand Down
Expand Up @@ -37,7 +37,8 @@ public boolean apply(final String... parameters) {
private static String toJavaRegex(final String patternString) {
return Pattern.quote(patternString)
.replaceAll("\\*", "\\\\E.*\\\\Q")
.replaceAll("\\?", "\\\\E.\\\\Q");
.replaceAll("\\?", "\\\\E.\\\\Q")
.replaceAll("\\|", "\\\\E|\\\\Q");
}

}

0 comments on commit e652166

Please sign in to comment.