use of org.nhindirect.config.ui.form.DomainForm 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;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method removeAnchors.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeanchors", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled())
log.debug("Enter domain/removeanchor");
if (simpleForm.getRemove() != null) {
if (log.isDebugEnabled())
log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
}
final String domAttr = (String) session.getAttribute("currentDomainName");
//simpleForm.getId();
String strid = "" + domAttr;
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
String owner = "";
String domname = "";
if (dom != null) {
domname = dom.getDomainName();
owner = domname;
}
if (anchorService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteanchors") || actionPath.equalsIgnoreCase("Remove Selected Anchors")) && simpleForm.getRemove() != null) {
int cnt = simpleForm.getRemove().size();
if (log.isDebugEnabled())
log.debug("removing anchors for domain with name: " + domname);
try {
// get list of certificates for this domain
final Collection<Anchor> certs = anchorService.getAnchorsForOwner(owner, false, false, "");
final ArrayList<Long> certtoberemovedlist = new ArrayList<Long>();
// now iterate over each one and remove the appropriate ones
for (int x = 0; x < cnt; x++) {
String removeid = simpleForm.getRemove().get(x);
for (Iterator<Anchor> iter = certs.iterator(); iter.hasNext(); ) {
Anchor t = (Anchor) iter.next();
//rest of the code block removed
if (t.getId() == Long.parseLong(removeid)) {
if (log.isDebugEnabled()) {
log.debug(" ");
log.debug("domain address id: " + t.getId());
log.debug(" ");
}
// create a collection of matching anchor ids
certtoberemovedlist.add(t.getId());
break;
}
}
}
// with the collection of anchor ids now remove them from the configSvc
if (log.isDebugEnabled())
log.debug(" Trying to remove anchors from database");
anchorService.deleteAnchorsByIds(certtoberemovedlist);
if (log.isDebugEnabled())
log.debug(" SUCCESS Trying to update the domain with removed anchors");
final AddressForm addrform = new AddressForm();
addrform.setId(dom.getId());
model.addAttribute("addressForm", addrform);
} catch (ServiceException e) {
if (log.isDebugEnabled())
log.error(e);
}
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
// BEGIN: temporary code for mocking purposes
final CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
final AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
model.addAttribute("addressesResults", dom.getAddresses());
mav.setViewName("domain");
// the Form's default button action
String action = "Update";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("action", action);
// SETTING THE ADDRESSES OBJECT
model.addAttribute("addressesResults", form.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) {
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
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
model.addAttribute("simpleForm", simpleForm);
strid = "" + simpleForm.getId();
if (log.isDebugEnabled())
log.debug(" the value of id of simpleform is: " + strid);
return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab2");
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method saveDomain.
/**
* Execute the save and return the results
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/saveupdate", method = RequestMethod.POST)
public ModelAndView saveDomain(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @RequestParam(value = "submitType") String actionPath, @ModelAttribute("domainForm") DomainForm form, Model model) {
if (log.isDebugEnabled())
log.debug("Enter");
if (log.isDebugEnabled())
log.debug("Entered saveDomain");
if (log.isDebugEnabled())
log.debug("The value of actionPath: " + actionPath);
ModelAndView mav = new ModelAndView();
if (actionPath.equalsIgnoreCase("cancel")) {
if (log.isDebugEnabled()) {
log.debug("trying to cancel from saveupdate");
}
return new ModelAndView("redirect:/config/main");
} else if ((actionPath.equalsIgnoreCase("update") || actionPath.equalsIgnoreCase("add"))) {
HashMap<String, String> msgs = new HashMap<String, String>();
mav.addObject("msgs", msgs);
mav.setViewName("domain");
try {
if (actionPath.equalsIgnoreCase("add")) {
// Add domain to configuration service
domainService.addDomain(form.getDomainFromForm());
session.setAttribute("currentDomainName", form.getDomainName());
final List<Domain> result = new ArrayList<Domain>(domainService.searchDomains(form.getDomainName(), form.getStatus()));
if (form.getSelectedBundles() != "") {
// Associate trust bundles if selected
final String selBundle = form.getSelectedBundles().replace("wHiTeSpAcE", " ");
final String[] bundles = selBundle.split(",");
int bundleCount = bundles.length;
log.debug("# of bundles associated: " + bundleCount);
// Associate trust bundles to Domain
for (int i = 0; i < bundleCount; i++) {
/*
* TODO: Add incoming and outgoing indicators
*/
final String[] bundleString = bundles[i].split("\\|\\|\\|\\|");
if (bundleString[1].equals("both")) {
bundleService.associateTrustBundleToDomain(bundleString[0], result.get(0).getDomainName(), true, true);
} else if (bundleString[1].equals("in")) {
bundleService.associateTrustBundleToDomain(bundleString[0], result.get(0).getDomainName(), true, false);
} else if (bundleString[1].equals("out")) {
bundleService.associateTrustBundleToDomain(bundleString[0], result.get(0).getDomainName(), false, true);
} else {
bundleService.associateTrustBundleToDomain(bundleString[0], result.get(0).getDomainName(), false, false);
}
log.error("Added Bundle ID #" + bundles[i]);
}
}
if (result.size() > 0) {
form = new DomainForm();
form.populate(result.get(0));
form.setDomainName(result.get(0).getDomainName());
msgs.put("msg", "domain.add.success");
}
} else if (actionPath.equalsIgnoreCase("update")) {
domainService.updateDomain(form.getDomainFromForm());
final List<Domain> result = new ArrayList<Domain>(domainService.searchDomains(form.getDomainName(), form.getStatus()));
if (result.size() > 0) {
form = new DomainForm();
form.populate(result.get(0));
}
msgs.put("msg", "domain.update.success");
}
final AddressForm addrform = new AddressForm();
addrform.setId(form.getDomainFromForm().getId());
model.addAttribute("domainForm", form);
model.addAttribute("addressForm", addrform);
final CertificateForm cform = new CertificateForm();
cform.setId(form.getDomainFromForm().getId());
AnchorForm aform = new AnchorForm();
aform.setId(form.getDomainFromForm().getId());
model.addAttribute("certificateForm", cform);
model.addAttribute("anchorForm", aform);
SimpleForm simple = new SimpleForm();
simple.setId(form.getDomainFromForm().getId());
model.addAttribute("simpleForm", simple);
// once certificates and anchors are available change code accordingly
// begin: add these dummy records too
final String owner = form.getDomainFromForm().getPostmasterAddress().getEmailAddress();
try {
if (owner != null && !owner.equalsIgnoreCase("")) {
// BEGIN: temporary code for mocking purposes
Collection<Certificate> certlist = null;
try {
certlist = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certlist);
} catch (ServiceException e) {
e.printStackTrace();
}
Collection<Anchor> anchorlist = null;
anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
// convert Anchor to AnchorForm
Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
}
} catch (Exception e) {
e.printStackTrace();
}
// END: temporary code for mocking purposes
// end: add these dummy records too
model.addAttribute("addressesResults", form.getDomainFromForm().getAddresses());
model.addAttribute("action", "update");
if (log.isDebugEnabled()) {
log.debug("Stored domain: " + form.getDomainFromForm().toString());
}
} catch (ServiceException e) {
log.error(e);
msgs.put("domainService", "domainService.add.error");
} catch (Exception ed) {
log.error(ed);
}
}
if (log.isDebugEnabled())
log.debug("Exit");
return new ModelAndView("redirect:/config/domain?id=" + form.getDomainName());
//return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method addAnchor.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addanchor", method = RequestMethod.POST)
public ModelAndView addAnchor(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm anchorForm, Model model, @RequestParam(value = "submitType") String actionPath, @RequestParam(value = "id") String id) {
final String domAttr = (String) session.getAttribute("currentDomainName");
ModelAndView mav = new ModelAndView();
String strid = "";
//anchorForm.getId();
strid = "" + domAttr;
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
if (log.isDebugEnabled())
log.debug("Enter domain/addanchor");
if (actionPath.equalsIgnoreCase("newanchor") || actionPath.equalsIgnoreCase("add anchor")) {
strid = "" + anchorForm.getId();
String owner = "";
if (dom != null) {
owner = dom.getDomainName();
}
// insert the new address into the Domain list of Addresses
if (log.isDebugEnabled())
log.debug("beginning to evaluate filedata");
try {
if (!anchorForm.getFileData().isEmpty()) {
final byte[] bytes = anchorForm.getFileData().getBytes();
String theUser = "";
if (bytes != null) {
// get the owner from the certificate information
// first transform into a certificate
CertContainer cont = toCertContainer(bytes);
if (cont != null && cont.getCert() != null) {
// now get the owner info from the cert
theUser = getTrustedEntityName(cont.getCert().getSubjectX500Principal());
anchorForm.setTrusteddomainoruser(theUser);
}
}
// store the bytes somewhere
final Anchor ank = new Anchor();
ank.setCertificateData(bytes);
if (log.isDebugEnabled())
log.debug("incoming is: " + anchorForm.isIncoming() + " and outgoing is: " + anchorForm.isOutgoing());
ank.setIncoming(anchorForm.isIncoming());
ank.setOutgoing(anchorForm.isOutgoing());
ank.setOwner(owner);
ank.setStatus(anchorForm.getStatus());
anchorService.addAnchor(ank);
if (log.isDebugEnabled())
log.debug("store the anchor certificate into database");
} else {
if (log.isDebugEnabled())
log.debug("DO NOT store the anchor certificate into database BECAUSE THERE IS NO FILE");
}
} catch (ConfigurationServiceException ed) {
if (log.isDebugEnabled())
log.error(ed);
} catch (Exception e) {
if (log.isDebugEnabled())
log.error(e.getMessage());
e.printStackTrace();
}
// certificate and anchor forms and results
try {
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certs);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
} catch (Exception e1) {
e1.printStackTrace();
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
SimpleForm simple = new SimpleForm();
simple.setId(dom.getId());
simple.setDomainName(dom.getDomainName());
model.addAttribute("simpleForm", simple);
model.addAttribute("addressesResults", dom.getAddresses());
mav.setViewName("domain");
// the Form's default button action
String action = "Update";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
}
AddressForm addressForm2 = new AddressForm();
addressForm2.setDisplayName("");
addressForm2.setEndpoint("");
addressForm2.setEmailAddress("");
addressForm2.setType("");
addressForm2.setId(Long.parseLong(strid));
model.addAttribute("addressForm", addressForm2);
return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab2");
//return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class MainController method newDomain.
/**
* Set up to display a new Domain page
* @param requestedWith
* @param session
* @param model
* @return
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/new", method = RequestMethod.GET)
public ModelAndView newDomain(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, Model model) {
if (log.isDebugEnabled())
log.debug("Enter");
ModelAndView mav = new ModelAndView();
mav.setViewName("domain");
model.addAttribute(new DomainForm());
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
Aggregations