@@ -832,11 +832,11 @@ private Task<bool> InternalEnforceAsync(IReadOnlyList<object> requestValues, str
832
832
/// <param name="requestValues">The request needs to be mediated, usually an array of strings,
833
833
/// can be class instances if ABAC is used.</param>
834
834
/// <param name="matcher">The custom matcher.</param>
835
- /// <param name="explains"></param>
835
+ /// <param name="explains">Collection of matched policy explains </param>
836
836
/// <returns>Whether to allow the request.</returns>
837
837
private bool InternalEnforce ( IReadOnlyList < object > requestValues , string matcher = null , ICollection < IEnumerable < string > > explains = null )
838
838
{
839
- EnforceContext context = EnforceContext . Create ( model , matcher , explains is not null ) ;
839
+ var context = EnforceContext . Create ( model , matcher , explains is not null ) ;
840
840
841
841
if ( context . RequestTokens . Count != requestValues . Count )
842
842
{
@@ -955,36 +955,41 @@ private bool InternalEnforce(IReadOnlyList<object> requestValues, string matcher
955
955
/// <param name="context">Storage of enforcer variables</param>
956
956
/// <param name="requestValues">The request needs to be mediated, usually an array of strings, can be class instances if ABAC is used.</param>
957
957
/// <param name="explains">Collection of matched policy explains</param>
958
- /// <param name="maxPriority">Index of maxPriority to filter out lower tier policies</param>
959
958
/// <returns>Whether to allow the request.</returns>
960
959
private bool InternalEnforceWithChainEffector (
961
960
EnforceContext context ,
962
961
IChainEffector chainEffector ,
963
962
IReadOnlyList < object > requestValues = null ,
964
- ICollection < IEnumerable < string > > explains = null ,
965
- PolicyEffectType effectType = PolicyEffectType . Custom ,
966
- int maxPriority = int . MaxValue )
963
+ ICollection < IEnumerable < string > > explains = null )
967
964
{
968
- bool result = false ;
965
+ bool finalResult = false ;
969
966
chainEffector . StartChain ( context . Effect ) ;
970
967
971
968
bool hasPriority = context . PolicyAssertion . TryGetPriorityIndex ( out int priorityIndex ) ;
969
+ bool isPriorityDenyOverrideEfffet = chainEffector . PolicyEffectType is PolicyEffectType . PriorityDenyOverride ;
970
+ int ? priority = null ;
972
971
973
972
if ( context . Policies . Count is not 0 )
974
973
{
975
- IEnumerable < IReadOnlyList < string > > policies = context . Policies ;
976
- if ( hasPriority && chainEffector . PolicyEffectType is PolicyEffectType . PriorityDenyOverride )
977
- {
978
- policies = policies . Where ( t => maxPriority == int . MaxValue || int . Parse ( t [ priorityIndex ] ) == maxPriority ) ;
979
- }
980
-
981
- foreach ( IReadOnlyList < string > policyValues in policies )
974
+ foreach ( IReadOnlyList < string > policyValues in context . Policies )
982
975
{
983
976
if ( context . PolicyTokens . Count != policyValues . Count )
984
977
{
985
978
throw new ArgumentException ( $ "Invalid policy size: expected { context . PolicyTokens . Count } , got { policyValues . Count } .") ;
986
979
}
987
980
981
+ if ( hasPriority && isPriorityDenyOverrideEfffet )
982
+ {
983
+ if ( int . TryParse ( policyValues [ priorityIndex ] , out int nowPriority ) )
984
+ {
985
+ if ( priority . HasValue && nowPriority != priority . Value )
986
+ {
987
+ break ;
988
+ }
989
+ priority = nowPriority ;
990
+ }
991
+ }
992
+
988
993
ExpressionHandler . SetPolicyParameters ( policyValues ) ;
989
994
990
995
bool expressionResult ;
@@ -1001,14 +1006,6 @@ private bool InternalEnforceWithChainEffector(
1001
1006
1002
1007
var nowEffect = GetEffect ( expressionResult ) ;
1003
1008
1004
- if ( context . Effect . Equals ( PermConstants . PolicyEffect . PriorityDenyOverride )
1005
- && nowEffect == Effect . Effect . Allow
1006
- && maxPriority == int . MaxValue )
1007
- {
1008
- return InternalEnforceWithChainEffector ( context , chainEffector , requestValues , explains , effectType ,
1009
- int . Parse ( policyValues [ priorityIndex ] ) ) ;
1010
- }
1011
-
1012
1009
if ( nowEffect is not Effect . Effect . Indeterminate
1013
1010
&& ExpressionHandler . Parameters . TryGetValue ( "p_eft" , out Parameter parameter ) )
1014
1011
{
@@ -1034,7 +1031,7 @@ private bool InternalEnforceWithChainEffector(
1034
1031
}
1035
1032
}
1036
1033
1037
- result = chainEffector . Result ;
1034
+ finalResult = chainEffector . Result ;
1038
1035
}
1039
1036
else
1040
1037
{
@@ -1049,7 +1046,7 @@ private bool InternalEnforceWithChainEffector(
1049
1046
1050
1047
if ( chainEffector . TryChain ( nowEffect ) )
1051
1048
{
1052
- result = chainEffector . Result ;
1049
+ finalResult = chainEffector . Result ;
1053
1050
}
1054
1051
1055
1052
if ( context . Explain && chainEffector . HitPolicy )
@@ -1061,14 +1058,14 @@ private bool InternalEnforceWithChainEffector(
1061
1058
#if ! NET45
1062
1059
if ( context . Explain )
1063
1060
{
1064
- Logger ? . LogEnforceResult ( requestValues , result , explains ) ;
1061
+ Logger ? . LogEnforceResult ( requestValues , finalResult , explains ) ;
1065
1062
}
1066
1063
else
1067
1064
{
1068
- Logger ? . LogEnforceResult ( requestValues , result ) ;
1065
+ Logger ? . LogEnforceResult ( requestValues , finalResult ) ;
1069
1066
}
1070
1067
#endif
1071
- return result ;
1068
+ return finalResult ;
1072
1069
}
1073
1070
1074
1071
private static Effect . Effect GetEffect ( bool expressionResult )
0 commit comments