Search in sources :

Example 1 with BundleForm

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

the class BundlesController method addBundle.

/*********************************
     *
     * Add Bundle Method
     *
     *********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addbundle", method = RequestMethod.POST)
public ModelAndView addBundle(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm bundleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    final ModelAndView mav = new ModelAndView();
    // Debug Statement
    if (log.isDebugEnabled())
        log.debug("Enter Add Trust Bundle");
    if (actionPath.equalsIgnoreCase("cancel")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to cancel from saveupdate");
        }
        // If cancel then clear form	
        final SearchDomainForm form2 = (SearchDomainForm) session.getAttribute("searchDomainForm");
        model.addAttribute(form2 != null ? form2 : new SearchDomainForm());
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        mav.setViewName("main");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
        return mav;
    }
    if (actionPath.equalsIgnoreCase("newbundle") || actionPath.equalsIgnoreCase("add bundle")) {
        Boolean formValidated = true;
        if (log.isDebugEnabled()) {
            log.debug("Beginning to process signing certificate file");
        }
        model.addAttribute("signingCertError", false);
        model.addAttribute("URLError", false);
        final TrustBundle trustBundle = new TrustBundle();
        String bundleName = bundleForm.getBundleName();
        trustBundle.setBundleName(bundleName);
        // Convert Hours to Seconds for backend
        trustBundle.setRefreshInterval(bundleForm.getRefreshInterval() * 3600);
        // Check if signing certificate is uploaded
        if (!bundleForm.getFileData().isEmpty()) {
            byte[] bytes = bundleForm.getFileData().getBytes();
            final String fileType = bundleForm.getFileData().getContentType();
            if (!fileType.matches("application/x-x509-ca-cert") && !fileType.matches("application/x-x509-user-cert") && !fileType.matches("application/pkix-cert")) {
                model.addAttribute("signingCertError", true);
                formValidated = false;
            } else {
                try {
                    trustBundle.setSigningCertificateData(bytes);
                } catch (Exception ce) {
                }
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("DO NOT store the bundle into database BECAUSE THERE IS NO FILE");
        }
        // Check for empty bundle name
        if (bundleName.isEmpty()) {
            model.addAttribute("EmptyBundleError", true);
            formValidated = false;
        } else {
            // Check if trust bundle name is already used
            TrustBundle dupeBundle = null;
            try {
                dupeBundle = bundleService.getTrustBundle(bundleName);
            } catch (ServiceException cse) {
                log.error("Could not get bundle information from config service");
            }
            if (dupeBundle != null) {
                model.addAttribute("DupeBundleError", true);
                formValidated = false;
            }
        }
        // Check for valid URL
        final String trustURL = bundleForm.getTrustURL();
        try {
            new URL(trustURL);
        } catch (MalformedURLException mu) {
            model.addAttribute("URLError", true);
            formValidated = false;
        }
        if (formValidated) {
            trustBundle.setBundleURL(trustURL);
            try {
                trustBundle.setCheckSum("");
                bundleService.addTrustBundle(trustBundle);
                if (log.isDebugEnabled()) {
                    log.debug("Add Trust Bundle to Database");
                }
            } catch (Exception e) {
                if (log.isDebugEnabled())
                    log.error(e);
                e.printStackTrace();
            }
            final BundleForm bform = new BundleForm();
            model.addAttribute("bundleForm", bform);
        }
        // Process data for Trust Bundle View
        try {
            // Get Trust Bundles
            final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
            if (trustBundles != null) {
                model.addAttribute("trustBundles", trustBundles);
            }
        } catch (ServiceException e1) {
        }
        model.addAttribute("bundlesSelected");
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        mav.setViewName("bundles");
    }
    return mav;
}
Also used : SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) BundleForm(org.nhindirect.config.ui.form.BundleForm) ModelAndView(org.springframework.web.servlet.ModelAndView) TrustBundle(org.nhindirect.config.model.TrustBundle) MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with BundleForm

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

the class BundlesController method removeCertificates.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removebundle", method = RequestMethod.POST)
public ModelAndView removeCertificates(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
    final ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled()) {
        log.debug("Enter bundles/removebundle");
    }
    if (simpleForm.getBundlesSelected() != null) {
        if (log.isDebugEnabled()) {
            log.debug("Bundles marked for removal: " + simpleForm.getBundlesSelected().toString());
        }
    }
    if (bundleService != null && simpleForm != null && simpleForm.getBundlesSelected() != null) {
        final int bundleCount = simpleForm.getBundlesSelected().size();
        if (log.isDebugEnabled()) {
            log.debug("Removing Bundles");
        }
        for (int i = 0; i < bundleCount; i++) {
            final String bundleName = simpleForm.getBundlesSelected().get(i);
            log.error(bundleName);
            // Delete Trust Bundle(s)
            try {
                bundleService.deleteTrustBundle(bundleName);
            } catch (ServiceException cse) {
                log.error("Problem removing bundles");
            }
        }
    }
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    final BundleForm bform = new BundleForm();
    bform.setId(0);
    model.addAttribute("bundleForm", bform);
    mav.setViewName("bundles");
    // Process data for Trust Bundle View
    try {
        // Get Trust Bundles
        final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
        if (trustBundles != null) {
            model.addAttribute("trustBundles", trustBundles);
        }
    } catch (ServiceException e1) {
    }
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) BundleForm(org.nhindirect.config.ui.form.BundleForm) ModelAndView(org.springframework.web.servlet.ModelAndView) TrustBundle(org.nhindirect.config.model.TrustBundle) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with BundleForm

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

the class BundlesController method assignBundlesForm.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/assignBundlesForm", method = RequestMethod.GET)
public ModelAndView assignBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled()) {
        log.debug("Enter bundles/assignBundles");
    }
    // Process data for Trust Bundle View
    try {
        // Get Trust Bundles
        final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
        if (trustBundles != null) {
            model.addAttribute("trustBundles", trustBundles);
        }
    } catch (ServiceException e1) {
    }
    BundleForm bform = new BundleForm();
    bform.setId(0);
    bform.setDomainName((String) session.getAttribute("currentDomainName"));
    model.addAttribute("bundleForm", bform);
    mav.setViewName("assignBundlesForm");
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) BundleForm(org.nhindirect.config.ui.form.BundleForm) ModelAndView(org.springframework.web.servlet.ModelAndView) TrustBundle(org.nhindirect.config.model.TrustBundle) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with BundleForm

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

the class BundlesController method addMoreBundlesForm.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addMoreBundlesForm", method = RequestMethod.GET)
public ModelAndView addMoreBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, @RequestParam(value = "domainName") String domainName, Model model) {
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled()) {
        log.debug("Enter bundles/addMoreBundlesForm");
    }
    // Process data for Trust Bundle View
    try {
        // Get Trust Bundles
        final Collection<TrustBundle> trustBundles = new ArrayList<TrustBundle>();
        Collection<TrustBundle> newBundles = new ArrayList<TrustBundle>();
        final Collection<TrustBundleDomainReltn> bundleRelationships = bundleService.getTrustBundlesByDomain(domainName, false);
        final Collection<TrustBundle> allBundles = bundleService.getTrustBundles(false);
        boolean bundleMatch = false;
        if (bundleRelationships != null && !bundleRelationships.isEmpty()) {
            for (TrustBundleDomainReltn relationship : bundleRelationships) {
                trustBundles.add(relationship.getTrustBundle());
            }
            for (TrustBundle bundle : allBundles) {
                bundleMatch = false;
                for (TrustBundle subBundle : trustBundles) {
                    if (subBundle.getId() == bundle.getId()) {
                        bundleMatch = true;
                    }
                }
                if (!bundleMatch) {
                    newBundles.add(bundle);
                }
            }
        } else {
            newBundles = bundleService.getTrustBundles(false);
        }
        //if(trustBundles != null) {
        model.addAttribute("trustBundles", newBundles);
    //}
    } catch (ServiceException e1) {
    }
    model.addAttribute("domainName", domainName);
    BundleForm bform = new BundleForm();
    bform.setId(0);
    bform.setDomainName((String) session.getAttribute("currentDomainName"));
    model.addAttribute("bundleForm", bform);
    mav.setViewName("addMoreBundlesForm");
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) BundleForm(org.nhindirect.config.ui.form.BundleForm) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) TrustBundle(org.nhindirect.config.model.TrustBundle) TrustBundleDomainReltn(org.nhindirect.config.model.TrustBundleDomainReltn) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with BundleForm

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

the class BundlesController method newBundleForm.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/newBundleForm", method = RequestMethod.GET)
public ModelAndView newBundleForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled()) {
        log.debug("Enter bundles/newBundles");
    }
    BundleForm bform = new BundleForm();
    bform.setId(0);
    model.addAttribute("bundleForm", bform);
    mav.setViewName("newBundleForm");
    return mav;
}
Also used : BundleForm(org.nhindirect.config.ui.form.BundleForm) ModelAndView(org.springframework.web.servlet.ModelAndView) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BundleForm (org.nhindirect.config.ui.form.BundleForm)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)6 TrustBundle (org.nhindirect.config.model.TrustBundle)6 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 KeyStore (java.security.KeyStore)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CertificateEncodingException (javax.security.cert.CertificateEncodingException)1