@RequestMapping(value = "{tourCode}/reserve", method = RequestMethod.POST) public String reserve(@AuthenticationPrincipal ReservationUserDetails userDetails, @PathVariable("tourCode") String tourCode, @Validated ReserveTourForm form, BindingResult result, Model model, RedirectAttributes redirectAttributes) { if (result.hasErrors()) { return reserveForm(userDetails, tourCode, form, model); } try { ReserveTourOutput output = reserveTourHelper.reserve(userDetails, tourCode, form); redirectAttributes.addFlashAttribute("output", output); } catch (BusinessException e) { model.addAttribute(e.getResultMessages()); return reserveForm(userDetails, tourCode, form, model); } return "redirect:/tours/{tourCode}/reserve?complete"; }
@RequestMapping(value = "/{user_id}/{action}", method = RequestMethod.PATCH) @Transactional public void updateUserAvailability(@PathVariable("user_id") final Long id, @PathVariable("action") final UpdateAction action, @AuthenticationPrincipal final User currentUser) { LOG.debug("User update :: ACTION:[{}], TARGET:[id:{}], CURRENT:{}", action, id, currentUser); final User user = lookupUser(id); switch (action) { case LOCK: lockUser(user); break; case UNLOCK: unlockUser(user); break; case DISABLE: disableUser(user); break; case ENABLE: enableUser(user); break; } }
@ModelAttribute("resources") @RequestMapping(method = GET, value = "") public Collection<Resource<MeasurementDto>> measurementsPage( @RequestParam(value = "metric", required = false, defaultValue = "") String metric, @RequestParam(value = "resource", required = false, defaultValue = "") String resource, @AuthenticationPrincipal User user, Model model) { model.addAttribute("refreshInterval", refreshInterval); model.addAttribute("measurementInput", new MeasurementInput()); model.addAttribute("graphInput", new GraphInput()); try { UserCredentials userCreds = UserConverter.convert(user); Collection<Resource<MeasurementDto>> result = getMeasurementsUC.getMeasurements(metric, resource, userCreds); setAvailableComplexTypes(result, model); return result; } catch (Exception e) { log.error("error", e); model.addAttribute("error", e.getMessage()); return new ArrayList<>(); } }
@RequestMapping(method = POST, value = "/add") @ModelAttribute("resources") public Collection<Resource<MeasurementDto>> addMeasurement( @ModelAttribute(value="measurementInput") MeasurementInput measurementInput, @AuthenticationPrincipal User user, Model model) { try { String addUri = measurementInput.getAddUri(); ComplexMeasurementOutDto complexDetails = ComplexConverter.convert(measurementInput.getComplexDetails()); UserCredentials userCreds = UserConverter.convert(user); addMeasurementUC.addMeasurement(addUri, complexDetails, userCreds); return measurementsPage("", "", user, model); } catch (Exception e) { log.error("error", e); model.addAttribute("error", e.getMessage()); return new ArrayList<>(); } }
@RequestMapping public String getCart(@AuthenticationPrincipal User activeUser){ Customer customer = customerService.getCustomerByUsername (activeUser.getUsername()); int cartId = customer.getCart().getCartId(); return "redirect:/customer/cart/"+cartId; }
@RequestMapping("/update") public String update(@AuthenticationPrincipal User user, @Validated PasswordUpdateForm form, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return edit(form); } user.setPassword(new StandardPasswordEncoder().encode(form.getNewPassword())); userRepository.save(user); return "redirect:/"; }
@RequestMapping(value = "/create", method = RequestMethod.POST) public String create(@AuthenticationPrincipal User user, @Validated TodoForm form, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { return index(user, form, model); } todoService.save(form, user.getId()); return "redirect:/todos"; }
@RequestMapping(value = "/{id}/update", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces={"application/json;charset=UTF-8"}) @ResponseBody public String update(@AuthenticationPrincipal User user, @RequestBody TodoUpdateForm form) { if (todoService.ownedBy(Long.parseLong(form.getId()), user.getId())) { todoService.update(form); } return "{\"result\": 0}"; }
@RequestMapping(value = "/{id}/delete", method = RequestMethod.POST) public String delete(@AuthenticationPrincipal User user, TodoForm form, Model model, @PathVariable Long id) { if (todoService.ownedBy(id, user.getId())) { todoService.delete(id); } return "redirect:/todos"; }
@RequestMapping(value = "{tourCode}/reserve", method = RequestMethod.POST, params = "confirm") public String confirm(@AuthenticationPrincipal ReservationUserDetails userDetails, @PathVariable("tourCode") String tourCode, @Validated ReserveTourForm form, BindingResult result, Model model) { if (result.hasErrors()) { return reserveForm(userDetails, tourCode, form, model); } TourDetailOutput output = reserveTourHelper.findTourDetail(userDetails, tourCode, form); model.addAttribute("output", output); return "reservetour/reserveConfirm"; }
@RequestMapping(value="me", method = RequestMethod.GET) public String list(@AuthenticationPrincipal ReservationUserDetails userDetails ,Model model) { List<ReserveRowOutput> rows = helper.list(userDetails); model.addAttribute("rows", rows); return "managereservation/list"; }
@RequestMapping public String index(@AuthenticationPrincipal User user, Model model) { if (!user.can(Abilities.READ_ORGANIZATION)) { return "redirect:/"; } model.addAttribute("organizationList", organizationService.findAll()); return "organization/index"; }
@RequestMapping(value = "", method = RequestMethod.POST) public @ResponseBody TokenDetails createToken(@AuthenticationPrincipal User user){ String token = tokenUtils.createToken(user); Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); calendar.add(Calendar.HOUR, 1); Date expires = calendar.getTime(); return new TokenDetails(token, user.getId(), now, expires); }
/** * Delete the user account by the given identifier * * @param id identifier of a user to be deleted * @param currentUser currently logged in user * @throws ResourceNotFoundException if there is no user profile with the given identifier */ @RequestMapping(value = "/{user_id}", method = RequestMethod.DELETE) @Transactional public void deleteUser(@PathVariable("user_id") final Long id, @AuthenticationPrincipal final User currentUser) { LOG.debug("Deleting user :: ID:[{}], CURRENT:{}", id, currentUser); final User user = lookupUser(id); if (user.getId() == currentUser.getId()) { throw new ResourceConflictException("User can't delete it's own user account"); } repository.delete(user); }
@RequestMapping(value = "/greet/{name}", method = RequestMethod.GET) public String greet(@AuthenticationPrincipal UserDetails user, @PathVariable(value = "name") final String name, final Model model) { if (user == null) { throw new RuntimeException("Authentication error"); } model.addAttribute("username", user.getUsername()); model.addAttribute("name", name); logger.info("The authenticated user '" + user.getUsername() + "' is masquarading as '" + name + "'."); return "site.admin.greet"; }
@RequestMapping(value = "/greet/{name}", method = RequestMethod.GET) public String greet(@AuthenticationPrincipal UserDetails user, @PathVariable(value = "name") final String name, final Model model) { if (user == null) { throw new RuntimeException("Authentication error"); } model.addAttribute("username", user.getUsername()); model.addAttribute("name", name); log.info("The authenticated user '" + user.getUsername() + "' is masquarading as '" + name + "'."); return "site.admin.greet"; }
@RequestMapping(method = GET, value = "/delete") @ModelAttribute("resources") public Collection<Resource<MeasurementDto>> deleteMeasurement( @RequestParam(value = "deleteUri", required = true) String deleteUri, @AuthenticationPrincipal User user, Model model) { try { UserCredentials userCreds = UserConverter.convert(user); deleteMeasurementUC.deleteMeasurement(deleteUri, userCreds); return measurementsPage("", "", user, model); } catch (Exception e) { model.addAttribute("error", e.getMessage()); return new ArrayList<>(); } }
@RequestMapping(method = POST, value = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody Resource<MeasurementDto> addMeasurement( @RequestBody Measurement measurement, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = null; if(user != null) applicationUser = new ApplicationUser(user.getUsername()); addMeasurementUC.addMeasurement(measurement, applicationUser); MeasurementDto dto = measurementConverter.convertMeasurement(measurement); return assmeblerSupport.addLinks(dto); }
@RequestMapping(method = DELETE, value = "/{id}") public void deleteMeasurement( @PathVariable("id") UUID uuid, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = null; if(user != null) applicationUser = new ApplicationUser(user.getUsername()); deleteMeasurementUC.deleteMeasurement(uuid, applicationUser); }
@RequestMapping(method = GET, value = "", produces = MediaType.APPLICATION_JSON_VALUE) public Resources<Resource<MeasurementDto>> getMeasurements( @RequestParam(value = "metric", defaultValue = "") String metric, @RequestParam(value = "resource", defaultValue = "") String resource, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = UserConverter.convert(user); List<Measurement> list = getMeasurementsUC.getList(metric, resource); List<MeasurementDto> dtoList = measurementConverter.convertMeasurements(list); return assemblerSupport.addLinks(dtoList, applicationUser); }
@RequestMapping(method = GET, value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public Resource<MeasurementDto> getMeasurement( @PathVariable("id") UUID uuid, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = UserConverter.convert(user); Measurement details = getMeasurementDetailsUC.getDetails(uuid); MeasurementDto dto = measurementConverter.convertMeasurement(details); return assemblerSupport.addLinks(dto, applicationUser); }
@RequestMapping(method = POST, value = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public Resource<MeasurementDto> createMeasurement( @RequestBody ComplexMeasurementInDto inDto, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = UserConverter.convert(user); ComplexMeasurement complex = measurementConverter.convertComplexMeasurement(inDto); Measurement measurement = createComplexMeasurementUC.create(complex, applicationUser); MeasurementDto outDto = measurementConverter.convertMeasurement(measurement); return assemblerSupport.addLinks(outDto, applicationUser); }
@RequestMapping(method = DELETE, value = "/{id}") public void deleteMeasurement( @PathVariable("id") UUID uuid, @AuthenticationPrincipal User user) { ApplicationUser applicationUser = UserConverter.convert(user); deleteComplexMeasurementUC.delete(uuid, applicationUser); }
@RequestMapping public String index(@AuthenticationPrincipal User user, TodoForm form, Model model) { model.addAttribute("allTodoStates", todoStateService.findAll()); model.addAttribute("allTodos", todoService.findAll(user.getId())); return "todos/index"; }
@RequestMapping(value = "{tourCode}/reserve", method = RequestMethod.POST, params = "redo") public String reserveRedo(@AuthenticationPrincipal ReservationUserDetails userDetails, @PathVariable("tourCode") String tourCode, ReserveTourForm form, Model model) { return reserveForm(userDetails, tourCode, form, model); }
@RequestMapping public String index(@AuthenticationPrincipal User user, Model model) { model.addAttribute("reportList", reportService.findByCreatorId(user.getId())); return "report/index"; }
@RequestMapping(value = "/create", method = RequestMethod.POST) public String create(@AuthenticationPrincipal User user, ReportForm reportForm) { reportService.create(user, reportForm); return "redirect:/report"; }
@Layout("layouts/logged_in") @RequestMapping("/hello") public String hello(@AuthenticationPrincipal User user, final Model model) { model.addAttribute("name", user.getUsername()); return "hello"; }
@RequestMapping(value = "/test", method = RequestMethod.GET, produces = "text/plain") public String test(@AuthenticationPrincipal Principal user) { log.debug("Received /test request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); return "TEST"; }
@RequestMapping(value = "/**", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Collection<T> get(@AuthenticationPrincipal Principal user) { log.debug("Received document list request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); return Lists.newArrayList(service.findAll()); }
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public T get(@PathVariable String id, @AuthenticationPrincipal Principal user) { log.debug("Received document get request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); return service.findOne(id); }
@RequestMapping(value = "/**", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public T create(@RequestBody T document, @AuthenticationPrincipal Principal user) { log.debug("Received document create request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); return service.create(document); }
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public T update(@PathVariable String id, @RequestBody T document, @AuthenticationPrincipal Principal user) { log.debug("Received document update request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); return service.update(document); }
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) public void delete(@PathVariable String id, @AuthenticationPrincipal Principal user) { log.debug("Received document delete request from user '" + (user == null ? "unknown user" : user.getName()) + "'"); service.delete(id); }
@RequestMapping(value = {"{tourCode}", "{tourCode}/reserve"}, method = RequestMethod.GET, params = "form") public String reserveForm(@AuthenticationPrincipal ReservationUserDetails userDetails, @PathVariable("tourCode") String tourCode, ReserveTourForm form, Model model) { TourDetailOutput output = reserveTourHelper.findTourDetail(userDetails, tourCode, form); model.addAttribute("output", output); return "reservetour/reserveForm"; }
/** * <pre> * Authenticates the current user. * * <b>Required roles:</b> ROLE_USER * <b>Path:</b> GET {@value Core#RESOURCE_USER}/authenticate * </pre> * * @return <b>200 OK</b> and the current logged in user or <br> * <b>403 Forbidden</b> if authentication failed */ @Secured(Core.ROLE_USER) @RequestMapping(method = RequestMethod.GET, value = "/authenticate") public Callable authenticate(@AuthenticationPrincipal User user) { final User user2 = Core.currentUser(); return () -> new ResponseEntity<>(user2, HttpStatus.OK); }
/** * <pre> * Change email workflow (Step 1) * * <b>Required roles:</b> ROLE_USER * <b>Path:</b> POST {@value Core#RESOURCE_USER}/changeEmail * </pre> * * @param emailToBeConfirmed the new email address to be confirmed * @return <b>200 OK</b> if everything goes well or <br> * <b>409 Conflict</b> if a user with the given username or email already exists */ @Secured(Core.ROLE_USER) @RequestMapping(method = RequestMethod.POST, value = "/changeEmail") public ResponseEntity changeEmail(@AuthenticationPrincipal User user, @RequestBody String emailToBeConfirmed) { userService.changeEmail(user, emailToBeConfirmed); return new ResponseEntity(HttpStatus.OK); }