Package java.lang

Examples of java.lang.String$ConsolePrintStream


    private boolean manageApplication(SecurityPolicyType type, SrxCommand command, Protocol protocol, int startPort, int endPort) throws ExecutionException {
        if (protocol.equals(Protocol.any)) {
            return true;
        }

        String applicationName = genApplicationName(type, protocol, startPort, endPort);
        String xml;

        switch (command) {

        case CHECK_IF_EXISTS:
            xml = SrxXml.APPLICATION_GETONE.getXml();
            xml = setDelete(xml, false);
            xml = replaceXmlValue(xml, "name", applicationName);
            return sendRequestAndCheckResponse(command, xml, "name", applicationName);

        case ADD:
            if (manageApplication(type, SrxCommand.CHECK_IF_EXISTS, protocol, startPort, endPort)) {
                return true;
            }
            String icmpOrDestPort;
            xml = SrxXml.APPLICATION_ADD.getXml();
            xml = replaceXmlValue(xml, "name", applicationName);
            xml = replaceXmlValue(xml, "protocol", protocol.toString());
            if (protocol.toString() == Protocol.icmp.toString()) {
                icmpOrDestPort = "<icmp-type>" + startPort + "</icmp-type>";
                icmpOrDestPort += "<icmp-code>" + endPort + "</icmp-code>";
            } else {
                String destPort;

                if (startPort == endPort) {
                    destPort = String.valueOf(startPort);
                } else {
                    destPort = startPort + "-" + endPort;
View Full Code Here


    private List<String> getUnusedApplications(List<String> applications, String fromZone, String toZone) throws ExecutionException {
        List<String> unusedApplications = new ArrayList<String>();

        // Check if any of the applications are unused by existing security policies
        String xml = SrxXml.SECURITY_POLICY_GETALL.getXml();
        xml = replaceXmlValue(xml, "from-zone", fromZone);
        xml = replaceXmlValue(xml, "to-zone", toZone);
        String allPolicies = sendRequest(xml);

        for (String application : applications) {
            if (!application.equals(Protocol.any.toString()) && !allPolicies.contains(application)) {
                unusedApplications.add(application);
            }
        }

        return unusedApplications;
View Full Code Here

        }

        return unusedApplications;
    }
    private List<String> getApplicationsForSecurityPolicy(SecurityPolicyType type, String privateIp, String fromZone, String toZone) throws ExecutionException {
        String policyName = genSecurityPolicyName(type, null, null, fromZone, toZone, privateIp);
        String xml = SrxXml.SECURITY_POLICY_GETONE.getXml();
        xml = setDelete(xml, false);
        xml = replaceXmlValue(xml, "from-zone", fromZone);
        xml = replaceXmlValue(xml, "to-zone", toZone);
        xml = replaceXmlValue(xml, "policy-name", policyName);
        String policy = sendRequest(xml);

        Document doc = getDocument(policy);

        List<String> policyApplications = new ArrayList<String>();
        NodeList applicationNodes = doc.getElementsByTagName("application");
View Full Code Here

          return genObjectName(type.getIdentifier(), fromZone, toZone, genIpIdentifier(translatedIp));
        }           
    }

    private boolean manageSecurityPolicy(SecurityPolicyType type, SrxCommand command, Long accountId, String username, String privateIp, List<String> applicationNames, List<String> cidrs, String ipsecVpnName, boolean defaultEgressAction) throws ExecutionException {
        String fromZone = _publicZone;
        String toZone = _privateZone;
       
        String securityPolicyName;
        String addressBookEntryName = null;

        if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
            securityPolicyName = ipsecVpnName;
            addressBookEntryName = ipsecVpnName;
        } else if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
            fromZone = _privateZone;
            toZone = _publicZone;
            securityPolicyName = genSecurityPolicyName(type, accountId, username, fromZone, toZone, privateIp);
        } else {
          securityPolicyName = genSecurityPolicyName(type, accountId, username, fromZone, toZone, privateIp);
            addressBookEntryName = genAddressBookEntryName(privateIp);
        }       

        String xml;

        switch (command) {

        case CHECK_IF_EXISTS:
            xml = SrxXml.SECURITY_POLICY_GETONE.getXml();
            xml = setDelete(xml, false);
            xml = replaceXmlValue(xml, "from-zone", fromZone);
            xml = replaceXmlValue(xml, "to-zone", toZone);
            xml = replaceXmlValue(xml, "policy-name", securityPolicyName);
           
            return sendRequestAndCheckResponse(command, xml, "name", securityPolicyName);

        case CHECK_IF_IN_USE:
            List<String[]> rulesToCheck = null;
            if (type.equals(SecurityPolicyType.STATIC_NAT)) {
                // Check if any static NAT rules rely on this security policy
                rulesToCheck = getStaticNatRules(RuleMatchCondition.ALL, null, null);
            } else if (type.equals(SecurityPolicyType.DESTINATION_NAT)) {
                // Check if any destination NAT rules rely on this security policy
                rulesToCheck = getDestNatRules(RuleMatchCondition.ALL, null, null, null, null);
            } else {
                return false;
            }         

            for (String[] rule : rulesToCheck) {
                String rulePrivateIp = rule[1];
                if (privateIp.equals(rulePrivateIp)) {
                    return true;
                }
            }

            return false;

        case ADD:
            if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT))) {
                if (!manageAddressBookEntry(SrxCommand.CHECK_IF_EXISTS, toZone, privateIp, addressBookEntryName)) {
                    throw new ExecutionException("No address book entry for policy: " + securityPolicyName);
                }
            }

            String srcAddrs = "";
            String dstAddrs = "";
            String action = "";
            xml = SrxXml.SECURITY_POLICY_ADD.getXml();
            xml = replaceXmlValue(xml, "policy-name", securityPolicyName);
            if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
                xml = replaceXmlValue(xml, "from-zone", _privateZone);
                xml = replaceXmlValue(xml, "to-zone", _publicZone);
                if (cidrs == null) {
                    srcAddrs = "<source-address>any</source-address>";
                } else {
                    for (String cidr : cidrs) {
                        srcAddrs += "<source-address>" + genAddressBookEntryName(cidr) + "</source-address>";
                    }
                }
                xml = replaceXmlValue(xml, "src-address", srcAddrs);
                dstAddrs = "<destination-address>any</destination-address>";
                xml = replaceXmlValue(xml, "dst-address", dstAddrs);
                if (defaultEgressAction == true) {
                    //configure block rules and default allow the traffic
                    action = "<deny></deny>";
                } else {
                    action = "<permit></permit>";
                }
                xml = replaceXmlValue(xml, "action", action);
            } else {
                xml = replaceXmlValue(xml, "from-zone", fromZone);
                xml = replaceXmlValue(xml, "to-zone", toZone);
                srcAddrs = "<source-address>any</source-address>";
                xml = replaceXmlValue(xml, "src-address", srcAddrs);
                dstAddrs = "<destination-address>" + addressBookEntryName + "</destination-address>";
                xml = replaceXmlValue(xml, "dst-address", dstAddrs);
            }

            if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
                xml = replaceXmlValue(xml, "tunnel", "<permit><tunnel><ipsec-vpn>" + ipsecVpnName + "</ipsec-vpn></tunnel></permit>");
            } else {       
              xml = replaceXmlValue(xml, "tunnel", "");
                if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS))) {
                    action = "<permit></permit>";
                    xml = replaceXmlValue(xml, "action", action);
                }
            }
                       
            String applications;
            if (applicationNames == null || applicationNames.size() == 0) {
              applications = "<application>any</application>";
            } else {
              applications = "";
              for (String applicationName : applicationNames) {
                    applications += "<application>" + applicationName + "</application>";
                }
            }          

            xml = replaceXmlValue(xml, "applications", applications);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add security policy for privateIp " + privateIp + " and applications " + applicationNames);
            } else {
                return true;
            }

        case DELETE:
            if (!manageSecurityPolicy(type, SrxCommand.CHECK_IF_EXISTS, null, null, privateIp, applicationNames, cidrs, ipsecVpnName, defaultEgressAction)) {
                return true;
            }

            if (manageSecurityPolicy(type, SrxCommand.CHECK_IF_IN_USE, null, null, privateIp, applicationNames, cidrs, ipsecVpnName, defaultEgressAction)) {
                return true;
            }

            xml = SrxXml.SECURITY_POLICY_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "from-zone", fromZone);
            xml = replaceXmlValue(xml, "to-zone", toZone);
            xml = replaceXmlValue(xml, "policy-name", securityPolicyName);
           
            boolean success = sendRequestAndCheckResponse(command, xml);

            if (success) {
                xml = SrxXml.SECURITY_POLICY_GETALL.getXml();
                xml = replaceXmlValue(xml, "from-zone", fromZone);
                xml = replaceXmlValue(xml, "to-zone", toZone);
                String getAllResponseXml = sendRequest(xml);

                if (getAllResponseXml == null) {
                    throw new ExecutionException("Deleted security policy, but failed to delete security policy group.");
                }
               
                if (!getAllResponseXml.contains(fromZone) || !getAllResponseXml.contains(toZone)) {
                    return true;
                } else if (!getAllResponseXml.contains("match") && !getAllResponseXml.contains("then")) {
                    xml = SrxXml.SECURITY_POLICY_GROUP.getXml();
                    xml = replaceXmlValue(xml, "from-zone", fromZone);
                    xml = replaceXmlValue(xml, "to-zone", toZone);
                    xml = setDelete(xml, true);
                    if (!sendRequestAndCheckResponse(command, xml)) {
View Full Code Here

        for (Object[] application : applications) {        
            Protocol protocol = (Protocol) application[0];
            int startPort = application[1] != null ? ((Integer) application[1]) : -1;
            int endPort = application[2] != null ? ((Integer) application[2]) : -1;

            String applicationName = genApplicationName(type, protocol, startPort, endPort);
            if (!applicationNames.contains(applicationName)) {
                applicationNames.add(applicationName);
            }

            manageApplication(type, SrxCommand.ADD, protocol, startPort, endPort);
View Full Code Here

            Protocol protocol = (Protocol) application[0];
            if (!protocol.equals(Protocol.all)) {
                int startPort = application[1] != null ? ((Integer) application[1]) : 0;
                int endPort = application[2] != null ? ((Integer) application[2]) : 65535;

                String applicationName = genApplicationName(type, protocol, startPort, endPort);
                if (!applicationNames.contains(applicationName)) {
                    applicationNames.add(applicationName);
                }
                manageApplication(type, SrxCommand.ADD, protocol, startPort, endPort);
            }
View Full Code Here

    private String genIpFilterTermName(String ipAddress) {
        return genIpIdentifier(ipAddress);
    }

    private boolean manageUsageFilter(SrxCommand command, UsageFilter filter, String ip, Long guestVlanTag, String filterTermName) throws ExecutionException {           
        String filterName;
        String filterDescription;
        String xml;

        if (filter.equals(_usageFilterIPInput) || filter.equals(_usageFilterIPOutput)) {
            assert (ip != null && guestVlanTag == null);         
            filterName = filter.getName();
            filterDescription = filter.toString() + ", public IP = " + ip;
View Full Code Here

        }
    } 

    private String genNameValueEntry(String name, String value) {
        String xml = SrxXml.TEMPLATE_ENTRY.getXml();
        xml = replaceXmlValue(xml, "name", name);
        xml = replaceXmlValue(xml, "value", value);
        return xml;
    }
View Full Code Here

        xml = replaceXmlValue(xml, "value", value);
        return xml;
    }
   
    private String genMultipleEntries(String name, List<String> values) {
        String result = "";
        for (String value : values) {
            result = result + genNameValueEntry(name, value);
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }
   
    private String genPortRangeEntry(String protocol, String portRange) {
        String result = "";
        result = result + genNameValueEntry("protocol", protocol);
        result = result + genNameValueEntry("destination-port", portRange);
        return result;
    }
View Full Code Here

TOP

Related Classes of java.lang.String$ConsolePrintStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.