Search in sources :

Example 36 with ServiceException

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

the class PoliciesController method addPolicy.

/*********************************
     *
     * Add Policy Method
     *
     *********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addPolicy", method = RequestMethod.POST)
@ResponseBody
public String addPolicy(@RequestParam("id") String id, @RequestParam("policyName") String policyName, @RequestParam("policyContent") String policyContent, @RequestParam("policyLexicon") String policyLexicon) {
    // Debug Statement
    if (log.isDebugEnabled()) {
        log.debug("Adding New Policy");
    }
    if (log.isDebugEnabled()) {
        log.debug("Beginning to add new policy");
    }
    try {
        URL configURL = new URL("http://localhost:8081/config-service/ConfigurationService");
    } catch (MalformedURLException ue) {
    }
    final CertPolicy newPolicy = new CertPolicy();
    newPolicy.setPolicyName(policyName);
    // Set policy lexicon type           
    final String lexiconName = policyLexicon;
    if (lexiconName.equalsIgnoreCase("XML")) {
        newPolicy.setLexicon(PolicyLexicon.XML);
    } else if (lexiconName.equalsIgnoreCase("JAVA_SER")) {
        newPolicy.setLexicon(PolicyLexicon.JAVA_SER);
    } else if (lexiconName.equalsIgnoreCase("SIMPLE_TEXT_V1")) {
        newPolicy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
    }
    // Get lexicon file from form
    //CommonsMultipartFile lexiconFile = policyForm.getFileData();            
    newPolicy.setPolicyData(policyContent.getBytes());
    // Debug
    log.error(newPolicy);
    try {
        policyService.addPolicy(newPolicy);
    } catch (ServiceException cse) {
        cse.printStackTrace();
    }
    return "test";
}
Also used : MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) CertPolicy(org.nhindirect.config.model.CertPolicy) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 37 with ServiceException

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

the class SettingsController method removeAnchors.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removesettings", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled())
        log.debug("Enter domain/removesettings");
    if (simpleForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
    }
    String strid = "" + simpleForm.getId();
    if (settingsService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("delete") || actionPath.equalsIgnoreCase("remove selected")) && 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");
            for (String toRemove : settingstoberemovedlist) settingsService.deleteSetting(toRemove);
            settingsService.getSettings();
            if (log.isDebugEnabled())
                log.debug(" SUCCESS Trying to remove settings");
        } catch (ServiceException e) {
            if (log.isDebugEnabled())
                log.error(e);
        }
    }
    try {
        model.addAttribute("settingsResults", settingsService.getSettings());
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    mav.setViewName("settings");
    String action = "Update";
    model.addAttribute("settingsForm", new SettingsForm());
    model.addAttribute("action", action);
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    model.addAttribute("simpleForm", simpleForm);
    strid = "" + simpleForm.getId();
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) SettingsForm(org.nhindirect.config.ui.form.SettingsForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with ServiceException

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

the class DNSController method addSOASetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addSOADNSRecord", method = RequestMethod.POST)
public ModelAndView addSOASetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (SoadnsForm != null && !SoadnsForm.getName().equalsIgnoreCase("") && SoadnsForm.getTtl() != 0L) {
        final DNSRecord rec = DNSEntryForm.entityToModelRecord(DNSRecordUtils.createSOARecord(SoadnsForm.getName(), SoadnsForm.getTtl(), SoadnsForm.getDomain(), SoadnsForm.getAdmin(), (int) SoadnsForm.getSerial(), SoadnsForm.getRefresh(), SoadnsForm.getRetry(), SoadnsForm.getExpire(), SoadnsForm.getMinimum()));
        try {
            dnsService.addDNSRecord(rec);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    final 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) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with ServiceException

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

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

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