Search in sources :

Example 11 with DNSEntryForm

use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.

the class MainController method search.

/**
	 * Execute the search and return the results
	 */
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView search(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath, @RequestParam(value = "domainName", required = false) String searchDomainName, @RequestParam(value = "status", required = false) EntityStatus searchStatus) {
    log.error("Hit Search Controller");
    if (log.isDebugEnabled()) {
        log.debug("Enter search");
    }
    String message = "Search complete";
    ModelAndView mav = new ModelAndView();
    if (actionPath.equalsIgnoreCase("gotosettings") || actionPath.equalsIgnoreCase("settings")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the settings page");
        }
        String action = "add";
        model.addAttribute("action", action);
        // Set view for this method
        mav.setViewName("settings");
        mav.addObject("actionPath", "gotosettings");
        // Initialize default settings form 
        SettingsForm form = (SettingsForm) session.getAttribute("settingsForm");
        if (form == null) {
            form = new SettingsForm();
        }
        model.addAttribute("settingsForm", form);
        // Retrieve list of settings for settingsResults
        List<Setting> results = null;
        if (settingsService != null) {
            try {
                final Collection<Setting> settings = settingsService.getSettings();
                if (settings != null) {
                    results = new ArrayList<Setting>(settings);
                } else {
                    results = new ArrayList<Setting>();
                }
            } catch (ServiceException e) {
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("settingsResults", results);
    } else if (actionPath.equalsIgnoreCase("gotocertificates") || actionPath.equalsIgnoreCase("certificates")) {
        /*************************************
                 * Manage Certificates
                 * 
                 *************************************/
        //if (log.isDebugEnabled()) {
        log.error("trying to go to the certificates page");
        //}
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("certificates");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("actionPath", "gotocertificates");
        CertificateForm form = (CertificateForm) session.getAttribute("certificateForm");
        if (form == null) {
            form = new CertificateForm();
        }
        model.addAttribute("certificateForm", form);
        // retrieve list of settings for settingsResults
        List<Certificate> results = null;
        if (certService != null) {
            try {
                final Collection<Certificate> certs = certService.getAllCertificates();
                if (certs != null) {
                    if (this.keyManager != null && this.keyManager instanceof MutableKeyStoreProtectionManager) {
                        final KeyStore keyStore = ((MutableKeyStoreProtectionManager) keyManager).getKS();
                        // the key store manager to see if they have private keys
                        for (Certificate cert : certs) {
                            if (!cert.isPrivateKey()) {
                                try {
                                    final X509Certificate checkCert = CertUtils.toX509Certificate(cert.getData());
                                    final String alias = keyStore.getCertificateAlias(checkCert);
                                    if (!StringUtils.isEmpty(alias)) {
                                        // check if this entry has a private key associated with
                                        // it
                                        final PrivateKey privKey = (PrivateKey) keyStore.getKey(alias, "".toCharArray());
                                        if (privKey != null)
                                            cert.setPrivateKey(true);
                                    }
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                    results = new ArrayList<Certificate>(certs);
                } else {
                    results = new ArrayList<Certificate>();
                }
            } catch (ServiceException e) {
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("certificatesResults", results);
    } else if (actionPath.equalsIgnoreCase("newdomain") || actionPath.equalsIgnoreCase("new domain")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the new domain page");
        }
        final HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        model.addAttribute("simpleForm", new SimpleForm());
        final AddressForm addrform = new AddressForm();
        addrform.setId(0L);
        model.addAttribute("addressForm", addrform);
        // TODO: once certificates and anchors are available change code accordingly
        final CertificateForm cform = new CertificateForm();
        //cform.setId(0L);
        final AnchorForm aform = new AnchorForm();
        aform.setId(0L);
        model.addAttribute("certificateForm", cform);
        model.addAttribute("anchorForm", aform);
        final String action = "Add";
        DomainForm form = (DomainForm) session.getAttribute("domainForm");
        if (form == null) {
            form = new DomainForm();
        }
        model.addAttribute("domainForm", form);
        model.addAttribute("action", action);
        mav.setViewName("domain");
        mav.addObject("actionPath", "newdomain");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
    } else if (actionPath.equalsIgnoreCase("gotodns") || actionPath.equalsIgnoreCase("DNS Entries")) {
        if (log.isDebugEnabled()) {
            log.debug("Entering DNS Management page");
        }
        final HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        final String action = "Update";
        model.addAttribute("action", action);
        // get all DNSType.A.getValue() records
        // GET A RECORDS
        Collection<DNSRecord> arecords = null;
        arecords = getDnsRecords(DNSType.A.getValue());
        model.addAttribute("dnsARecordResults", arecords);
        // GET A4 RECORDS
        Collection<DNSRecord> a4records = null;
        a4records = getDnsRecords(DNSType.AAAA.getValue());
        model.addAttribute("dnsA4RecordResults", a4records);
        // GET C RECORDS
        Collection<DNSRecord> crecords = null;
        crecords = getDnsRecords(DNSType.CNAME.getValue());
        model.addAttribute("dnsCnameRecordResults", crecords);
        // GET Cert RECORDS
        Collection<DNSRecord> certrecords = null;
        certrecords = getDnsRecords(DNSType.CERT.getValue());
        model.addAttribute("dnsCertRecordResults", certrecords);
        // GET MX RECORDS
        Collection<DNSRecord> mxrecords = null;
        mxrecords = getDnsRecords(DNSType.MX.getValue());
        model.addAttribute("dnsMxRecordResults", mxrecords);
        // GET SRV RECORDS
        Collection<DNSRecord> srvrecords = null;
        srvrecords = getDnsRecords(DNSType.SRV.getValue());
        model.addAttribute("dnsSrvRecordResults", srvrecords);
        mav.setViewName("dns");
        mav.addObject("actionPath", "gotodns");
        model.addAttribute("AdnsForm", new DNSEntryForm());
        model.addAttribute("AAdnsForm", new DNSEntryForm());
        model.addAttribute("CdnsForm", new DNSEntryForm());
        model.addAttribute("CertdnsForm", new DNSEntryForm());
        model.addAttribute("MXdnsForm", new DNSEntryForm());
        model.addAttribute("SrvdnsForm", new DNSEntryForm());
        refreshModelFromService(model);
        model.addAttribute("simpleForm", new SimpleForm());
    } else if (actionPath.equalsIgnoreCase("ManagePolicies") || actionPath.equalsIgnoreCase("Policies")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the Policies page");
        }
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("policies");
        mav.addObject("actionPath", "gotopolicies");
        PolicyForm form = (PolicyForm) session.getAttribute("policyForm");
        if (form == null) {
            form = new PolicyForm();
        }
        model.addAttribute("policyForm", form);
        Collection<CertPolicy> policies = null;
        try {
            policies = policyService.getPolicies();
        } catch (Exception e) {
            System.out.println("Failed to lookup policies: " + e.getMessage());
        }
        if (policies != null) {
            model.addAttribute("policies", policies);
        } else {
            model.addAttribute("policies", "");
        }
        /*
                // retrieve list of settings for settingsResults
                List<Certificate> results = null;
                if (configSvc != null) {
                    // Process data for Trust Bundle View
                    try {

                        // Get Trust Bundles
                        Collection<TrustBundle> trustBundles = configSvc.getTrustBundles(true); 
                        
                        if (trustBundles == null)
                        	trustBundles = Collections.emptyList();
                        
                        Map<String, Object> bundleMap = new HashMap<String, Object>(trustBundles.size());                                                                                                            
                                    
                        Collection<TrustBundleAnchor> tbAnchors;    // Store anchors for each bundle   



                        for(TrustBundle bundle : trustBundles) 
                        {                                        
                            tbAnchors = bundle.getTrustBundleAnchors();    
                            Map<TrustBundleAnchor, String> anchorMap = new HashMap<TrustBundleAnchor, String>(tbAnchors.size());                                                                                

                            //String[] anchorDNs = new String[tbAnchors.size()];  // String array for storing anchor DNs
                            int curAnchor = 0;  // Counter as we iterate through anchor list

                            // Loop through anchors to collect some information about the certificates
                            for(TrustBundleAnchor anchor : tbAnchors) {

                                try {
                                    X509Certificate cert = anchor.toCertificate();                                            

                                    String subjectDN = cert.getSubjectDN().toString();
                                    anchorMap.put(anchor, subjectDN);

                                } catch (org.nhindirect.config.store.CertificateException ex) {                                                
                                }

                                curAnchor++;
                            }

                            bundleMap.put(bundle.getBundleName(), anchorMap);

                        }

                        model.addAttribute("bundleMap", bundleMap);  
                        
                        
                        
                        model.addAttribute("trustBundles", trustBundles);                                

                    } catch (ConfigurationServiceException e1) {
                            e1.printStackTrace();
                    }								
                }
                */
        model.addAttribute("simpleForm", new SimpleForm());
    } else if (actionPath.equalsIgnoreCase("ManageTrustBundles") || actionPath.equalsIgnoreCase("Bundles")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the Bundles page");
        }
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("bundles");
        mav.addObject("actionPath", "gotobundles");
        BundleForm form = (BundleForm) session.getAttribute("BundleForm");
        if (form == null) {
            form = new BundleForm();
        }
        model.addAttribute("bundleForm", form);
        // retrieve list of settings for settingsResults
        if (bundleService != null) {
            // Process data for Trust Bundle View
            try {
                // Get Trust Bundles
                Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(true);
                if (trustBundles == null) {
                    trustBundles = Collections.emptyList();
                }
                final Map<String, Object> bundleMap = new HashMap<String, Object>(trustBundles.size());
                // Store anchors for each bundle   
                Collection<TrustBundleAnchor> tbAnchors;
                for (TrustBundle bundle : trustBundles) {
                    tbAnchors = bundle.getTrustBundleAnchors();
                    final Map<TrustBundleAnchor, String> anchorMap = new HashMap<TrustBundleAnchor, String>(tbAnchors.size());
                    // Loop through anchors to collect some information about the certificates
                    for (TrustBundleAnchor anchor : tbAnchors) {
                        final X509Certificate cert = anchor.getAsX509Certificate();
                        final String subjectDN = cert.getSubjectDN().toString();
                        anchorMap.put(anchor, subjectDN);
                    }
                    bundleMap.put(bundle.getBundleName(), anchorMap);
                }
                model.addAttribute("bundleMap", bundleMap);
                model.addAttribute("trustBundles", trustBundles);
            } catch (ServiceException e1) {
                e1.printStackTrace();
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
    } else {
        SearchDomainForm form = (SearchDomainForm) session.getAttribute("searchDomainForm");
        if (form == null) {
            form = new SearchDomainForm();
        }
        model.addAttribute(form);
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        final String domain = (!searchDomainName.isEmpty()) ? searchDomainName : "%";
        mav.addObject("searchTerm", searchDomainName);
        EntityStatus status = searchStatus;
        List<Domain> results = null;
        if (domainService != null) {
            try {
                final Collection<Domain> domains = domainService.searchDomains(domain, org.nhindirect.config.model.EntityStatus.valueOf(status.toString()));
                if (domains != null) {
                    results = new ArrayList<Domain>(domains);
                } else {
                    results = new ArrayList<Domain>();
                }
            } catch (ServiceException e1) {
                e1.printStackTrace();
            }
        }
        if (AjaxUtils.isAjaxRequest(requestedWith)) {
            // prepare model for rendering success message in this request
            model.addAttribute("message", new Message(MessageType.success, message));
            model.addAttribute("ajaxRequest", true);
            model.addAttribute("searchResults", results);
            return null;
        }
        mav.setViewName("main");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
        mav.addObject("searchResults", results);
    }
    if (log.isDebugEnabled()) {
        log.debug("Exit");
    }
    return mav;
}
Also used : SimpleForm(org.nhindirect.config.ui.form.SimpleForm) CertificateForm(org.nhindirect.config.ui.form.CertificateForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) PrivateKey(java.security.PrivateKey) Message(org.nhindirect.config.ui.flash.FlashMap.Message) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) MutableKeyStoreProtectionManager(org.nhindirect.common.crypto.MutableKeyStoreProtectionManager) TrustBundle(org.nhindirect.config.model.TrustBundle) EntityStatus(org.nhindirect.config.store.EntityStatus) List(java.util.List) ArrayList(java.util.ArrayList) BundleForm(org.nhindirect.config.ui.form.BundleForm) Setting(org.nhindirect.config.model.Setting) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextParseException(org.xbill.DNS.TextParseException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) PolicyForm(org.nhindirect.config.ui.form.PolicyForm) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) CertPolicy(org.nhindirect.config.model.CertPolicy) SettingsForm(org.nhindirect.config.ui.form.SettingsForm) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.model.Certificate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with DNSEntryForm

use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.

the class DNSController method addCertSetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addCertDNSRecord", method = RequestMethod.POST)
public ModelAndView addCertSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // CERT records
    if (CertdnsForm != null && !CertdnsForm.getName().equalsIgnoreCase("") && CertdnsForm.getTtl() != 0L) {
        X509Certificate tcert = null;
        byte[] certbytes = null;
        try {
            if (!CertdnsForm.getFileData().isEmpty()) {
                byte[] bytes = CertdnsForm.getFileData().getBytes();
                certbytes = bytes;
                if (bytes != null) {
                    // get the owner from the certificate information
                    // first transform into a certificate
                    final CertContainer cont = toCertContainer(bytes);
                    if (cont != null && cont.getCert() != null) {
                        final Certificate cert2 = new Certificate();
                        cert2.setData(bytes);
                        tcert = cont.getCert();
                    }
                }
            }
        } catch (ConfigurationServiceException ed) {
            if (log.isDebugEnabled())
                log.error(ed);
        } catch (Exception e) {
            if (log.isDebugEnabled())
                log.error(e.getMessage());
            e.printStackTrace();
        }
        CertdnsForm.setType("CERT");
        CertdnsForm.setCertificate(tcert);
        CertdnsForm.setCertificateData(certbytes);
        try {
            dnsService.addDNSRecord(DNSEntryForm.createCertRecord(CertdnsForm));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) X509Certificate(java.security.cert.X509Certificate) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextParseException(org.xbill.DNS.TextParseException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.model.Certificate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with DNSEntryForm

use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.

the class DNSController method addCNAMESetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addCNAMEDNSRecord", method = RequestMethod.POST)
public ModelAndView addCNAMESetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (CdnsForm != null && !CdnsForm.getName().equalsIgnoreCase("") && CdnsForm.getTtl() != 0L && !CdnsForm.getDest().equalsIgnoreCase("")) {
        try {
            dnsService.addDNSRecord(DNSEntryForm.toDNSRecord(CdnsForm));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with DNSEntryForm

use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.

the class DNSController method removeAnchors.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removesettings", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @ModelAttribute("AdnsForm") DNSEntryForm AdnsForm, @ModelAttribute("NSdnsForm") DNSEntryForm NSdnsForm, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, HttpSession session, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter domain/removesettings");
    // A records
    try {
        Collection<DNSRecord> arecords = null;
        if (dnsService != null && AdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected As")) && AdnsForm.getRemove() != null) {
            int cnt = AdnsForm.getRemove().size();
            arecords = dnsService.getDNSRecord(DNSType.A.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // A4 records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && AAdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteA4DnsEntries") || actionPath.equalsIgnoreCase("Remove Selected A4s")) && AAdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.AAAA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AAdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CNAME records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCNAMEDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CNAMEs")) && CdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CNAME.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // MX records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && MXdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteMXDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected MXs")) && MXdnsForm.getRemove() != null) {
            int cnt = MXdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.MX.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = MXdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CERT records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CertdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCERTDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CERTs")) && CertdnsForm.getRemove() != null) {
            int cnt = CertdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CERT.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CertdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SRV records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && SrvdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSRVDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SRVs")) && SrvdnsForm.getRemove() != null) {
            int cnt = SrvdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.SRV.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SrvdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SOA records
    try {
        Collection<DNSRecord> soarecords = null;
        if (dnsService != null && SoadnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSOADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SOAs")) && SoadnsForm.getRemove() != null) {
            int cnt = SoadnsForm.getRemove().size();
            soarecords = dnsService.getDNSRecord(DNSType.SOA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SoadnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // NS records
    try {
        Collection<DNSRecord> nsrecords = null;
        if (dnsService != null && NSdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteNSDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected NSs")) && NSdnsForm.getRemove() != null) {
            int cnt = NSdnsForm.getRemove().size();
            nsrecords = dnsService.getDNSRecord(DNSType.NS.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = NSdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // additional post clean up to redisplay
    ModelAndView mav = new ModelAndView("dns");
    if (AdnsForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + AdnsForm.getRemove().toString());
    }
    /*
		 * if (configSvc != null && simpleForm != null && actionPath != null &&
		 * actionPath.equalsIgnoreCase("delete") && simpleForm.getRemove() !=
		 * null) { int cnt = simpleForm.getRemove().size(); try{
		 * Collection<String> settingstoberemovedlist = simpleForm.getRemove();
		 * if (log.isDebugEnabled())
		 * log.debug(" Trying to remove settings from database");
		 * configSvc.deleteSetting(settingstoberemovedlist); if
		 * (log.isDebugEnabled())
		 * log.debug(" SUCCESS Trying to remove settings"); } catch
		 * (ConfigurationServiceException e) { if (log.isDebugEnabled())
		 * log.error(e); } }
		 */
    refreshModelFromService(model);
    model.addAttribute("dnsEntryForm", new DNSEntryForm());
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with DNSEntryForm

use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.

the class DNSController method addSRVSetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addSRVDNSRecord", method = RequestMethod.POST)
public ModelAndView addSRVSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (SrvdnsForm != null && !SrvdnsForm.getName().equalsIgnoreCase("") && SrvdnsForm.getTtl() != 0L && !SrvdnsForm.getDest().equalsIgnoreCase("")) {
        final DNSRecord rec = DNSEntryForm.entityToModelRecord(DNSRecordUtils.createSRVRecord("_" + SrvdnsForm.getService() + "._" + SrvdnsForm.getProtocol() + "." + SrvdnsForm.getName(), SrvdnsForm.getDest(), SrvdnsForm.getTtl(), SrvdnsForm.getPort(), SrvdnsForm.getPriority(), SrvdnsForm.getWeight()));
        try {
            dnsService.addDNSRecord(rec);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    mav.setViewName("dns");
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)16 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ModelAndView (org.springframework.web.servlet.ModelAndView)10 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)9 ArrayList (java.util.ArrayList)7 TextParseException (org.xbill.DNS.TextParseException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 X509Certificate (java.security.cert.X509Certificate)5 CertificateEncodingException (javax.security.cert.CertificateEncodingException)5 IOException (java.io.IOException)4 Certificate (org.nhindirect.config.model.Certificate)4 DNSRecord (org.nhindirect.config.model.DNSRecord)4 DNSRecord (org.nhindirect.config.store.DNSRecord)4 NSRecord (org.xbill.DNS.NSRecord)3 SOARecord (org.xbill.DNS.SOARecord)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2