Search in sources :

Example 6 with CertificateForm

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

the class DomainController method addCertificate.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addcertificate", method = RequestMethod.POST)
public ModelAndView addCertificate(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute CertificateForm certificateForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    final ModelAndView mav = new ModelAndView();
    String strid = "";
    if (log.isDebugEnabled())
        log.debug("Enter domain/addcertificate");
    if (actionPath.equalsIgnoreCase("newcertificate") || actionPath.equalsIgnoreCase("add certificate")) {
        strid = "" + certificateForm.getId();
        Domain dom = null;
        try {
            dom = domainService.getDomain(strid);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        String owner = "";
        // insert the new address into the Domain list of Addresses
        if (log.isDebugEnabled())
            log.debug("beginning to evaluate filedata");
        try {
            if (!certificateForm.getFileData().isEmpty()) {
                final byte[] bytes = certificateForm.getFileData().getBytes();
                owner = certificateForm.getOwner();
                final Certificate cert = new Certificate();
                cert.setData(bytes);
                cert.setOwner(owner);
                cert.setStatus(certificateForm.getStatus());
                certService.addCertificate(cert);
                // store the bytes somewhere
                if (log.isDebugEnabled())
                    log.debug("store the certificate into database");
            } else {
                if (log.isDebugEnabled())
                    log.debug("DO NOT store the certificate into database BECAUSE THERE IS NO FILE");
            }
        } catch (ServiceException ed) {
            if (log.isDebugEnabled())
                log.error(ed);
        } catch (Exception e) {
            if (log.isDebugEnabled())
                log.error(e);
            e.printStackTrace();
        }
        // certificate and anchor forms and results
        try {
            final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
            model.addAttribute("certificatesResults", certs);
            final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
            final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
            // now set anchorsResults
            model.addAttribute("anchorsResults", convertedanchors);
            final CertificateForm cform = new CertificateForm();
            cform.setId(dom.getId());
            model.addAttribute("certificateForm", cform);
            final AnchorForm aform = new AnchorForm();
            aform.setId(dom.getId());
            model.addAttribute("anchorForm", aform);
        } catch (ServiceException e1) {
            e1.printStackTrace();
        }
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        final SimpleForm simple = new SimpleForm();
        simple.setId(Long.parseLong(strid));
        model.addAttribute("simpleForm", simple);
        model.addAttribute("addressesResults", dom.getAddresses());
        mav.setViewName("domain");
        // the Form's default button action
        final String action = "Update";
        DomainForm form = (DomainForm) session.getAttribute("domainForm");
        if (form == null) {
            form = new DomainForm();
            form.populate(dom);
        }
        model.addAttribute("domainForm", form);
        model.addAttribute("action", action);
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
    }
    final AddressForm addressForm2 = new AddressForm();
    addressForm2.setDisplayName("");
    addressForm2.setEndpoint("");
    addressForm2.setEmailAddress("");
    addressForm2.setType("");
    addressForm2.setId(Long.parseLong(strid));
    model.addAttribute("addressForm", addressForm2);
    return mav;
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) SimpleForm(org.nhindirect.config.ui.form.SimpleForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) ModelAndView(org.springframework.web.servlet.ModelAndView) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) Domain(org.nhindirect.config.model.Domain) 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 7 with CertificateForm

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

