-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Handle ignored artifacts separately #21440
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...us/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/IgnoredArtifacts.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Copyright 2023 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.keycloak.quarkus.runtime.configuration; | ||
|
|
||
| import org.keycloak.common.Profile; | ||
| import org.keycloak.config.StorageOptions; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| import static java.util.Collections.emptySet; | ||
| import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile; | ||
|
|
||
| /** | ||
| * Ignore particular artifacts based on build configuration | ||
| */ | ||
| public class IgnoredArtifacts { | ||
|
|
||
| public static Set<String> getDefaultIgnoredArtifacts() { | ||
| return new Builder() | ||
| .append(fips()) | ||
| .append(storage()) | ||
| .build(); | ||
| } | ||
|
|
||
| // FIPS | ||
| public static final Set<String> FIPS_ENABLED = Set.of( | ||
| "org.bouncycastle:bcprov-jdk18on", | ||
| "org.bouncycastle:bcpkix-jdk18on", | ||
| "org.bouncycastle:bcutil-jdk18on", | ||
| "org.keycloak:keycloak-crypto-default" | ||
| ); | ||
|
|
||
| public static final Set<String> FIPS_DISABLED = Set.of( | ||
| "org.keycloak:keycloak-crypto-fips1402", | ||
| "org.bouncycastle:bc-fips", | ||
| "org.bouncycastle:bctls-fips", | ||
| "org.bouncycastle:bcpkix-fips" | ||
| ); | ||
|
|
||
| private static Set<String> fips() { | ||
| final Profile profile = getCurrentOrCreateFeatureProfile(); | ||
| boolean isFipsEnabled = profile.getFeatures().get(Profile.Feature.FIPS); | ||
|
|
||
| return isFipsEnabled ? FIPS_ENABLED : FIPS_DISABLED; | ||
| } | ||
|
|
||
| // Map Store | ||
| public static final Set<String> MAP_STORE = Set.of( | ||
| "org.keycloak:keycloak-model-map-jpa", | ||
| "org.keycloak:keycloak-model-map-hot-rod", | ||
| "org.keycloak:keycloak-model-map", | ||
| "org.keycloak:keycloak-model-map-file" | ||
| ); | ||
|
|
||
| private static Set<String> storage() { | ||
| Optional<String> storage = Configuration.getOptionalValue( | ||
| MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + StorageOptions.STORAGE.getKey()); | ||
|
|
||
| return storage.isEmpty() ? MAP_STORE : emptySet(); | ||
| } | ||
|
|
||
| /** | ||
| * Builder for artifacts aggregation | ||
| */ | ||
| private static final class Builder { | ||
| private final Set<String> finalIgnoredArtifacts; | ||
|
|
||
| public Builder() { | ||
| this.finalIgnoredArtifacts = new HashSet<>(); | ||
| } | ||
|
|
||
| public Builder append(Set<String> ignoredArtifacts) { | ||
| finalIgnoredArtifacts.addAll(ignoredArtifacts); | ||
| return this; | ||
| } | ||
|
|
||
| public Set<String> build() { | ||
| return finalIgnoredArtifacts; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...e/src/test/java/org/keycloak/quarkus/runtime/configuration/test/IgnoredArtifactsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright 2023 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.keycloak.quarkus.runtime.configuration.test; | ||
|
|
||
| import org.junit.Test; | ||
| import org.keycloak.common.Profile; | ||
| import org.keycloak.common.profile.PropertiesProfileConfigResolver; | ||
| import org.keycloak.config.StorageOptions; | ||
| import org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts; | ||
| import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider; | ||
|
|
||
| import java.util.Properties; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
|
|
||
| public class IgnoredArtifactsTest { | ||
|
|
||
| @Test | ||
| public void fipsDisabled() { | ||
| var profile = Profile.defaults(); | ||
| assertThat(profile.isFeatureEnabled(Profile.Feature.FIPS), is(false)); | ||
|
|
||
| var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); | ||
| assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.FIPS_DISABLED), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| public void fipsEnabled() { | ||
| Properties properties = new Properties(); | ||
| properties.setProperty("keycloak.profile.feature.fips", "enabled"); | ||
| var profile = Profile.configure(new PropertiesProfileConfigResolver(properties)); | ||
|
|
||
| assertThat(profile.isFeatureEnabled(Profile.Feature.FIPS), is(true)); | ||
|
|
||
| var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); | ||
| assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.FIPS_ENABLED), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| public void ignoredMapStorage() { | ||
| var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); | ||
| assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.MAP_STORE), is(true)); | ||
|
|
||
| Consumer<String> assertStorage = (storage) -> { | ||
| System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + StorageOptions.STORAGE.getKey(), storage); | ||
|
|
||
| try { | ||
| final var artifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); | ||
| assertThat(artifacts.containsAll(IgnoredArtifacts.MAP_STORE), is(false)); | ||
| } finally { | ||
| System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + StorageOptions.STORAGE.getKey(), ""); | ||
| } | ||
| }; | ||
|
|
||
| assertStorage.accept("jpa"); | ||
| assertStorage.accept("hotrod"); | ||
| assertStorage.accept("file"); | ||
| assertStorage.accept("chm"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 feels to me like a bit overkill. ;) Could be easily replaced e.g. by
Stream.of(...).flatMap(Collection::stream).collect(Collectors.toSet());. But not a blocker for me...