Skip to content

MatchersManager.match返回错误的Policy #3165

@zhaozw

Description

@zhaozw

  public <T extends AbstractPolicy> T match(GovernanceRequest request, Map<String, T> policies) {
    Map<String, Boolean> calculatedMatches = invocationContext.getCalculatedMatches();

    List<T> sortPolicies = new ArrayList<>(policies.size());
    sortPolicies.addAll(policies.values());
    sortPolicies.sort(T::compareTo);

    for (T policy : sortPolicies) {
      if (calculatedMatches.containsKey(policy.getName())) {
        return policy;
      }

      boolean keyMatch = matchersService.checkMatch(request, policy.getName());
      invocationContext.addMatch(policy.getName(), keyMatch);
      if (keyMatch) {
        return policy;
      }
    }
    return null;
  }

针对同一类型的配置policies的值是不变的,但是request可以是不同的,但是如果所有的policy都加入calculatedMatches缓存之后,calculatedMatches.containsKey(policy.getName())一直是true,也就是每次都会返回第一个policy,无论路径是什么,建议加一个url + policytype到policy的映射,或者calculatedMatches 的可以由url和policy.getName()拼接的,或者其它好的办法

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions