Search in sources :

Example 1 with TrustBundleAnchor

use of org.nhindirect.config.model.TrustBundleAnchor in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildTrustAnchorResolver.

public void buildTrustAnchorResolver() {
    Provider<TrustAnchorResolver> provider = null;
    Map<String, Collection<X509Certificate>> incomingAnchors = new HashMap<String, Collection<X509Certificate>>();
    Map<String, Collection<X509Certificate>> outgoingAnchors = new HashMap<String, Collection<X509Certificate>>();
    /* 
		 * first determine how anchors are stored... possibilities are LDAP, keystore, and WS
		 * 
		 */
    Setting setting = null;
    String storeType;
    String resolverType;
    try {
        setting = settingsService.getSetting("AnchorStoreType");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting anchor store type: " + e.getMessage(), e);
    }
    if (setting == null || setting.getValue() == null || setting.getValue().isEmpty())
        // default to WS
        storeType = STORE_TYPE_WS;
    else
        storeType = setting.getValue();
    // if the store type is anything other than WS, then we need to get the anchor names so we can look them up in the repository
    if (!storeType.equalsIgnoreCase(STORE_TYPE_WS)) {
        getAnchorsFromNonWS(incomingAnchors, outgoingAnchors, storeType);
    } else {
        // trust bundles are shared objects across domains, so just pull the entire bundle list and associate
        // the anchors in the bundles to the appropriate domains as we go... this will not always be the most efficient
        // algorithm, but it most cases it will be when there are several domains configured (in which case this
        // loading algorithm will be much more efficient)
        final Map<String, TrustBundle> bundleMap = new HashMap<String, TrustBundle>();
        try {
            final Collection<TrustBundle> bundles = trustBundleService.getTrustBundles(true);
            // put the bundles in a Map by name
            if (bundles != null)
                for (TrustBundle bundle : bundles) bundleMap.put(bundle.getBundleName(), bundle);
        } catch (Exception e) {
            throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting trust bundles: " + e.getMessage(), e);
        }
        // hit up the web service for each domains anchor
        for (Domain domain : lookedupRESTServiceDomains) {
            try {
                final Collection<X509Certificate> incomingAnchorsToAdd = new ArrayList<X509Certificate>();
                final Collection<X509Certificate> outgoingAnchorsToAdd = new ArrayList<X509Certificate>();
                // get the anchors for the domain
                final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(domain.getDomainName(), false, false, null);
                if (anchors != null) {
                    for (Anchor anchor : anchors) {
                        final X509Certificate anchorToAdd = certFromData(anchor.getCertificateData());
                        if (anchor.isIncoming())
                            incomingAnchorsToAdd.add(anchorToAdd);
                        if (anchor.isOutgoing())
                            outgoingAnchorsToAdd.add(anchorToAdd);
                    }
                }
                // check to see if there is a bundle associated to this domain
                final Collection<TrustBundleDomainReltn> domainAssocs = trustBundleService.getTrustBundlesByDomain(domain.getDomainName(), false);
                if (domainAssocs != null) {
                    for (TrustBundleDomainReltn domainAssoc : domainAssocs) {
                        final TrustBundle bundle = bundleMap.get(domainAssoc.getTrustBundle().getBundleName());
                        if (bundle != null && bundle.getTrustBundleAnchors() != null) {
                            for (TrustBundleAnchor anchor : bundle.getTrustBundleAnchors()) {
                                final X509Certificate anchorToAdd = certFromData(anchor.getAnchorData());
                                if (domainAssoc.isIncoming())
                                    incomingAnchorsToAdd.add(anchorToAdd);
                                if (domainAssoc.isOutgoing())
                                    outgoingAnchorsToAdd.add(anchorToAdd);
                            }
                        }
                    }
                }
                incomingAnchors.put(domain.getDomainName(), incomingAnchorsToAdd);
                outgoingAnchors.put(domain.getDomainName(), outgoingAnchorsToAdd);
            } catch (SmtpAgentException e) {
                // rethrow
                throw e;
            } catch (Exception e) {
                throw new SmtpAgentException(SmtpAgentError.InvalidTrustAnchorSettings, "WebService error getting trust anchors for domain " + domain + ":" + e.getMessage(), e);
            }
        }
    }
    try {
        setting = settingsService.getSetting("AnchorResolverType");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting anchor resolver type: " + e.getMessage(), e);
    }
    if (incomingAnchors.size() == 0 && outgoingAnchors.size() == 0)
        throw new SmtpAgentException(SmtpAgentError.InvalidTrustAnchorSettings, "No trust anchors defined.");
    if (setting == null || setting.getValue() == null || setting.getValue().isEmpty()) {
        // multi domain should be the default... uniform really only makes sense for dev purposes
        resolverType = ANCHOR_RES_TYPE_MULTIDOMAIN;
    } else
        resolverType = setting.getValue();
    if (resolverType.equalsIgnoreCase(ANCHOR_RES_TYPE_UNIFORM)) {
        // the same... just get the first collection in the incoming map
        if (incomingAnchors.size() > 0)
            provider = new UniformTrustAnchorResolverProvider(incomingAnchors.values().iterator().next());
        else
            provider = new UniformTrustAnchorResolverProvider(outgoingAnchors.values().iterator().next());
    } else if (resolverType.equalsIgnoreCase(ANCHOR_RES_TYPE_MULTIDOMAIN)) {
        provider = new MultiDomainTrustAnchorResolverProvider(incomingAnchors, outgoingAnchors);
    } else {
        throw new SmtpAgentException(SmtpAgentError.InvalidTrustAnchorSettings);
    }
    certAnchorModule = TrustAnchorModule.create(provider);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) HashMap(java.util.HashMap) Setting(org.nhindirect.config.model.Setting) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) TrustBundleDomainReltn(org.nhindirect.config.model.TrustBundleDomainReltn) Anchor(org.nhindirect.config.model.Anchor) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) UniformTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider) Collection(java.util.Collection) TrustBundle(org.nhindirect.config.model.TrustBundle) Domain(org.nhindirect.config.model.Domain) MultiDomainTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor)

Example 2 with TrustBundleAnchor

use of org.nhindirect.config.model.TrustBundleAnchor in project nhin-d by DirectProject.

the class EntityModelConversion method toEntityTrustBundle.

public static org.nhindirect.config.store.TrustBundle toEntityTrustBundle(TrustBundle bundle) {
    if (bundle == null)
        return null;
    final org.nhindirect.config.store.TrustBundle retVal = new org.nhindirect.config.store.TrustBundle();
    final Collection<org.nhindirect.config.store.TrustBundleAnchor> trustAnchors = new ArrayList<org.nhindirect.config.store.TrustBundleAnchor>();
    if (bundle.getTrustBundleAnchors() != null) {
        for (TrustBundleAnchor anchor : bundle.getTrustBundleAnchors()) {
            final org.nhindirect.config.store.TrustBundleAnchor retAnchor = new org.nhindirect.config.store.TrustBundleAnchor();
            try {
                retAnchor.setData(anchor.getAnchorData());
            } catch (CertificateException e) {
                throw new CertificateConversionException(e);
            }
            // the entity object sets all other attributes based on the cert data,
            // no need to explicitly set it here
            retAnchor.setTrustBundle(retVal);
            trustAnchors.add(retAnchor);
        }
    }
    retVal.setBundleName(bundle.getBundleName());
    retVal.setBundleURL(bundle.getBundleURL());
    if (bundle.getCheckSum() == null)
        retVal.setCheckSum("");
    else
        retVal.setCheckSum(bundle.getCheckSum());
    retVal.setCreateTime(bundle.getCreateTime());
    retVal.setId(bundle.getId());
    retVal.setLastRefreshAttempt(bundle.getLastRefreshAttempt());
    if (bundle.getLastRefreshError() != null)
        retVal.setLastRefreshError(org.nhindirect.config.store.BundleRefreshError.valueOf(bundle.getLastRefreshError().toString()));
    retVal.setLastSuccessfulRefresh(bundle.getLastSuccessfulRefresh());
    retVal.setRefreshInterval(bundle.getRefreshInterval());
    if (bundle.getSigningCertificateData() != null) {
        try {
            retVal.setSigningCertificateData(bundle.getSigningCertificateData());
        } catch (CertificateException e) {
            throw new CertificateConversionException(e);
        }
    }
    retVal.setTrustBundleAnchors(trustAnchors);
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) TrustBundle(org.nhindirect.config.model.TrustBundle) CertificateException(org.nhindirect.config.store.CertificateException) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor)

