use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class BundlesController method assignBundlesForm.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/assignBundlesForm", method = RequestMethod.GET)
public ModelAndView assignBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/assignBundles");
}
// 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) {
}
BundleForm bform = new BundleForm();
bform.setId(0);
bform.setDomainName((String) session.getAttribute("currentDomainName"));
model.addAttribute("bundleForm", bform);
mav.setViewName("assignBundlesForm");
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class DomainController method removeBundles.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeBundles", method = RequestMethod.POST)
public ModelAndView removeBundles(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm anchorForm, Model model, @RequestParam(value = "domainId") String domainId, @RequestParam(value = "bundles") String bundles) {
ModelAndView mav = new ModelAndView();
// DEBUG
if (log.isDebugEnabled()) {
log.debug("Enter domain/removeBundles");
}
String[] bundleIds = bundles.split(":");
for (String bundle : bundleIds) {
try {
configSvc.disassociateTrustBundleFromDomain(Long.parseLong(domainId), Long.parseLong(bundle));
} catch (ConfigurationServiceException cse) {
}
}
return new ModelAndView("redirect:/config/domain?id=" + domainId + "&action=update#tab3");
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class PoliciesController method checkPolicyContent.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/checkPolicyContent", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public String checkPolicyContent(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpServletResponse response, HttpServletRequest request, Object command) throws Exception {
final org.nhindirect.policy.PolicyLexicon parseLexicon;
String jsonResponse = "";
String content = request.getParameter("content");
String lexicon = "";
if (log.isDebugEnabled()) {
log.debug("Checking policy content for format and validation");
}
lexicon = request.getParameter("lexicon");
org.nhind.config.PolicyLexicon lex = null;
// Check the file for three types of policies
if (lexicon.isEmpty()) {
lex = org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
try {
// Convert string of file contents to lexicon object
lex = org.nhind.config.PolicyLexicon.fromString(lexicon);
} catch (Exception e) {
log.error("Invalid lexicon name.");
}
}
// Determine lexicon type
if (lex.equals(org.nhind.config.PolicyLexicon.JAVA_SER)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.JAVA_SER;
} else if (lex.equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
parseLexicon = org.nhindirect.policy.PolicyLexicon.XML;
}
InputStream inStr = null;
try {
// Convert policy file upload to byte stream
inStr = new ByteArrayInputStream(content.getBytes());
// Initialize parser engine
final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(parseLexicon);
// Attempt to parse the lexicon file for validity
parser.parse(inStr);
} catch (PolicyParseException e) {
log.error("Syntax error in policy content " + " : " + e.getMessage());
jsonResponse = "{\"Status\":\"Policy content was not valid.\",\"Error\":\"" + e.getMessage() + "\"}";
} finally {
IOUtils.closeQuietly(inStr);
}
if (jsonResponse.isEmpty()) {
jsonResponse = "{\"Status\":\"Success\"}";
}
return jsonResponse;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class PoliciesController method newPolicyForm.
/*********************************
*
* New Policy Form Method
*
*********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/newPolicyForm", method = RequestMethod.GET)
public ModelAndView newPolicyForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute PolicyForm policyForm, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter policies");
}
PolicyForm pform = new PolicyForm();
pform.setId(0);
model.addAttribute("policyForm", pform);
model.addAttribute("lexiconNames", pform.getLexiconNames());
mav.setViewName("newPolicyForm");
return mav;
}
use of org.springframework.security.access.prepost.PreAuthorize in project nhin-d by DirectProject.
the class PoliciesController method checkLexiconFile.
/*********************************
*
* Check Lexicon File Method
*
*********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/checkLexiconFile", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public String checkLexiconFile(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpServletResponse response, Object command, @RequestHeader(value = "lexicon", required = false) String lexicon, MultipartHttpServletRequest request) throws FileUploadException, IOException, Exception {
final org.nhindirect.policy.PolicyLexicon parseLexicon;
String jsonResponse = "";
String uploadToString = "";
if (log.isDebugEnabled()) {
log.debug("Checking uploaded lexicon file for format and validation");
}
// Grab uploaded file from the post submission
UploadedFile ufile = new UploadedFile();
Iterator<String> itr = request.getFileNames();
MultipartFile mpf = request.getFile(itr.next());
try {
ufile.length = mpf.getBytes().length;
ufile.bytes = mpf.getBytes();
ufile.type = mpf.getContentType();
ufile.name = mpf.getOriginalFilename();
} catch (IOException e) {
}
// Convert upload content to string
uploadToString = new String(ufile.bytes);
uploadToString = JSONObject.escape(uploadToString);
lexicon = request.getParameter("lexicon");
org.nhind.config.PolicyLexicon lex = null;
// Check the file for three types of policies
if (lexicon.isEmpty()) {
lex = org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
try {
// Convert string of file contents to lexicon object
lex = org.nhind.config.PolicyLexicon.fromString(lexicon);
} catch (Exception e) {
log.error("Invalid lexicon name.");
}
}
// Determine lexicon type
if (lex.equals(org.nhind.config.PolicyLexicon.JAVA_SER)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.JAVA_SER;
} else if (lex.equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
parseLexicon = org.nhindirect.policy.PolicyLexicon.XML;
}
InputStream inStr = null;
try {
// Convert policy file upload to byte stream
inStr = new ByteArrayInputStream(ufile.bytes);
// Initialize parser engine
final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(parseLexicon);
// Attempt to parse the lexicon file for validity
parser.parse(inStr);
} catch (PolicyParseException e) {
log.error("Syntax error in policy file " + " : " + e.getMessage());
jsonResponse = "{\"Status\":\"File was not a valid file.\",\"Content\":\"" + uploadToString + "\"}";
} finally {
IOUtils.closeQuietly(inStr);
}
if (jsonResponse.isEmpty()) {
jsonResponse = "{\"Status\":\"Success\",\"Content\":\"" + uploadToString + "\"}";
}
return jsonResponse;
}
Aggregations