use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class RegisteredServiceSimpleFormController method saveService.
/**
* Adds the service to the Service Registry.
*
* @param request the request
* @param response the response
* @param result the result
* @param service the edit bean
*/
@PostMapping(value = "saveService.html")
public void saveService(final HttpServletRequest request, final HttpServletResponse response, @RequestBody final RegisteredServiceEditBean.ServiceData service, final BindingResult result) {
try {
if (StringUtils.isNotBlank(service.getAssignedId())) {
final RegisteredService svc = this.servicesManager.findServiceBy(Long.parseLong(service.getAssignedId()));
if (svc != null) {
this.servicesManager.delete(svc.getId());
}
}
final RegisteredService svcToUse = this.registeredServiceFactory.createRegisteredService(service);
final RegisteredService newSvc = this.servicesManager.save(svcToUse);
LOGGER.info("Saved changes to service [{}]", svcToUse.getId());
final Map<String, Object> model = new HashMap<>();
model.put("id", newSvc.getId());
model.put("status", HttpServletResponse.SC_OK);
JsonUtils.render(model, response);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class TicketsResource method createServiceTicket.
/**
* Create new service ticket.
*
* @param requestBody service application/x-www-form-urlencoded value
* @param tgtId ticket granting ticket id URI path param
* @return {@link ResponseEntity} representing RESTful response
*/
@PostMapping(value = "/v1/tickets/{tgtId:.+}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createServiceTicket(@RequestBody final MultiValueMap<String, String> requestBody, @PathVariable("tgtId") final String tgtId) {
try {
final String serviceId = requestBody.getFirst(CasProtocolConstants.PARAMETER_SERVICE);
final AuthenticationResultBuilder builder = new DefaultAuthenticationResultBuilder(this.authenticationSystemSupport.getPrincipalElectionStrategy());
final Service service = this.webApplicationServiceFactory.createService(serviceId);
final AuthenticationResult authenticationResult = builder.collect(this.ticketRegistrySupport.getAuthenticationFrom(tgtId)).build(service);
final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(tgtId, service, authenticationResult);
return new ResponseEntity<>(serviceTicketId.getId(), HttpStatus.OK);
} catch (final InvalidTicketException e) {
return new ResponseEntity<>("TicketGrantingTicket could not be found", HttpStatus.NOT_FOUND);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.springframework.web.bind.annotation.PostMapping in project spring-boot by spring-projects.
the class MessageController method create.
@PostMapping
public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) {
if (result.hasErrors()) {
ModelAndView mav = new ModelAndView("messages/form");
mav.addObject("formErrors", result.getAllErrors());
mav.addObject("fieldErrors", getFieldErrors(result));
return mav;
}
message = this.messageRepository.save(message);
redirect.addFlashAttribute("globalMessage", "Successfully created a new message");
return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
}
use of org.springframework.web.bind.annotation.PostMapping in project spring-boot by spring-projects.
the class SampleController method olleh.
@PostMapping("/")
@ResponseBody
public Map<String, Object> olleh(@Validated Message message) {
Map<String, Object> model = new LinkedHashMap<>();
model.put("message", message.getValue());
model.put("title", "Hello Home");
model.put("date", new Date());
return model;
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class SettingsController method post.
@PostMapping
public String post(@RequestParam(required = false) String tags, @RequestParam(required = false) String latlng, @RequestParam(required = false) String replyEmailsOn, @RequestParam(required = false) String commentEmailsOn, HttpServletRequest req) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
if (!StringUtils.isBlank(tags)) {
Set<String> ts = new LinkedHashSet<String>();
for (String tag : tags.split(",")) {
if (!StringUtils.isBlank(tag) && ts.size() <= MAX_FAV_TAGS) {
ts.add(tag);
}
}
authUser.setFavtags(new LinkedList<String>(ts));
}
if (!StringUtils.isBlank(latlng)) {
authUser.setLatlng(latlng);
}
authUser.setReplyEmailsEnabled(Boolean.valueOf(replyEmailsOn));
authUser.setCommentEmailsEnabled(Boolean.valueOf(commentEmailsOn));
authUser.update();
}
return "redirect:" + settingslink;
}
Aggregations