Search in sources :

Example 1 with Domain

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

the class DomainController method removeAddresses.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeaddresses", method = RequestMethod.POST)
public ModelAndView removeAddresses(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    final String domAttr = (String) session.getAttribute("currentDomainName");
    ModelAndView mav = new ModelAndView();
    if (log.isDebugEnabled())
        log.debug("Enter domain/removeaddresses");
    if (simpleForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
    }
    Domain dom = null;
    try {
        dom = domainService.getDomain(domAttr);
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    //+simpleForm.getId();
    String strid = "" + dom.getDomainName();
    String domname = "";
    if (dom != null) {
        domname = dom.getDomainName();
        if (addressService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("delete") || actionPath.equalsIgnoreCase("remove selected Addresses")) && simpleForm.getRemove() != null) {
            int cnt = simpleForm.getRemove().size();
            if (log.isDebugEnabled())
                log.debug("removing addresses for domain with name: " + domname);
            try {
                for (int x = 0; x < cnt; x++) {
                    String removeid = simpleForm.getRemove().get(x);
                    Collection<Address> t = dom.getAddresses();
                    for (Iterator<Address> iter = t.iterator(); iter.hasNext(); ) {
                        Address ts = (Address) iter.next();
                        if (ts.getId() == Long.parseLong(removeid)) {
                            dom.getAddresses().remove(ts);
                            if (addressService != null) {
                                addressService.deleteAddress(ts.getEmailAddress());
                                try {
                                    dom = domainService.getDomain(strid);
                                } catch (ServiceException e) {
                                    e.printStackTrace();
                                }
                                break;
                            }
                        }
                    }
                }
                if (log.isDebugEnabled())
                    log.debug(" Trying to update the domain with removed addresses");
                domainService.updateDomain(dom);
                try {
                    dom = domainService.getDomain(strid);
                } catch (ServiceException e) {
                    e.printStackTrace();
                }
                if (log.isDebugEnabled())
                    log.debug(" SUCCESS Trying to update the domain with removed addresses");
                final AddressForm addrform = new AddressForm();
                addrform.setId(dom.getId());
                addrform.setDomainName(dom.getDomainName());
                model.addAttribute("addressForm", addrform);
                // BEGIN: temporary code for mocking purposes
                String owner = "";
                model.addAttribute("addressesResults", dom.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 (Exception e) {
                }
                model.addAttribute("certificatesResults", certlist);
                // convert Anchor to AnchorForm
                Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
                // now set anchorsResults
                model.addAttribute("anchorsResults", convertedanchors);
            // END: temporary code for mocking purposes
            } catch (ServiceException e) {
                if (log.isDebugEnabled())
                    log.error(e);
            }
        } else if (domainService != null && (actionPath.equalsIgnoreCase("newaddress") || actionPath.equalsIgnoreCase("add address"))) {
            // insert the new address into the Domain list of Addresses
            final String anEmail = simpleForm.getPostmasterEmail();
            if (log.isDebugEnabled())
                log.debug(" Trying to add address: " + anEmail);
            final Address e = new Address();
            e.setEmailAddress(anEmail);
            dom.getAddresses().add(e);
            simpleForm.setPostmasterEmail("");
            try {
                domainService.updateDomain(dom);
                if (log.isDebugEnabled())
                    log.debug(" After attempt to insert new email address ");
            } catch (ServiceException ed) {
                if (log.isDebugEnabled())
                    log.error(ed);
            }
        }
    }
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
    mav.addObject("statusList", EntityStatus.getEntityStatusList());
    final String action = "Update";
    model.addAttribute("action", action);
    DomainForm form = (DomainForm) session.getAttribute("domainForm");
    if (form == null) {
        form = new DomainForm();
        form.populate(dom);
    }
    model.addAttribute("domainForm", form);
    mav.setViewName("domain");
    String owner = "";
    // certificate and anchor forms and results
    try {
        if (owner != null && !owner.equalsIgnoreCase("")) {
            final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
            model.addAttribute("certificatesResults", certs);
            final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
            // convert Anchor to AnchorForm
            final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
            // now set anchorsResults
            model.addAttribute("anchorsResults", convertedanchors);
        }
        final CertificateForm cform = new CertificateForm();
        model.addAttribute("certificateForm", cform);
        final AnchorForm aform = new AnchorForm();
        //aform.setId(dom.getId());
        aform.setDomainName(dom.getDomainName());
        model.addAttribute("anchorForm", aform);
    } catch (ServiceException e1) {
        e1.printStackTrace();
    }
    model.addAttribute("simpleForm", simpleForm);
    //simpleForm.getId();
    strid = "" + dom.getDomainName();
    if (log.isDebugEnabled())
        log.debug(" the value of id of simpleform is: " + strid);
    return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab1");
//return mav;
}
Also used : CertificateForm(org.nhindirect.config.ui.form.CertificateForm) AnchorForm(org.nhindirect.config.ui.form.AnchorForm) Address(org.nhindirect.config.model.Address) ModelAndView(org.springframework.web.servlet.ModelAndView) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DomainForm(org.nhindirect.config.ui.form.DomainForm) SearchDomainForm(org.nhindirect.config.ui.form.SearchDomainForm) 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) 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 2 with Domain

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

