Search in sources :

Example 1 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DNSController method addA4Setting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addA4DNSRecord", method = RequestMethod.POST)
public ModelAndView addA4Setting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (AAdnsForm != null && !AAdnsForm.getName().equalsIgnoreCase("") && AAdnsForm.getTtl() != 0L && !AAdnsForm.getDest().equalsIgnoreCase("")) {
        try {
            dnsService.addDNSRecord(DNSEntryForm.createA4Record(AAdnsForm.getName(), AAdnsForm.getTtl(), AAdnsForm.getDest()));
        } 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 2 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DNSController method addMXSetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addMXDNSRecord", method = RequestMethod.POST)
public ModelAndView addMXSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (MXdnsForm != null && !MXdnsForm.getName().equalsIgnoreCase("") && MXdnsForm.getTtl() != 0L && !MXdnsForm.getDest().equalsIgnoreCase("")) {
        try {
            dnsService.addDNSRecord(DNSEntryForm.entityToModelRecord(DNSRecordUtils.createMXRecord(MXdnsForm.getName(), MXdnsForm.getDest(), MXdnsForm.getTtl(), MXdnsForm.getPriority())));
        } 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());
    final 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 3 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DNSEntryForm method createCertRecord.

/**
	 * Creates a DNS Cert type record.
	 * @param name The record name.  Generally a fully qualified domain name such as host.example.com.
	 * @param ttl The time to live in seconds.
	 * @param ip The ip4 address that the name will resolve.
	 * @return A DNSRecord representing an A type record.
	 * @throws ConfigurationStoreException
	 */
public static DNSRecord createCertRecord(String name, long ttl, int certtype, int keytag, int alg, X509Certificate cert) throws ServiceException {
    if (!name.endsWith("."))
        name = name + ".";
    try {
        int keyTag = 0;
        if (cert.getPublicKey() instanceof RSAKey) {
            final RSAKey key = (RSAKey) cert.getPublicKey();
            byte[] modulus = key.getModulus().toByteArray();
            keyTag = (modulus[modulus.length - 2] << 8) & 0xFF00;
            keyTag |= modulus[modulus.length - 1] & 0xFF;
        }
        final CERTRecord rec = new CERTRecord(Name.fromString(name), DClass.IN, ttl, CERTRecord.PKIX, keyTag, 5, cert.getEncoded());
        return xbillToModelRecord(rec);
    } catch (Exception e) {
        throw new ServiceException("Failed to create DNS CERT record: " + e.getMessage(), e);
    }
}
Also used : RSAKey(java.security.interfaces.RSAKey) CERTRecord(org.xbill.DNS.CERTRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 4 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException 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 5 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException 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)

Aggregations

ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)42 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 ModelAndView (org.springframework.web.servlet.ModelAndView)31 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)19 IOException (java.io.IOException)18 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)15 X509Certificate (java.security.cert.X509Certificate)12 Certificate (org.nhindirect.config.model.Certificate)12 CertificateForm (org.nhindirect.config.ui.form.CertificateForm)12 ArrayList (java.util.ArrayList)11 Domain (org.nhindirect.config.model.Domain)10 TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)9 AddressForm (org.nhindirect.config.ui.form.AddressForm)9 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)9 Anchor (org.nhindirect.config.model.Anchor)8 DomainForm (org.nhindirect.config.ui.form.DomainForm)8 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)8 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)7 TrustBundle (org.nhindirect.config.model.TrustBundle)6