Skip to content

Commit

Permalink
fix: Interrupt policy scanner at final block (#362)
Browse files Browse the repository at this point in the history
Signed-off-by: Taoyuesong <[email protected]>
  • Loading branch information
Taoyuesong authored Aug 11, 2024
1 parent 6863c41 commit 91904e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
53 changes: 30 additions & 23 deletions Casbin/Enforcer.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,39 @@ private bool InternalEnforce<TRequest, TPolicy>(in EnforceContext context, in TR

if (context.View.HasPolicyParameter && session.HasNextPolicy)
{
int policyIndex = 0;
while (scanner.GetNext(out IPolicyValues outValues))
try
{
TPolicy policyValues = (TPolicy)outValues;
session.PolicyIndex = policyIndex;

HandleBeforeExpression(in context, ref session, in effectChain, in requestValues, policyValues);
session.ExpressionResult = expressionHandler.Invoke(in context, session.ExpressionString,
in requestValues, in policyValues);

if (session.IsChainEffector)
{
HandleExpressionResult(in context, ref session, ref effectChain, in requestValues, policyValues);
}
else
{
HandleExpressionResult(in context, ref session, Effector, in requestValues, policyValues);
}

if (session.Determined)
int policyIndex = 0;
while (scanner.GetNext(out IPolicyValues outValues))
{
scanner.Interrupt();
break;
TPolicy policyValues = (TPolicy)outValues;
session.PolicyIndex = policyIndex;

HandleBeforeExpression(in context, ref session, in effectChain, in requestValues, policyValues);
session.ExpressionResult = expressionHandler.Invoke(in context, session.ExpressionString,
in requestValues, in policyValues);

if (session.IsChainEffector)
{
HandleExpressionResult(in context, ref session, ref effectChain, in requestValues, policyValues);
}
else
{
HandleExpressionResult(in context, ref session, Effector, in requestValues, policyValues);
}

if (session.Determined)
{
scanner.Interrupt();
break;
}

policyIndex++;
}

policyIndex++;
}
finally
{
scanner.Interrupt();
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "7.0.0",
"version": "9.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
}

0 comments on commit 91904e9

Please sign in to comment.