Example 3 with TrustBundleAnchor

use of org.nhindirect.config.model.TrustBundleAnchor in project nhin-d by DirectProject.

the class EntityModelConversion method toModelTrustBundle.

public static TrustBundle toModelTrustBundle(org.nhindirect.config.store.TrustBundle bundle) {
    if (bundle == null)
        return null;
    final TrustBundle retVal = new TrustBundle();
    final Collection<TrustBundleAnchor> trustAnchors = new ArrayList<TrustBundleAnchor>();
    if (bundle.getTrustBundleAnchors() != null) {
        for (org.nhindirect.config.store.TrustBundleAnchor anchor : bundle.getTrustBundleAnchors()) {
            final TrustBundleAnchor retAnchor = new TrustBundleAnchor();
            retAnchor.setAnchorData(anchor.getData());
            retAnchor.setThumbprint(anchor.getThumbprint());
            retAnchor.setId(anchor.getId());
            retAnchor.setValidEndDate(anchor.getValidEndDate());
            retAnchor.setValidStartDate(anchor.getValidStartDate());
            trustAnchors.add(retAnchor);
        }
    }
    retVal.setBundleName(bundle.getBundleName());
    retVal.setBundleURL(bundle.getBundleURL());
    retVal.setCheckSum(bundle.getCheckSum());
    retVal.setCreateTime(bundle.getCreateTime());
    retVal.setId(bundle.getId());
    retVal.setLastRefreshAttempt(bundle.getLastRefreshAttempt());
    if (bundle.getLastRefreshAttempt() != null)
        retVal.setLastRefreshError(BundleRefreshError.valueOf(bundle.getLastRefreshError().toString()));
    retVal.setLastSuccessfulRefresh(bundle.getLastSuccessfulRefresh());
    retVal.setRefreshInterval(bundle.getRefreshInterval());
    retVal.setSigningCertificateData(bundle.getSigningCertificateData());
    retVal.setTrustBundleAnchors(trustAnchors);
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) TrustBundle(org.nhindirect.config.model.TrustBundle) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor)

Example 4 with TrustBundleAnchor

use of org.nhindirect.config.model.TrustBundleAnchor 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 5 with TrustBundleAnchor