the class DomainController method removeCertificates.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removecertifcates", method = RequestMethod.POST)
public ModelAndView removeCertificates(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute CertificateForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled())
        log.debug("Enter domain/removecertificates");
    if (simpleForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
    }
    String strid = "" + simpleForm.getId();
    Domain dom = null;
    try {
        dom = domainService.getDomain(strid);
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    String owner = "";
    String domname = "";
    if (certService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deletecertificate") || actionPath.equalsIgnoreCase("remove selected")) && simpleForm.getRemove() != null) {
        int cnt = simpleForm.getRemove().size();
        if (log.isDebugEnabled())
            log.debug("removing certificates for domain with name: " + domname);
        try {
            // get list of certificates for this domain
            final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
            final ArrayList<Long> certtoberemovedlist = new ArrayList<Long>();
            // now iterate over each one and remove the appropriate ones
            for (int x = 0; x < cnt; x++) {
                String removeid = simpleForm.getRemove().get(x);
                for (Iterator<Certificate> iter = certs.iterator(); iter.hasNext(); ) {
                    Certificate t = (Certificate) iter.next();
                    //rest of the code block removed
                    if (t.getId() == Long.parseLong(removeid)) {
                        if (log.isDebugEnabled()) {
                            log.debug(" ");
                            log.debug("domain address id: " + t.getId());
                            log.debug(" ");
                        }
                        // create a collection of matching anchor ids
                        certtoberemovedlist.add(t.getId());
                        break;
                    }
                }
            }
            // with the collection of anchor ids now remove them from the configSvc
            if (log.isDebugEnabled())
                log.debug(" Trying to remove certificates from database");
            certService.deleteCertificatesByIds(certtoberemovedlist);
            if (log.isDebugEnabled())
                log.debug(" SUCCESS Trying to update the domain with removed certificates");
            final AddressForm addrform = new AddressForm();
            addrform.setId(dom.getId());
            model.addAttribute("addressForm", addrform);
        } catch (ServiceException e) {
            if (log.isDebugEnabled())
                log.error(e);
        }
    }
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    // BEGIN: temporary code for mocking purposes
    final CertificateForm cform = new CertificateForm();
    cform.setId(dom.getId());
    model.addAttribute("certificateForm", cform);
    final AnchorForm aform = new AnchorForm();
    aform.setId(dom.getId());
    model.addAttribute("anchorForm", aform);
    model.addAttribute("addressesResults", dom.getAddresses());
    mav.setViewName("domain");
    // the Form's default button action
    final String action = "Update";
    DomainForm form = (DomainForm) session.getAttribute("domainForm");
    if (form == null) {
        form = new DomainForm();
        form.populate(dom);
    }
    model.addAttribute("domainForm", form);
    model.addAttribute("action", action);
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    mav.addObject("action", action);
    // SETTING THE ADDRESSES OBJECT
    model.addAttribute("addressesResults", form.getAddresses());
    Collection<Certificate> certlist = null;
    try {
        certlist = certService.getCertificatesByOwner(owner);
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    Collection<Anchor> anchorlist = null;
    try {
        anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
    } catch (Exception e) {
        e.printStackTrace();
    }
    model.addAttribute("certificatesResults", certlist);
    // convert Anchor to AnchorForm
    Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
    // now set anchorsResults
    model.addAttribute("anchorsResults", convertedanchors);
    // END: temporary code for mocking purposes	
    mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
    mav.addObject("statusList", EntityStatus.getEntityStatusList());
    model.addAttribute("simpleForm", simpleForm);
    strid = "" + simpleForm.getId();
    if (log.isDebugEnabled())
        log.debug(" the value of id of simpleform is: " + strid);
    return mav;
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) Domain(org.nhindirect.config.model.Domain) 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 8 with CertificateForm

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

the class DomainController method addAddress.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addaddress", method = RequestMethod.POST)
public ModelAndView addAddress(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AddressForm addressForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    final String domAttr = (String) session.getAttribute("currentDomainName");
    ModelAndView mav = new ModelAndView();
    String strid = "";
    if (log.isDebugEnabled())
        log.debug("Enter domain/addaddress");
    Domain dom = null;
    if (actionPath.equalsIgnoreCase("newaddress") || actionPath.equalsIgnoreCase("add address")) {
        //addressForm.getId();
        strid = "" + domAttr;
        try {
            dom = domainService.getDomain(strid);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        String owner = dom.getDomainName();
        // insert the new address into the Domain list of Addresses
        final String anEmail = addressForm.getEmailAddress();
        final String displayname = addressForm.getDisplayName();
        final String endpoint = addressForm.getEndpoint();
        final EntityStatus estatus = addressForm.getaStatus();
        final String etype = addressForm.getType();
        if (log.isDebugEnabled())
            log.debug(" Trying to add address: " + anEmail);
        final Address e = new Address();
        e.setEmailAddress(anEmail);
        e.setDisplayName(displayname);
        e.setEndpoint(endpoint);
        e.setStatus(estatus);
        e.setType(etype);
        final List<Address> modAddrs = new ArrayList<Address>(dom.getAddresses());
        modAddrs.add(e);
        dom.setAddresses(modAddrs);
        try {
            domainService.updateDomain(dom);
            if (log.isDebugEnabled())
                log.debug(" After attempt to insert new email address ");
        } catch (ServiceException ed) {
            if (log.isDebugEnabled())
                log.error(ed);
        }
        // certificate and anchor forms and results
        try {
            final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
            model.addAttribute("certificatesResults", certs);
        } catch (ServiceException e1) {
        }
        try {
            final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
            // convert Anchor to AnchorForm
            final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
            // now set anchorsResults
            model.addAttribute("anchorsResults", convertedanchors);
        } catch (Exception e1) {
        }
        try {
            CertificateForm cform = new CertificateForm();
            cform.setId(dom.getId());
            model.addAttribute("certificateForm", cform);
            AnchorForm aform = new AnchorForm();
            aform.setId(dom.getId());
            model.addAttribute("anchorForm", aform);
        } catch (Exception e1x) {
        }
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        SimpleForm simple = new SimpleForm();
        //simple.setId(Long.parseLong(strid));
        simple.setDomainName(dom.getDomainName());
        model.addAttribute("simpleForm", simple);
        model.addAttribute("addressesResults", dom.getAddresses());
        mav.setViewName("domain");
        // the Form's default button action
        String action = "Update";
        DomainForm form = (DomainForm) session.getAttribute("domainForm");
        if (form == null) {
            form = new DomainForm();
            form.populate(dom);
        }
        model.addAttribute("domainForm", form);
        model.addAttribute("action", action);
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
    }
    AddressForm addressForm2 = new AddressForm();
    addressForm2.setDisplayName("");
    addressForm2.setEndpoint("");
    addressForm2.setEmailAddress("");
    addressForm2.setType("");
    //addressForm2.setId(Long.parseLong(strid));
    addressForm2.setDomainName(strid);
    model.addAttribute("addressForm", addressForm2);
    //return new ModelAndView("redirect:/config/domain?id="+dom.getDomainName()+"#tab1");
    return mav;
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) SimpleForm(org.nhindirect.config.ui.form.SimpleForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) Address(org.nhindirect.config.model.Address) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) EntityStatus(org.nhindirect.config.model.EntityStatus) Domain(org.nhindirect.config.model.Domain) 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 9 with CertificateForm

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

the class DomainController method viewDomain.

/**
     * Display a Domain
     */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView viewDomain(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @RequestParam(required = false) String domainName, HttpSession session, Model model) throws java.security.cert.CertificateException {
    if (log.isDebugEnabled()) {
        log.debug("Enter View Domain");
    }
    if (StringUtils.isEmpty(domainName))
        domainName = (String) session.getAttribute("currentDomainName");
    ModelAndView mav = new ModelAndView();
    mav.setViewName("domain");
    String action = "Add";
    DomainForm form = (DomainForm) session.getAttribute("domainForm");
    if (form == null) {
        form = new DomainForm();
    }
    model.addAttribute("domainForm", form);
    model.addAttribute("action", action);
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    mav.addObject("action", action);
    mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
    mav.addObject("statusList", EntityStatus.getEntityStatusList());
    session.setAttribute("currentDomainName", domainName);
    if ((domainName != null) && (domainName.length() > 0)) {
        if (log.isDebugEnabled()) {
            log.debug("Need to search for Domain ID: " + domainName);
        }
        Domain results = null;
        model.addAttribute("domainName", domainName);
        AddressForm addrform = new AddressForm();
        addrform.setDomainName(domainName);
        model.addAttribute("addressForm", addrform);
        final CertificateForm cform = new CertificateForm();
        cform.setDomainName(domainName);
        final AnchorForm aform = new AnchorForm();
        aform.setDomainName(domainName);
        model.addAttribute("certificateForm", cform);
        model.addAttribute("anchorForm", aform);
        if (domainService != null) {
            try {
                results = domainService.getDomain(domainName);
            } catch (ServiceException e) {
                e.printStackTrace();
            }
            if (results != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Found a valid domain" + results.toString());
                }
                Collection<TrustBundleDomainReltn> bundles = null;
                // Get Trust Bundles
                try {
                    bundles = bundleService.getTrustBundlesByDomain(domainName, true);
                } catch (ServiceException cse) {
                }
                if (bundles != null) {
                    model.addAttribute("trustBundles", bundles);
                    final Map<String, Object> bundleMap = new HashMap<String, Object>(bundles.size());
                    // Store anchors for each bundle   
                    Collection<TrustBundleAnchor> tbAnchors;
                    for (TrustBundleDomainReltn bundle : bundles) {
                        tbAnchors = bundle.getTrustBundle().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.getTrustBundle().getBundleName(), anchorMap);
                    }
                    model.addAttribute("bundleMap", bundleMap);
                }
                form.populate(results);
                action = "Update";
                model.addAttribute("action", action);
                // SETTING THE ADDRESSES OBJECT
                model.addAttribute("addressesResults", results.getAddresses());
                // BEGIN: temporary code for mocking purposes
                String owner = "";
                owner = results.getDomainName();
                model.addAttribute("addressesResults", results.getAddresses());
                Collection<Certificate> certlist = null;
                try {
                    certlist = certService.getCertificatesByOwner(owner);
                } catch (ServiceException e) {
                    e.printStackTrace();
                }
                Collection<Anchor> anchorlist = null;
                try {
                    anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
                } catch (ServiceException e) {
                    e.printStackTrace();
                }
                model.addAttribute("certificatesResults", certlist);
                // convert Anchor to AnchorForm
                final Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
                // now set anchorsResults
                model.addAttribute("anchorsResults", convertedanchors);
                // END: temporary code for mocking purposes			
                final SimpleForm simple = new SimpleForm();
                simple.setDomainName(domainName);
                model.addAttribute("simpleForm", simple);
                mav.addObject("action", action);
            } else {
                log.warn("Service returned a null Domain for a known key: " + domainName);
            }
        } else {
            log.error("Web Service bean is null.  Configuration error detected.");
        }
        if (AjaxUtils.isAjaxRequest(requestedWith)) {
            // prepare model for rendering success message in this request
            model.addAttribute("message", "");
            model.addAttribute("ajaxRequest", true);
            model.addAttribute("action", action);
            return null;
        }
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) SimpleForm(org.nhindirect.config.ui.form.SimpleForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) X509Certificate(java.security.cert.X509Certificate) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) TrustBundleDomainReltn(org.nhindirect.config.model.TrustBundleDomainReltn) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) Domain(org.nhindirect.config.model.Domain) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.model.Certificate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with CertificateForm

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

