use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class DNSController method addSetting.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addDNSRecord", method = RequestMethod.POST)
public ModelAndView addSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("AdnsForm") DNSEntryForm AdnsForm, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) throws ServiceException {
if (log.isDebugEnabled())
log.debug("Enter");
// A records
if (AdnsForm != null && !AdnsForm.getName().equalsIgnoreCase("") && AdnsForm.getTtl() != 0L && !AdnsForm.getDest().equalsIgnoreCase("")) {
AdnsForm.setType("A");
DNSEntryForm.toDNSRecord(AdnsForm);
}
model.addAttribute("AdnsForm", new DNSEntryForm());
// A4 records
if (AAdnsForm != null && !AAdnsForm.getName().equalsIgnoreCase("") && AAdnsForm.getTtl() != 0L && !AAdnsForm.getDest().equalsIgnoreCase("")) {
AAdnsForm.setType("AAAA");
DNSEntryForm.toDNSRecord(AAdnsForm);
}
model.addAttribute("AAdnsForm", new DNSEntryForm());
// CNAME records
if (CdnsForm != null && !CdnsForm.getName().equalsIgnoreCase("") && CdnsForm.getTtl() != 0L && !CdnsForm.getDest().equalsIgnoreCase("")) {
CdnsForm.setType("CNAME");
DNSEntryForm.toDNSRecord(CdnsForm);
}
model.addAttribute("CdnsForm", new DNSEntryForm());
// MX records
if (MXdnsForm != null && !MXdnsForm.getName().equalsIgnoreCase("") && MXdnsForm.getTtl() != 0L && !MXdnsForm.getDest().equalsIgnoreCase("")) {
MXdnsForm.setType("MX");
DNSEntryForm.toDNSRecord(MXdnsForm);
}
model.addAttribute("MXdnsForm", new DNSEntryForm());
// CERT records
if (CertdnsForm != null && !CertdnsForm.getName().equalsIgnoreCase("") && CertdnsForm.getTtl() != 0L && !CertdnsForm.getDest().equalsIgnoreCase("")) {
CertdnsForm.setType("CERT");
DNSEntryForm.toDNSRecord(CertdnsForm);
}
// SRV records
if (SrvdnsForm != null && !SrvdnsForm.getName().equalsIgnoreCase("") && SrvdnsForm.getTtl() != 0L && !SrvdnsForm.getDest().equalsIgnoreCase("")) {
SrvdnsForm.setType("SRV");
DNSEntryForm.toDNSRecord(SrvdnsForm);
}
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
ModelAndView mav = new ModelAndView("dns");
refreshModelFromService(model);
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class DNSController method addA4Setting.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addA4DNSRecord", method = RequestMethod.POST)
public ModelAndView addA4Setting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter");
// A records
if (AAdnsForm != null && !AAdnsForm.getName().equalsIgnoreCase("") && AAdnsForm.getTtl() != 0L && !AAdnsForm.getDest().equalsIgnoreCase("")) {
try {
dnsService.addDNSRecord(DNSEntryForm.createA4Record(AAdnsForm.getName(), AAdnsForm.getTtl(), AAdnsForm.getDest()));
} catch (ServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("AdnsForm", new DNSEntryForm());
model.addAttribute("AAdnsForm", new DNSEntryForm());
model.addAttribute("CdnsForm", new DNSEntryForm());
model.addAttribute("MXdnsForm", new DNSEntryForm());
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
ModelAndView mav = new ModelAndView("dns");
refreshModelFromService(model);
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class DNSController method addMXSetting.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addMXDNSRecord", method = RequestMethod.POST)
public ModelAndView addMXSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter");
// A records
if (MXdnsForm != null && !MXdnsForm.getName().equalsIgnoreCase("") && MXdnsForm.getTtl() != 0L && !MXdnsForm.getDest().equalsIgnoreCase("")) {
try {
dnsService.addDNSRecord(DNSEntryForm.entityToModelRecord(DNSRecordUtils.createMXRecord(MXdnsForm.getName(), MXdnsForm.getDest(), MXdnsForm.getTtl(), MXdnsForm.getPriority())));
} catch (ServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("AdnsForm", new DNSEntryForm());
model.addAttribute("AAdnsForm", new DNSEntryForm());
model.addAttribute("CdnsForm", new DNSEntryForm());
model.addAttribute("MXdnsForm", new DNSEntryForm());
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
final ModelAndView mav = new ModelAndView("dns");
refreshModelFromService(model);
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class BundlesController method addBundle.
/*********************************
*
* Add Bundle Method
*
*********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addbundle", method = RequestMethod.POST)
public ModelAndView addBundle(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm bundleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final ModelAndView mav = new ModelAndView();
// Debug Statement
if (log.isDebugEnabled())
log.debug("Enter Add Trust Bundle");
if (actionPath.equalsIgnoreCase("cancel")) {
if (log.isDebugEnabled()) {
log.debug("trying to cancel from saveupdate");
}
// If cancel then clear form
final SearchDomainForm form2 = (SearchDomainForm) session.getAttribute("searchDomainForm");
model.addAttribute(form2 != null ? form2 : new SearchDomainForm());
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.setViewName("main");
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
return mav;
}
if (actionPath.equalsIgnoreCase("newbundle") || actionPath.equalsIgnoreCase("add bundle")) {
Boolean formValidated = true;
if (log.isDebugEnabled()) {
log.debug("Beginning to process signing certificate file");
}
model.addAttribute("signingCertError", false);
model.addAttribute("URLError", false);
final TrustBundle trustBundle = new TrustBundle();
String bundleName = bundleForm.getBundleName();
trustBundle.setBundleName(bundleName);
// Convert Hours to Seconds for backend
trustBundle.setRefreshInterval(bundleForm.getRefreshInterval() * 3600);
// Check if signing certificate is uploaded
if (!bundleForm.getFileData().isEmpty()) {
byte[] bytes = bundleForm.getFileData().getBytes();
final String fileType = bundleForm.getFileData().getContentType();
if (!fileType.matches("application/x-x509-ca-cert") && !fileType.matches("application/x-x509-user-cert") && !fileType.matches("application/pkix-cert")) {
model.addAttribute("signingCertError", true);
formValidated = false;
} else {
try {
trustBundle.setSigningCertificateData(bytes);
} catch (Exception ce) {
}
}
} else {
if (log.isDebugEnabled())
log.debug("DO NOT store the bundle into database BECAUSE THERE IS NO FILE");
}
// Check for empty bundle name
if (bundleName.isEmpty()) {
model.addAttribute("EmptyBundleError", true);
formValidated = false;
} else {
// Check if trust bundle name is already used
TrustBundle dupeBundle = null;
try {
dupeBundle = bundleService.getTrustBundle(bundleName);
} catch (ServiceException cse) {
log.error("Could not get bundle information from config service");
}
if (dupeBundle != null) {
model.addAttribute("DupeBundleError", true);
formValidated = false;
}
}
// Check for valid URL
final String trustURL = bundleForm.getTrustURL();
try {
new URL(trustURL);
} catch (MalformedURLException mu) {
model.addAttribute("URLError", true);
formValidated = false;
}
if (formValidated) {
trustBundle.setBundleURL(trustURL);
try {
trustBundle.setCheckSum("");
bundleService.addTrustBundle(trustBundle);
if (log.isDebugEnabled()) {
log.debug("Add Trust Bundle to Database");
}
} catch (Exception e) {
if (log.isDebugEnabled())
log.error(e);
e.printStackTrace();
}
final BundleForm bform = new BundleForm();
model.addAttribute("bundleForm", bform);
}
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
if (trustBundles != null) {
model.addAttribute("trustBundles", trustBundles);
}
} catch (ServiceException e1) {
}
model.addAttribute("bundlesSelected");
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.setViewName("bundles");
}
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class BundlesController method removeCertificates.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removebundle", method = RequestMethod.POST)
public ModelAndView removeCertificates(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
final ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/removebundle");
}
if (simpleForm.getBundlesSelected() != null) {
if (log.isDebugEnabled()) {
log.debug("Bundles marked for removal: " + simpleForm.getBundlesSelected().toString());
}
}
if (bundleService != null && simpleForm != null && simpleForm.getBundlesSelected() != null) {
final int bundleCount = simpleForm.getBundlesSelected().size();
if (log.isDebugEnabled()) {
log.debug("Removing Bundles");
}
for (int i = 0; i < bundleCount; i++) {
final String bundleName = simpleForm.getBundlesSelected().get(i);
log.error(bundleName);
// Delete Trust Bundle(s)
try {
bundleService.deleteTrustBundle(bundleName);
} catch (ServiceException cse) {
log.error("Problem removing bundles");
}
}
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
final BundleForm bform = new BundleForm();
bform.setId(0);
model.addAttribute("bundleForm", bform);
mav.setViewName("bundles");
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
if (trustBundles != null) {
model.addAttribute("trustBundles", trustBundles);
}
} catch (ServiceException e1) {
}
return mav;
}
Aggregations