|
@@ -30,12 +30,12 @@ import org.springframework.data.redis.core.SessionCallback;
|
|
|
@Slf4j
|
|
|
public class DefaultFirewallProcessor implements FirewallProcessor {
|
|
|
private final VariableParser parser;
|
|
|
- private final List<Action> actions;
|
|
|
+ private final ActionExecutor executor;
|
|
|
private volatile IdentityUtils.Generator sequenceGenerator;
|
|
|
|
|
|
- public DefaultFirewallProcessor(@NonNull VariableParser parser, @NonNull List<Action> actions) {
|
|
|
+ public DefaultFirewallProcessor(@NonNull VariableParser parser, @NonNull ActionExecutor executor) {
|
|
|
this.parser = parser;
|
|
|
- this.actions = Collections.unmodifiableList(actions);
|
|
|
+ this.executor = executor;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -54,20 +54,6 @@ public class DefaultFirewallProcessor implements FirewallProcessor {
|
|
|
return this.sequenceGenerator.next();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理规则动作
|
|
|
- *
|
|
|
- * @param principal 主体信息
|
|
|
- * @param rule 匹配规则
|
|
|
- */
|
|
|
- private void doAction(String principal, Rule rule) {
|
|
|
- for (Action action : this.actions) {
|
|
|
- if (Objects.equals(rule.getAction(), action.getName())) {
|
|
|
- action.execute(principal, rule);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取匹配规则
|
|
|
*
|
|
@@ -180,7 +166,7 @@ public class DefaultFirewallProcessor implements FirewallProcessor {
|
|
|
if (pair.getValue().getCount() > 0) {
|
|
|
return false;
|
|
|
}
|
|
|
- this.doAction(pair.getKey(), pair.getValue());
|
|
|
+ this.executor.execute(pair.getKey(), pair.getValue());
|
|
|
return true;
|
|
|
});
|
|
|
}
|
|
@@ -200,7 +186,7 @@ public class DefaultFirewallProcessor implements FirewallProcessor {
|
|
|
for (int i = 0, size = actions.size(); i < size && iterator.hasNext(); i++) {
|
|
|
Pair<String, Rule> pair = iterator.next();
|
|
|
if (StringUtils.notEmpty(actions.get(i++))) {
|
|
|
- this.doAction(pair.getKey(), pair.getValue());
|
|
|
+ this.executor.execute(pair.getKey(), pair.getValue());
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|