the class DomainController method removeAnchors.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeanchors", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    final ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled())
        log.debug("Enter domain/removeanchor");
    if (simpleForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
    }
    final String domAttr = (String) session.getAttribute("currentDomainName");
    //simpleForm.getId();
    String strid = "" + domAttr;
    Domain dom = null;
    try {
        dom = domainService.getDomain(strid);
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    String owner = "";
    String domname = "";
    if (dom != null) {
        domname = dom.getDomainName();
        owner = domname;
    }
    if (anchorService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteanchors") || actionPath.equalsIgnoreCase("Remove Selected Anchors")) && simpleForm.getRemove() != null) {
        int cnt = simpleForm.getRemove().size();
        if (log.isDebugEnabled())
            log.debug("removing anchors for domain with name: " + domname);
        try {
            // get list of certificates for this domain
            final Collection<Anchor> certs = anchorService.getAnchorsForOwner(owner, false, false, "");
            final ArrayList<Long> certtoberemovedlist = new ArrayList<Long>();
            // now iterate over each one and remove the appropriate ones
            for (int x = 0; x < cnt; x++) {
                String removeid = simpleForm.getRemove().get(x);
                for (Iterator<Anchor> iter = certs.iterator(); iter.hasNext(); ) {
                    Anchor t = (Anchor) iter.next();
                    //rest of the code block removed
                    if (t.getId() == Long.parseLong(removeid)) {
                        if (log.isDebugEnabled()) {
                            log.debug(" ");
                            log.debug("domain address id: " + t.getId());
                            log.debug(" ");
                        }
                        // create a collection of matching anchor ids
                        certtoberemovedlist.add(t.getId());
                        break;
                    }
                }
            }
            // with the collection of anchor ids now remove them from the configSvc
            if (log.isDebugEnabled())
                log.debug(" Trying to remove anchors from database");
            anchorService.deleteAnchorsByIds(certtoberemovedlist);
            if (log.isDebugEnabled())
                log.debug(" SUCCESS Trying to update the domain with removed anchors");
            final AddressForm addrform = new AddressForm();
            addrform.setId(dom.getId());
            model.addAttribute("addressForm", addrform);
        } catch (ServiceException e) {
            if (log.isDebugEnabled())
                log.error(e);
        }
    }
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    // BEGIN: temporary code for mocking purposes
    final CertificateForm cform = new CertificateForm();
    cform.setId(dom.getId());
    model.addAttribute("certificateForm", cform);
    final AnchorForm aform = new AnchorForm();
    aform.setId(dom.getId());
    model.addAttribute("anchorForm", aform);
    model.addAttribute("addressesResults", dom.getAddresses());
    mav.setViewName("domain");
    // the Form's default button action
    String action = "Update";
    DomainForm form = (DomainForm) session.getAttribute("domainForm");
    if (form == null) {
        form = new DomainForm();
        form.populate(dom);
    }
    model.addAttribute("domainForm", form);
    model.addAttribute("action", action);
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    mav.addObject("action", action);
    // SETTING THE ADDRESSES OBJECT
    model.addAttribute("addressesResults", form.getAddresses());
    Collection<Certificate> certlist = null;
    try {
        certlist = certService.getCertificatesByOwner(owner);
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    Collection<Anchor> anchorlist = null;
    try {
        anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
    } catch (Exception e) {
        e.printStackTrace();
    }
    model.addAttribute("certificatesResults", certlist);
    // convert Anchor to AnchorForm
    final Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
    // now set anchorsResults
    model.addAttribute("anchorsResults", convertedanchors);
    // END: temporary code for mocking purposes	
    mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
    mav.addObject("statusList", EntityStatus.getEntityStatusList());
    model.addAttribute("simpleForm", simpleForm);
    strid = "" + simpleForm.getId();
    if (log.isDebugEnabled())
        log.debug(" the value of id of simpleform is: " + strid);
    return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab2");
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) Domain(org.nhindirect.config.model.Domain) 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)

Aggregations

CertificateForm (org.nhindirect.config.ui.form.CertificateForm)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 X509Certificate (java.security.cert.X509Certificate)12 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)12 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IOException (java.io.IOException)11 Certificate (org.nhindirect.config.model.Certificate)11 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)10 AddressForm (org.nhindirect.config.ui.form.AddressForm)10 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)10 DomainForm (org.nhindirect.config.ui.form.DomainForm)10 ArrayList (java.util.ArrayList)9 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)9 Domain (org.nhindirect.config.model.Domain)8 TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)8 Anchor (org.nhindirect.config.model.Anchor)7 KeyStore (java.security.KeyStore)4 PrivateKey (java.security.PrivateKey)4