the class EntityModelConversion method toEntityDomain.

public static org.nhindirect.config.store.Domain toEntityDomain(Domain domain) {
    final org.nhindirect.config.store.Domain retVal = new org.nhindirect.config.store.Domain();
    final Collection<org.nhindirect.config.store.Address> addresses = new ArrayList<org.nhindirect.config.store.Address>();
    if (domain.getAddresses() != null) {
        for (Address address : domain.getAddresses()) {
            addresses.add(toEntityAddress(address));
        }
    }
    retVal.setAddresses(addresses);
    retVal.setCreateTime(domain.getCreateTime());
    retVal.setDomainName(domain.getDomainName());
    retVal.setId(domain.getId());
    if (domain.getPostmasterAddress() != null)
        retVal.setPostMasterEmail(domain.getPostmasterAddress().getEmailAddress());
    if (domain.getStatus() != null)
        retVal.setStatus(org.nhindirect.config.store.EntityStatus.valueOf(domain.getStatus().toString()));
    retVal.setUpdateTime(domain.getUpdateTime());
    return retVal;
}
Also used : Address(org.nhindirect.config.model.Address) ArrayList(java.util.ArrayList) Domain(org.nhindirect.config.model.Domain)

Example 3 with Domain

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

the class RESTSmtpAgentConfig method buildDomains.

@Override
protected void buildDomains() {
    domains = new ArrayList<String>();
    domainPostmasters = new HashMap<String, DomainPostmaster>();
    // get the domain list first
    try {
        lookedupRESTServiceDomains = domainService.searchDomains("", null);
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting domains list: " + e.getMessage(), e);
    }
    if (lookedupRESTServiceDomains != null) {
        for (Domain dom : lookedupRESTServiceDomains) {
            domains.add(dom.getDomainName());
            try {
                String configuredAddress = (dom.getPostmasterAddress() == null) ? "" : dom.getPostmasterAddress().getEmailAddress();
                configuredAddress = (configuredAddress == null || configuredAddress.trim().isEmpty()) ? DomainPostmaster.getDefaultPostmaster(dom.getDomainName()) : configuredAddress;
                domainPostmasters.put(dom.getDomainName().toUpperCase(Locale.getDefault()), new DomainPostmaster(dom.getDomainName(), new InternetAddress(configuredAddress)));
            } catch (AddressException e) {
            }
        }
    }
    if (domains.size() == 0)
        throw new SmtpAgentException(SmtpAgentError.MissingDomains);
    // now get the trust anchors
    buildTrustAnchorResolver();
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) DomainPostmaster(org.nhindirect.gateway.smtp.DomainPostmaster) Domain(org.nhindirect.config.model.Domain) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 4 with Domain

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

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

the class EntityModelConversion method toModelDomain.

public static Domain toModelDomain(org.nhindirect.config.store.Domain domain) {
    final Domain retVal = new Domain();
    final Collection<Address> addresses = new ArrayList<Address>();
    if (domain.getAddresses() != null) {
        for (org.nhindirect.config.store.Address address : domain.getAddresses()) {
            addresses.add(toModelAddress(address));
        }
    }
    retVal.setAddresses(addresses);
    retVal.setCreateTime(domain.getCreateTime());
    retVal.setDomainName(domain.getDomainName());
    retVal.setId(domain.getId());
    // get the postmaster address
    if (domain.getPostMasterEmail() != null && !domain.getPostMasterEmail().isEmpty()) {
        System.out.println("Postmaster email address: " + domain.getPostMasterEmail());
        if ((domain.getAddresses().size() > 0) && (domain.getPostmasterAddressId() != null) && (domain.getPostmasterAddressId() > 0)) {
            for (org.nhindirect.config.store.Address address : domain.getAddresses()) {
                if (address.getId().equals(domain.getPostmasterAddressId())) {
                    retVal.setPostmasterAddress(toModelAddress(address));
                    break;
                }
            }
        }
    }
    if (domain.getStatus() != null)
        retVal.setStatus(EntityStatus.valueOf(domain.getStatus().toString()));
    retVal.setUpdateTime(domain.getUpdateTime());
    return retVal;
}
Also used : Address(org.nhindirect.config.model.Address) ArrayList(java.util.ArrayList) Domain(org.nhindirect.config.model.Domain)

Aggregations

Domain (org.nhindirect.config.model.Domain)14 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)10 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ModelAndView (org.springframework.web.servlet.ModelAndView)10 ArrayList (java.util.ArrayList)9 Anchor (org.nhindirect.config.model.Anchor)9 TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)9 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 X509Certificate (java.security.cert.X509Certificate)8 AddressForm (org.nhindirect.config.ui.form.AddressForm)8 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)8 CertificateForm (org.nhindirect.config.ui.form.CertificateForm)8 DomainForm (org.nhindirect.config.ui.form.DomainForm)8 IOException (java.io.IOException)7 Certificate (org.nhindirect.config.model.Certificate)7 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)5 Address (org.nhindirect.config.model.Address)4 HashMap (java.util.HashMap)3