Repository navigation
WIP - Add support for configuration profiles #10429
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
Closed
Closed
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
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
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,122 @@ | ||
| package org.keycloak.util; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import org.keycloak.Config; | ||
|
|
||
| import static org.keycloak.Config.Scope; | ||
|
|
||
| public class ConfigUtil { | ||
|
|
||
| public static class CompositeScope implements Scope { | ||
|
|
||
| private Scope[] scopes; | ||
|
|
||
| public CompositeScope(Scope... scopes) { | ||
| this.scopes = scopes == null ? new Scope[0] : scopes; | ||
| } | ||
|
|
||
| @Override | ||
| public String get(String key) { | ||
| return this.get(key, null); | ||
| } | ||
|
|
||
| @Override | ||
| public String get(String key, String defaultValue) { | ||
| for (Scope scope : this.scopes) { | ||
| String value = scope.get(key); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return defaultValue; | ||
| } | ||
|
|
||
| @Override | ||
| public String[] getArray(String key) { | ||
| for (Scope scope : this.scopes) { | ||
| String[] value = scope.getArray(key); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Integer getInt(String key) { | ||
| return this.getInt(key, null); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer getInt(String key, Integer defaultValue) { | ||
| for (Scope scope : this.scopes) { | ||
| Integer value = scope.getInt(key); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return defaultValue; | ||
| } | ||
|
|
||
| @Override | ||
| public Long getLong(String key) { | ||
| return this.getLong(key, null); | ||
| } | ||
|
|
||
| @Override | ||
| public Long getLong(String key, Long defaultValue) { | ||
| for (Scope scope : this.scopes) { | ||
| Long value = scope.getLong(key); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return defaultValue; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean getBoolean(String key) { | ||
| return this.getBoolean(key, null); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean getBoolean(String key, Boolean defaultValue) { | ||
| for (Scope scope : this.scopes) { | ||
| Boolean value = scope.getBoolean(key); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return defaultValue; | ||
| } | ||
|
|
||
| @Override | ||
| public Scope scope(String... scope) { | ||
| Scope[] subScopes = new Scope[this.scopes.length]; | ||
| for (int i = 0; i < this.scopes.length; i++) { | ||
| subScopes[i] = this.scopes[i].scope(scope); | ||
| } | ||
| return new CompositeScope(subScopes); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getPropertyNames() { | ||
| Set<String> propertyNames = new HashSet<>(); | ||
| for (Scope scope : this.scopes) { | ||
| Set<String> scopePropertyNames = scope.getPropertyNames(); | ||
| if (scopePropertyNames != null) { | ||
| propertyNames.addAll(scopePropertyNames); | ||
| } | ||
| } | ||
| return propertyNames; | ||
| } | ||
| } | ||
|
|
||
| public static Scope getProviderScope(final String spiName, final String provider, final String profile) { | ||
| Scope rootScope = Config.scope(spiName, provider); | ||
| Scope profileScope = rootScope.scope("profile", profile); | ||
| return new CompositeScope(profileScope, rootScope); | ||
| } | ||
| } |
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
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
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
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
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
23 changes: 23 additions & 0 deletions
23
server-spi-private/src/main/java/org/keycloak/component/ProfileEnabledProviderFactory.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,23 @@ | ||
| /* | ||
| * Copyright 2022 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.component; | ||
|
|
||
| /** | ||
| * Marker interface to identify provider factories that support multiple configuration profiles. | ||
| */ | ||
| public interface ProfileEnabledProviderFactory { | ||
|
Contributor
Author
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. I propose the introduction of this interface to allow the code that is initializing the instantiated factories to handle profiles only if the factory supports them, for efficiency reasons. But, of course, this can be changed. |
||
| } | ||
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
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
Oops, something went wrong.
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.
Where does this constant originate from?
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.
Right now it is coming from the SPI name. For authorization the different areas are not currently separated, they are all initialized to use the same storage factory. I don't know if we will change that in the future so that the different authz models will be configurable independently with respect to the storage factory, but for now they all share the same so I decided to use the SPI name.
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.
If we won't be splitting the different authz models, then perhaps a better name for the authz storage would be simply
authorization.