use of org.nhindirect.config.model.TrustBundleAnchor 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, @RequestParam(value = "domainName", required = false) String searchDomainName, @RequestParam(value = "status", required = false) EntityStatus searchStatus) {
    log.error("Hit Search Controller");
    if (log.isDebugEnabled()) {
        log.debug("Enter search");
    }
    String message = "Search complete";
    ModelAndView mav = new ModelAndView();
    if (actionPath.equalsIgnoreCase("gotosettings") || actionPath.equalsIgnoreCase("settings")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the settings page");
        }
        String action = "add";
        model.addAttribute("action", action);
        // Set view for this method
        mav.setViewName("settings");
        mav.addObject("actionPath", "gotosettings");
        // Initialize default settings form 
        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 (settingsService != null) {
            try {
                final Collection<Setting> settings = settingsService.getSettings();
                if (settings != null) {
                    results = new ArrayList<Setting>(settings);
                } else {
                    results = new ArrayList<Setting>();
                }
            } catch (ServiceException e) {
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("settingsResults", results);
    } else if (actionPath.equalsIgnoreCase("gotocertificates") || actionPath.equalsIgnoreCase("certificates")) {
        /*************************************
                 * Manage Certificates
                 * 
                 *************************************/
        //if (log.isDebugEnabled()) {
        log.error("trying to go to the certificates page");
        //}
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("certificates");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("actionPath", "gotocertificates");
        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 (certService != null) {
            try {
                final Collection<Certificate> certs = certService.getAllCertificates();
                if (certs != null) {
                    if (this.keyManager != null && this.keyManager instanceof MutableKeyStoreProtectionManager) {
                        final KeyStore keyStore = ((MutableKeyStoreProtectionManager) keyManager).getKS();
                        // the key store manager to see if they have private keys
                        for (Certificate cert : certs) {
                            if (!cert.isPrivateKey()) {
                                try {
                                    final X509Certificate checkCert = CertUtils.toX509Certificate(cert.getData());
                                    final String alias = keyStore.getCertificateAlias(checkCert);
                                    if (!StringUtils.isEmpty(alias)) {
                                        // check if this entry has a private key associated with
                                        // it
                                        final PrivateKey privKey = (PrivateKey) keyStore.getKey(alias, "".toCharArray());
                                        if (privKey != null)
                                            cert.setPrivateKey(true);
                                    }
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                    results = new ArrayList<Certificate>(certs);
                } else {
                    results = new ArrayList<Certificate>();
                }
            } catch (ServiceException e) {
            }
        }
        model.addAttribute("simpleForm", new SimpleForm());
        model.addAttribute("certificatesResults", results);
    } else if (actionPath.equalsIgnoreCase("newdomain") || actionPath.equalsIgnoreCase("new domain")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the new domain page");
        }
        final HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        model.addAttribute("simpleForm", new SimpleForm());
        final AddressForm addrform = new AddressForm();
        addrform.setId(0L);
        model.addAttribute("addressForm", addrform);
        // TODO: once certificates and anchors are available change code accordingly
        final CertificateForm cform = new CertificateForm();
        //cform.setId(0L);
        final AnchorForm aform = new AnchorForm();
        aform.setId(0L);
        model.addAttribute("certificateForm", cform);
        model.addAttribute("anchorForm", aform);
        final 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", "newdomain");
        mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        mav.addObject("statusList", EntityStatus.getEntityStatusList());
    } else if (actionPath.equalsIgnoreCase("gotodns") || actionPath.equalsIgnoreCase("DNS Entries")) {
        if (log.isDebugEnabled()) {
            log.debug("Entering DNS Management page");
        }
        final HashMap<String, String> msgs = new HashMap<String, String>();
        mav.addObject("msgs", msgs);
        final 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", "gotodns");
        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 if (actionPath.equalsIgnoreCase("ManagePolicies") || actionPath.equalsIgnoreCase("Policies")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the Policies page");
        }
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("policies");
        mav.addObject("actionPath", "gotopolicies");
        PolicyForm form = (PolicyForm) session.getAttribute("policyForm");
        if (form == null) {
            form = new PolicyForm();
        }
        model.addAttribute("policyForm", form);
        Collection<CertPolicy> policies = null;
        try {
            policies = policyService.getPolicies();
        } catch (Exception e) {
            System.out.println("Failed to lookup policies: " + e.getMessage());
        }
        if (policies != null) {
            model.addAttribute("policies", policies);
        } else {
            model.addAttribute("policies", "");
        }
        /*
                // retrieve list of settings for settingsResults
                List<Certificate> results = null;
                if (configSvc != null) {
                    // Process data for Trust Bundle View
                    try {

                        // Get Trust Bundles
                        Collection<TrustBundle> trustBundles = configSvc.getTrustBundles(true); 
                        
                        if (trustBundles == null)
                        	trustBundles = Collections.emptyList();
                        
                        Map<String, Object> bundleMap = new HashMap<String, Object>(trustBundles.size());                                                                                                            
                                    
                        Collection<TrustBundleAnchor> tbAnchors;    // Store anchors for each bundle   



                        for(TrustBundle bundle : trustBundles) 
                        {                                        
                            tbAnchors = bundle.getTrustBundleAnchors();    
                            Map<TrustBundleAnchor, String> anchorMap = new HashMap<TrustBundleAnchor, String>(tbAnchors.size());                                                                                

                            //String[] anchorDNs = new String[tbAnchors.size()];  // String array for storing anchor DNs
                            int curAnchor = 0;  // Counter as we iterate through anchor list

                            // Loop through anchors to collect some information about the certificates
                            for(TrustBundleAnchor anchor : tbAnchors) {

                                try {
                                    X509Certificate cert = anchor.toCertificate();                                            

                                    String subjectDN = cert.getSubjectDN().toString();
                                    anchorMap.put(anchor, subjectDN);

                                } catch (org.nhindirect.config.store.CertificateException ex) {                                                
                                }

                                curAnchor++;
                            }

                            bundleMap.put(bundle.getBundleName(), anchorMap);

                        }

                        model.addAttribute("bundleMap", bundleMap);  
                        
                        
                        
                        model.addAttribute("trustBundles", trustBundles);                                

                    } catch (ConfigurationServiceException e1) {
                            e1.printStackTrace();
                    }								
                }
                */
        model.addAttribute("simpleForm", new SimpleForm());
    } else if (actionPath.equalsIgnoreCase("ManageTrustBundles") || actionPath.equalsIgnoreCase("Bundles")) {
        if (log.isDebugEnabled()) {
            log.debug("trying to go to the Bundles page");
        }
        final String action = "Update";
        model.addAttribute("action", action);
        mav.setViewName("bundles");
        mav.addObject("actionPath", "gotobundles");
        BundleForm form = (BundleForm) session.getAttribute("BundleForm");
        if (form == null) {
            form = new BundleForm();
        }
        model.addAttribute("bundleForm", form);
        // retrieve list of settings for settingsResults
        if (bundleService != null) {
            // Process data for Trust Bundle View
            try {
                // Get Trust Bundles
                Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(true);
                if (trustBundles == null) {
                    trustBundles = Collections.emptyList();
                }
                final Map<String, Object> bundleMap = new HashMap<String, Object>(trustBundles.size());
                // Store anchors for each bundle   
                Collection<TrustBundleAnchor> tbAnchors;
                for (TrustBundle bundle : trustBundles) {
                    tbAnchors = bundle.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.getBundleName(), anchorMap);
                }
                model.addAttribute("bundleMap", bundleMap);
                model.addAttribute("trustBundles", trustBundles);
            } catch (ServiceException e1) {
                e1.printStackTrace();
            }
        }
        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));
        final String domain = (!searchDomainName.isEmpty()) ? searchDomainName : "%";
        mav.addObject("searchTerm", searchDomainName);
        EntityStatus status = searchStatus;
        List<Domain> results = null;
        if (domainService != null) {
            try {
                final Collection<Domain> domains = domainService.searchDomains(domain, org.nhindirect.config.model.EntityStatus.valueOf(status.toString()));
                if (domains != null) {
                    results = new ArrayList<Domain>(domains);
                } else {
                    results = new ArrayList<Domain>();
                }
            } catch (ServiceException e1) {
                e1.printStackTrace();
            }
        }
        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("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
        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) PrivateKey(java.security.PrivateKey) Message(org.nhindirect.config.ui.flash.FlashMap.Message) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) MutableKeyStoreProtectionManager(org.nhindirect.common.crypto.MutableKeyStoreProtectionManager) TrustBundle(org.nhindirect.config.model.TrustBundle) EntityStatus(org.nhindirect.config.store.EntityStatus) List(java.util.List) ArrayList(java.util.ArrayList) BundleForm(org.nhindirect.config.ui.form.BundleForm) Setting(org.nhindirect.config.model.Setting) KeyStore(java.security.KeyStore) 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) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) PolicyForm(org.nhindirect.config.ui.form.PolicyForm) AddressForm(org.nhindirect.config.ui.form.AddressForm) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) CertPolicy(org.nhindirect.config.model.CertPolicy) SettingsForm(org.nhindirect.config.ui.form.SettingsForm) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) TrustBundleAnchor(org.nhindirect.config.model.TrustBundleAnchor) 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

TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)5 ArrayList (java.util.ArrayList)4 TrustBundle (org.nhindirect.config.model.TrustBundle)4 X509Certificate (java.security.cert.X509Certificate)3 HashMap (java.util.HashMap)3 Collection (java.util.Collection)2 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)2 Anchor (org.nhindirect.config.model.Anchor)2 Certificate (org.nhindirect.config.model.Certificate)2 Domain (org.nhindirect.config.model.Domain)2 Setting (org.nhindirect.config.model.Setting)2 TrustBundleDomainReltn (org.nhindirect.config.model.TrustBundleDomainReltn)2 AddressForm (org.nhindirect.config.ui.form.AddressForm)2 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)2 CertificateForm (org.nhindirect.config.ui.form.CertificateForm)2 DomainForm (org.nhindirect.config.ui.form.DomainForm)2 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)2 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2