Search in sources :

Example 46 with PostMapping

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);
    }
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) HashMap(java.util.HashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 47 with PostMapping

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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) DefaultAuthenticationResultBuilder(org.apereo.cas.authentication.DefaultAuthenticationResultBuilder) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) DefaultAuthenticationResultBuilder(org.apereo.cas.authentication.DefaultAuthenticationResultBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 48 with PostMapping

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());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 49 with PostMapping

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;
}
Also used : Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 50 with PostMapping

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)83 ApiOperation (io.swagger.annotations.ApiOperation)21 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 Example (tk.mybatis.mapper.entity.Example)8 HashMap (java.util.HashMap)7 Service (org.apereo.cas.authentication.principal.Service)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 User (amu.zhcet.data.user.User)4 Report (com.erudika.scoold.core.Report)4 IOException (java.io.IOException)4 Map (java.util.Map)4 Credential (org.apereo.cas.authentication.Credential)4 Reply (com.erudika.scoold.core.Reply)3 Log (io.github.tesla.ops.common.Log)3 LinkedHashMap (java.util.LinkedHashMap)3