Search in sources :

Example 16 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateDaoImpl method setStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.CertificateDao#setStatus(java.util.List, org.nhindirect.config.store.EntityStatus)
     */
@Transactional(readOnly = false)
public void setStatus(List<Long> certificateIDs, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Certificate> certs = this.list(certificateIDs);
    if (certs == null || certs.size() == 0)
        return;
    for (Certificate cert : certs) {
        cert.setStatus(status);
        entityManager.merge(cert);
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.store.Certificate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateDaoImpl method setStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.CertificateDao#setStatus(java.lang.String, org.nhindirect.config.store.EntityStatus)
     */
@Transactional(readOnly = false)
public void setStatus(String owner, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Certificate> certs = list(owner);
    if (certs == null || certs.size() == 0)
        return;
    for (Certificate cert : certs) {
        cert.setStatus(status);
        entityManager.merge(cert);
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.store.Certificate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Certificate

use of org.nhindirect.config.store.Certificate 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) {
    if (log.isDebugEnabled())
        log.debug("Enter search");
    String message = "Search complete";
    ModelAndView mav = new ModelAndView();
    // check to see if new domain requested
    if (actionPath.equalsIgnoreCase("gotosettings")) {
        if (log.isDebugEnabled())
            log.debug("trying to go to the settings page");
        String action = "add";
        model.addAttribute("action", action);
        mav.setViewName("settings");
        mav.addObject("actionPath", actionPath);
        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 (configSvc != null) {
            try {
                Collection<Setting> settings = configSvc.getAllSettings();
                if (settings != null)
                    results = new ArrayList<Setting>(settings);
                else
                    results = new ArrayList<Setting>();
            } catch (ConfigurationServiceException e) {
                e.printStackTrace();
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("settingsResults", results);
    } else if (actionPath.equalsIgnoreCase("gotocertificates")) {
        if (log.isDebugEnabled())
            log.debug("trying to go to the certificates page");
        String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("certificates");
        mav.addObject("actionPath", actionPath);
        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 (configSvc != null) {
            try {
                Collection<Certificate> certs = configSvc.listCertificates(1, 10000, CertificateGetOptions.DEFAULT);
                if (certs != null)
                    results = new ArrayList<Certificate>(certs);
                else
                    results = new ArrayList<Certificate>();
            } catch (ConfigurationServiceException e) {
                e.printStackTrace();
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("certificatesResults", results);
    } else if (actionPath.equalsIgnoreCase("newdomain")) {
        if (log.isDebugEnabled())
            log.debug("trying to go to the new domain page");
        HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        model.addAttribute("simpleForm", new SimpleForm());
        AddressForm addrform = new AddressForm();
        addrform.setId(0L);
        model.addAttribute("addressForm", addrform);
        // TODO: once certificates and anchors are available change code accordingly
        CertificateForm cform = new CertificateForm();
        cform.setId(0L);
        AnchorForm aform = new AnchorForm();
        aform.setId(0L);
        model.addAttribute("certificateForm", cform);
        model.addAttribute("anchorForm", aform);
        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", actionPath);
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
    } else if (actionPath.equalsIgnoreCase("gotodns")) {
        if (log.isDebugEnabled())
            log.debug("trying to go to the DNS page");
        HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        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", actionPath);
        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 {
        SearchDomainForm form = (SearchDomainForm) session.getAttribute("searchDomainForm");
        if (form == null) {
            form = new SearchDomainForm();
        }
        model.addAttribute(form);
        model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
        String domain = form.getDomainName();
        EntityStatus status = form.getStatus();
        List<Domain> results = null;
        if (configSvc != null) {
            Collection<Domain> domains = configSvc.searchDomain(domain, status);
            if (domains != null) {
                results = new ArrayList<Domain>(domains);
            } else {
                results = new ArrayList<Domain>();
            }
        }
        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("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) Message(org.nhindirect.config.ui.flash.FlashMap.Message) HashMap(java.util.HashMap) Setting(org.nhindirect.config.store.Setting) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) AddressForm(org.nhindirect.config.ui.form.AddressForm) SettingsForm(org.nhindirect.config.ui.form.SettingsForm) Collection(java.util.Collection) EntityStatus(org.nhindirect.config.store.EntityStatus) List(java.util.List) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.store.Certificate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class ServiceTest method testDNSService.

//    @Test
//    public void testDomainService()
//    {
//        try
//        {
//            int count = configSvc. getDomainCount();
//            log.info(""+count + " Domains exist in the database");
//        } 
//        catch (ConfigurationServiceException e)
//        {
//            e.printStackTrace();
//            fail(e.getMessage());
//        }  
//    }
//    @Test
public void testDNSService() {
    //        try
    //        {
    //configSvc.getDNSCount();
    int count = 0;
    //            log.info(""+count + " DNS records exist in the database");
    //            System.out.println(""+count + " DNS records exist in the database");
    //            configSvc.removeDomain("pjpassoc.com");
    Collection<DNSRecord> records = new ArrayList<DNSRecord>();
    //            records.add(DNSRecordUtils.createARecord("pjpassoc.com", 3600L, "192.168.1.1"));
    //            records.add(DNSRecordUtils.createMXRecord("pjpassoc.com", "mail.pjpassoc.com", 3600L, 0));
    byte[] certData = null;
    try {
        //				certData = loadPkcs12FromCertAndKey("gm2552.der", "gm2552Key.der");
        certData = loadCertificateData("gm2552.der");
        if (certData != null) {
            // get the owner from the certificate information
            // first transform into a certificate
            CertContainer cont = toCertContainer(certData);
            if (cont != null && cont.getCert() != null) {
                Certificate cert2 = new Certificate();
                cert2.setData(certData);
                System.out.println(getThumbPrint(cont.getCert()));
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
//            records.add(DNSEntryForm.createCertRecord("yahoo.com", 3600L, 0,0,0,certData));
//            configSvc.addDNS(records);
//            assertEquals(2, configSvc.getDNSCount());
//        }
//        catch (ConfigurationServiceException e)
//        {
//            e.printStackTrace();
//            fail(e.getMessage());
//        }  
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) TextParseException(org.xbill.DNS.TextParseException) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.store.Certificate)

Aggregations

Certificate (org.nhindirect.config.store.Certificate)19 X509Certificate (java.security.cert.X509Certificate)10 Expectations (org.jmock.Expectations)7 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 CertificateServiceImpl (org.nhindirect.config.service.impl.CertificateServiceImpl)5 List (java.util.List)4 CertificateGetOptions (org.nhindirect.config.service.impl.CertificateGetOptions)4 Query (javax.persistence.Query)3 DNSRecord (org.nhindirect.config.store.DNSRecord)3 Setting (org.nhindirect.config.store.Setting)3 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)2 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 CertContainer (org.nhindirect.config.store.Certificate.CertContainer)2 Domain (org.nhindirect.config.store.Domain)2