@Override public Result evaluate(Environment environment) { Result subroutineResult = new Result(); // By default move on to the next policy subroutineResult.setFallThrough(true); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { // Reached an exit/terminal action. Return regardless of boolean value return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { // Found first match that returns false, short-circuit here subroutineResult.setReturn(false); return subroutineResult; } } // Check if we are allowed to fall through to the default policy, if not, return last result if (!subroutineResult.getFallThrough()) { return subroutineResult; } else { String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); return callDefaultPolicy.evaluate(environment); } else { throw new BatfishException("Default policy is not set"); } } }
@Override public Result evaluate(Environment environment) { Result subroutineResult = new Result(); // By default move on to the next policy subroutineResult.setFallThrough(true); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { // Reached an exit/terminal action. Return regardless of boolean value return subroutineResult; } else if (!subroutineResult.getFallThrough() && subroutineResult.getBooleanValue()) { // Matched the route, first match that returns true lets us short-circuit subroutineResult.setReturn(true); return subroutineResult; } } // Check if we are allowed to fall through to the default policy, if not, return last result if (!subroutineResult.getFallThrough()) { return subroutineResult; } else { String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); return callDefaultPolicy.evaluate(environment); } else { throw new BatfishException("Default policy is not set"); } } }