use of org.nhindirect.config.model.TrustBundleDomainReltn in project nhin-d by DirectProject.
the class TrustBundleResource method getTrustBundlesByDomain.
/**
* Gets all trust bundles associated to a domain.
* @param domainName The name of the domain to fetch trust bundles for.
* @param fetchAnchors Indicates if the retrieval should also include the trust anchors in the bundle. When only needing bundle names,
* this parameter should be set to false for better performance.
* @return A JSON representation of a collection of trust bundle that are associated to the given domain. Returns a status of
* 404 if a domain with the given name does not exist or a status of 404 if no trust bundles are associated with the given name.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("domains/{domainName}")
public Response getTrustBundlesByDomain(@PathParam("domainName") String domainName, @QueryParam("fetchAnchors") @DefaultValue("true") boolean fetchAnchors) {
// make sure the domain exists
org.nhindirect.config.store.Domain entityDomain;
try {
entityDomain = domainDao.getDomainByName(domainName);
if (entityDomain == null)
return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up domain.", e);
return Response.serverError().cacheControl(noCache).build();
}
Collection<org.nhindirect.config.store.TrustBundleDomainReltn> retBundles = null;
try {
retBundles = bundleDao.getTrustBundlesByDomain(entityDomain.getId());
if (retBundles.isEmpty())
return Response.noContent().cacheControl(noCache).build();
} catch (Throwable e) {
log.error("Error looking up trust bundles", e);
return Response.serverError().cacheControl(noCache).build();
}
final Collection<TrustBundleDomainReltn> modelBundles = new ArrayList<TrustBundleDomainReltn>();
for (org.nhindirect.config.store.TrustBundleDomainReltn bundleReltn : retBundles) {
if (!fetchAnchors)
bundleReltn.getTrustBundle().setTrustBundleAnchors(new ArrayList<TrustBundleAnchor>());
final TrustBundleDomainReltn newReltn = new TrustBundleDomainReltn();
newReltn.setIncoming(bundleReltn.isIncoming());
newReltn.setOutgoing(bundleReltn.isOutgoing());
newReltn.setDomain(EntityModelConversion.toModelDomain(bundleReltn.getDomain()));
newReltn.setTrustBundle(EntityModelConversion.toModelTrustBundle(bundleReltn.getTrustBundle()));
modelBundles.add(newReltn);
}
final GenericEntity<Collection<TrustBundleDomainReltn>> entity = new GenericEntity<Collection<TrustBundleDomainReltn>>(modelBundles) {
};
return Response.ok(entity).cacheControl(noCache).build();
}
use of org.nhindirect.config.model.TrustBundleDomainReltn in project nhin-d by DirectProject.
the class DomainController method updateBundleDirection.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/updateBundleDirection", method = RequestMethod.POST)
public ModelAndView updateBundleDirection(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @RequestParam(required = true) String domainName, @RequestParam(required = true) String bundle, @RequestParam(required = true) String direction, @RequestParam(required = true) String directionValue, HttpSession session, Model model) {
Collection<TrustBundleDomainReltn> bundles = null;
try {
bundles = bundleService.getTrustBundlesByDomain(domainName, false);
} catch (ServiceException ex) {
Logger.getLogger(DomainController.class.getName()).log(Level.SEVERE, null, ex);
}
for (TrustBundleDomainReltn bundleReltn : bundles) {
if (bundleReltn.getId() == Long.parseLong(bundle)) {
if (direction.toLowerCase().equals("incoming")) {
if (Integer.parseInt(directionValue) == 1) {
bundleReltn.setIncoming(true);
} else {
bundleReltn.setIncoming(false);
}
} else {
if (Integer.parseInt(directionValue) == 1) {
bundleReltn.setOutgoing(true);
} else {
bundleReltn.setOutgoing(false);
}
}
}
}
final ModelAndView mav = new ModelAndView();
mav.setViewName("updateBundleDirection");
return mav;
}
use of org.nhindirect.config.model.TrustBundleDomainReltn 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);
}
use of org.nhindirect.config.model.TrustBundleDomainReltn in project nhin-d by DirectProject.
the class BundlesController method addMoreBundlesForm.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addMoreBundlesForm", method = RequestMethod.GET)
public ModelAndView addMoreBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, @RequestParam(value = "domainName") String domainName, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/addMoreBundlesForm");
}
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = new ArrayList<TrustBundle>();
Collection<TrustBundle> newBundles = new ArrayList<TrustBundle>();
final Collection<TrustBundleDomainReltn> bundleRelationships = bundleService.getTrustBundlesByDomain(domainName, false);
final Collection<TrustBundle> allBundles = bundleService.getTrustBundles(false);
boolean bundleMatch = false;
if (bundleRelationships != null && !bundleRelationships.isEmpty()) {
for (TrustBundleDomainReltn relationship : bundleRelationships) {
trustBundles.add(relationship.getTrustBundle());
}
for (TrustBundle bundle : allBundles) {
bundleMatch = false;
for (TrustBundle subBundle : trustBundles) {
if (subBundle.getId() == bundle.getId()) {
bundleMatch = true;
}
}
if (!bundleMatch) {
newBundles.add(bundle);
}
}
} else {
newBundles = bundleService.getTrustBundles(false);
}
//if(trustBundles != null) {
model.addAttribute("trustBundles", newBundles);
//}
} catch (ServiceException e1) {
}
model.addAttribute("domainName", domainName);
BundleForm bform = new BundleForm();
bform.setId(0);
bform.setDomainName((String) session.getAttribute("currentDomainName"));
model.addAttribute("bundleForm", bform);
mav.setViewName("addMoreBundlesForm");
return mav;
}
use of org.nhindirect.config.model.TrustBundleDomainReltn 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;
}
Aggregations