@Override public void enterS_access_line(S_access_lineContext ctx) { String name = ctx.linetype.getText(); _configuration.getCf().getLines().computeIfAbsent(name, Line::new); }
@Override public void exitL_transport(L_transportContext ctx) { SortedSet<String> protocols = ctx.prot.stream().map(RuleContext::getText).collect(toCollection(TreeSet::new)); BiConsumer<Line, SortedSet<String>> setter; if (ctx.INPUT() != null) { setter = Line::setTransportInput; } else if (ctx.OUTPUT() != null) { setter = Line::setTransportOutput; } else if (ctx.PREFERRED() != null) { setter = Line::setTransportPreferred; } else { throw new BatfishException("Invalid or unsupported line transport type"); } for (String currentName : _currentLineNames) { Line line = _configuration.getCf().getLines().get(currentName); setter.accept(line, protocols); } }
@Override public void exitL_exec_timeout(L_exec_timeoutContext ctx) { int minutes = toInteger(ctx.minutes); int seconds = ctx.seconds != null ? toInteger(ctx.seconds) : 0; for (String lineName : _currentLineNames) { Line line = _configuration.getCf().getLines().get(lineName); line.setExecTimeoutMinutes(minutes); line.setExecTimeoutSeconds(seconds); } }
@Override public void exitL_login_authentication(L_login_authenticationContext ctx) { String list; if (ctx.DEFAULT() != null) { list = ctx.DEFAULT().getText(); } else if (ctx.name != null) { list = ctx.name.getText(); } else { throw new BatfishException("Invalid list name"); } // get the authentication list or null if Aaa, AaaAuthentication, or AaaAuthenticationLogin is // null or the list is not defined AaaAuthenticationLoginList authList = Optional.ofNullable(_configuration.getCf().getAaa()) .map(Aaa::getAuthentication) .map(AaaAuthentication::getLogin) .map(AaaAuthenticationLogin::getLists) .map(lists -> lists.get(list)) .orElse(null); // if the authentication list has been defined, apply it to all lines in _currentLineNames for (String line : _currentLineNames) { if (authList != null) { _configuration.getCf().getLines().get(line).setAaaAuthenticationLoginList(authList); } // set the name of the login list even if the list hasn't been defined yet because it may be // defined later _configuration.getCf().getLines().get(line).setLoginAuthentication(list); } }
Line line = _configuration.getCf().getLines().get(currentName); setter.accept(line, name);
private void processLines() { // nxos does not have 'login authentication' for lines, so just have it // use default list if one exists if (_vendor == ConfigurationFormat.CISCO_NX && _cf.getAaa() != null && _cf.getAaa().getAuthentication() != null && _cf.getAaa().getAuthentication().getLogin() != null && _cf.getAaa() .getAuthentication() .getLogin() .getLists() .get(AaaAuthenticationLogin.DEFAULT_LIST_NAME) != null) { for (Line line : _cf.getLines().values()) { line.setLoginAuthentication(AaaAuthenticationLogin.DEFAULT_LIST_NAME); } } }
@Override public void enterCisco_configuration(Cisco_configurationContext ctx) { _configuration = new CiscoConfiguration(); _configuration.setVendor(_format); _currentVrf = Configuration.DEFAULT_VRF_NAME; if (_format == CISCO_IOS) { Logging logging = new Logging(); logging.setOn(true); _configuration.getCf().setLogging(logging); } else if (_format == CISCO_ASA) { // serial line may not be anywhere in the config so add it here to make sure the serial line // is in the data model _configuration.getCf().getLines().computeIfAbsent(SERIAL_LINE, Line::new); } }
@Override public void enterAaa_authentication_asa(Aaa_authentication_asaContext ctx) { if (_configuration.getCf().getAaa().getAuthentication().getLogin() == null) { _configuration.getCf().getAaa().getAuthentication().setLogin(new AaaAuthenticationLogin()); } ArrayList<AuthenticationMethod> methods = new ArrayList<>(); if (ctx.aaa_authentication_asa_console().group != null) { methods.add(AuthenticationMethod.GROUP_USER_DEFINED); } if (ctx.aaa_authentication_asa_console().LOCAL_ASA() != null) { methods.add(AuthenticationMethod.LOCAL_CASE); } if (!methods.isEmpty()) { AaaAuthenticationLogin login = _configuration.getCf().getAaa().getAuthentication().getLogin(); String name = ctx.linetype.getText(); AaaAuthenticationLoginList authList = new AaaAuthenticationLoginList(methods); _configuration .getCf() .getLines() .computeIfAbsent(name, Line::new) .setAaaAuthenticationLoginList(authList); // not allowed to specify multiple login lists for a given linetype so use computeIfAbsent // rather than put so we only accept the first login list _currentAaaAuthenticationLoginList = login.getLists().computeIfAbsent(name, k -> authList); } }
SortedMap<String, Line> lines = _configuration.getCf().getLines(); for (Line line : lines.values()) { if (name.equals(AaaAuthenticationLogin.DEFAULT_LIST_NAME)) {
@Override public TableAnswerElement answer() { AaaAuthenticationLoginQuestion question = (AaaAuthenticationLoginQuestion) _question; TableAnswerElement answerElement = create(question); Set<String> specifiedNodes = question.getNodes().getMatchingNodes(_batfish); SortedMap<String, Configuration> configs = _batfish.loadConfigurations(); configs.forEach( (configName, config) -> { if (specifiedNodes.contains(configName)) { Row row = null; if (config.getVendorFamily().getCisco() != null) { row = getRow(configName, config.getVendorFamily().getCisco().getLines().values()); } else if (config.getVendorFamily().getJuniper() != null) { row = getRow(configName, config.getVendorFamily().getJuniper().getLines().values()); } if (row != null) { answerElement.addRow(row); } } }); answerElement.setSummary(answerElement.computeSummary(question.getAssertion())); return answerElement; }
for (Line line : _cf.getLines().values()) { String list = line.getLoginAuthentication(); if (list == null) {