Repository navigation
Improve rule component to handle non literal values for conditions #8334
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
Open
ashanthamara
wants to merge
6
commits into
wso2:master
Choose a base branch
from
ashanthamara:feature/rule-mgt-field-comparison
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc20175
Improve rule component to handle non literal values for conditions
ashanthamara dd8c637
Address review comments on rule validation and evaluation
ashanthamara a0e18b1
Remove duplicate pom declarations
ashanthamara fee9f78
Fix sonar issues
ashanthamara 6bd1c54
Merge remote-tracking branch 'upstream/master' into feature/rule-mgt-…
ashanthamara 30a3bdc
Remove unneccessary changes
ashanthamara 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import org.wso2.carbon.identity.rule.evaluation.api.model.Field; | ||
| import org.wso2.carbon.identity.rule.evaluation.api.model.ValueType; | ||
| import org.wso2.carbon.identity.rule.management.api.model.Expression; | ||
| import org.wso2.carbon.identity.rule.management.api.model.FieldReference; | ||
| import org.wso2.carbon.identity.rule.management.api.model.Rule; | ||
| import org.wso2.carbon.identity.rule.metadata.api.model.FieldDefinition; | ||
| import org.wso2.carbon.identity.rule.metadata.api.model.OptionsReferenceValue; | ||
|
|
@@ -59,19 +60,35 @@ public FieldExtractor(List<FieldDefinition> expressionMetadataFields) { | |
| public List<Field> extractFields(Rule rule) throws RuleEvaluationException { | ||
|
|
||
| List<Field> fieldList = new ArrayList<>(); | ||
| Set<String> extractedFieldName = new HashSet<>(); | ||
| Set<String> extractedFields = new HashSet<>(); | ||
|
|
||
| for (Expression expression : rule.getExpressions()) { | ||
| String fieldName = expression.getField(); | ||
| if (extractedFieldName.add(fieldName)) { | ||
| // The qualifier takes part in identity: two expressions over the same field with different qualifiers | ||
| // are different values, and de-duplicating on the name alone would drop the second. | ||
|
Comment on lines
+66
to
+67
Contributor
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. do we need this comments. Keep the comments to a minimum and make the code self-explanatory as much as possible |
||
| if (extractedFields.add(FieldLookup.token(expression.getField(), expression.getFieldQualifier()))) { | ||
| // Metadata is held per field, not per qualifier, so the definition is still looked up by name. | ||
| FieldDefinition fieldDefinition = expressionMetadataFieldsMap.get(expression.getField()); | ||
| if (fieldDefinition == null) { | ||
| throw new RuleEvaluationException( | ||
| "Field definition not found for the field: " + expression.getField()); | ||
| } | ||
|
|
||
| Field field = new Field(expression.getField(), resolveValueType(fieldDefinition.getValue())); | ||
| fieldList.add(field); | ||
| fieldList.add(new Field(expression.getField(), expression.getFieldQualifier(), | ||
| resolveValueType(fieldDefinition.getValue()))); | ||
| } | ||
| // A value read from another field needs that field resolved too. | ||
| FieldReference reference = expression.getValue() == null ? null | ||
| : expression.getValue().getFieldReference(); | ||
| if (reference != null && expression.getValue().getType() | ||
| == org.wso2.carbon.identity.rule.management.api.model.Value.Type.FIELD | ||
| && extractedFields.add(FieldLookup.token(reference.getName(), reference.getQualifier()))) { | ||
| FieldDefinition referencedDefinition = expressionMetadataFieldsMap.get(reference.getName()); | ||
| if (referencedDefinition == null) { | ||
| throw new RuleEvaluationException( | ||
| "Field definition not found for the field: " + reference.getName()); | ||
| } | ||
| fieldList.add(new Field(reference.getName(), reference.getQualifier(), | ||
| resolveValueType(referencedDefinition.getValue()))); | ||
| } | ||
| } | ||
|
|
||
|
|
||
51 changes: 51 additions & 0 deletions
51
...main/java/org/wso2/carbon/identity/rule/evaluation/internal/service/impl/FieldLookup.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,51 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you 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.wso2.carbon.identity.rule.evaluation.internal.service.impl; | ||
|
|
||
| /** | ||
| * Identifies a field within one evaluation. | ||
| * <p> | ||
| * A field name alone stops being enough once a field is qualified: two expressions over the same field | ||
| * with different qualifiers are different values, and collapsing them would silently drop one. A field with | ||
| * no qualifier tokenises to its bare name, so every field that existed before qualifiers behaves as it always did. | ||
| */ | ||
| final class FieldLookup { | ||
|
|
||
| /** | ||
| * Separator between a field name and its qualifier. A unit separator is used because neither a field | ||
| * name nor a qualifier may contain a control character, so the token cannot be ambiguous. | ||
| */ | ||
| private static final char SEPARATOR = (char) 0x1F; | ||
|
|
||
| private FieldLookup() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Build the token identifying a field within one evaluation. | ||
| * | ||
| * @param name Field name. | ||
| * @param qualifier Qualifier selecting a value within that field, or null when the field is not qualified. | ||
| * @return Token that distinguishes this field from every other in the same rule. | ||
| */ | ||
| static String token(String name, String qualifier) { | ||
|
|
||
| return qualifier == null ? name : name + SEPARATOR + qualifier; | ||
| } | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.