Java 类org.springframework.security.web.bind.annotation.AuthenticationPrincipal 实例源码

项目:springboot-tourreservation    文件:ReserveTourController.java   
@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";
}
项目:freezo    文件:UsersController.java   
@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;
    }
}
项目:DistributedSystemMonitoring    文件:MeasurementController.java   
@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<>();
    }
}
项目:DistributedSystemMonitoring    文件:MeasurementController.java   
@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<>();
    }
}
项目:Foodtastic-e-foodstore-website    文件:CartController.java   
@RequestMapping
public String getCart(@AuthenticationPrincipal User activeUser){
    Customer customer = customerService.getCustomerByUsername (activeUser.getUsername());
    int cartId = customer.getCart().getCartId();

    return "redirect:/customer/cart/"+cartId;
}
项目:todo    文件:PasswordController.java   
@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:/";
}
项目:todo    文件:TodoController.java   
@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";
}
项目:todo    文件:TodoController.java   
@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}";
}
项目:todo    文件:TodoController.java   
@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";
}
项目:springboot-tourreservation    文件:ReserveTourController.java   
@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";
}
项目:springboot-tourreservation    文件:ManageReservationController.java   
@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";
}
项目:ability    文件:OrganizationController.java   
@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";
}
项目:centromere    文件:UserController.java   
@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);
}
项目:freezo    文件:UsersController.java   
/**
 * 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);
}
项目:spring-boot-web-app-base    文件:AdminController.java   
@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";
}
项目:spring-boot-web-mvc-tiles3-security    文件:AdminController.java   
@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";
}
项目:DistributedSystemMonitoring    文件:MeasurementController.java   
@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<>();
    }
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@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);
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@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);
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@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);
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@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);
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@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);
}
项目:DistributedSystemMonitoring    文件:MeasurementsController.java   
@RequestMapping(method = DELETE, value = "/{id}")
public void deleteMeasurement(
        @PathVariable("id") UUID uuid,
        @AuthenticationPrincipal User user) {
    ApplicationUser applicationUser = UserConverter.convert(user);
    deleteComplexMeasurementUC.delete(uuid, applicationUser);
}
项目:todo    文件:TodoController.java   
@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";
}
项目:springboot-tourreservation    文件:ReserveTourController.java   
@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);
}
项目:ability    文件:ReportController.java   
@RequestMapping
public String index(@AuthenticationPrincipal User user, Model model) {
    model.addAttribute("reportList", reportService.findByCreatorId(user.getId()));
    return "report/index";
}
项目:ability    文件:ReportController.java   
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@AuthenticationPrincipal User user, ReportForm reportForm) {
    reportService.create(user, reportForm);
    return "redirect:/report";
}
项目:spring-boot-spring-loaded-java8-example    文件:SecurityController.java   
@Layout("layouts/logged_in")
@RequestMapping("/hello")
public String hello(@AuthenticationPrincipal User user, final Model model) {
    model.addAttribute("name", user.getUsername());
    return "hello";
}
项目:mongo-rest    文件:DocumentController.java   
@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";
}
项目:mongo-rest    文件:DocumentController.java   
@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());
}
项目:mongo-rest    文件:DocumentController.java   
@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);
}
项目:mongo-rest    文件:DocumentController.java   
@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);
}
项目:mongo-rest    文件:DocumentController.java   
@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);
}
项目:mongo-rest    文件:DocumentController.java   
@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);
}
项目:springboot-tourreservation    文件:ReserveTourController.java   
@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";
}
项目:LivingDocumentsServer    文件:UserController.java   
/**
 * <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);
}
项目:LivingDocumentsServer    文件:UserController.java   
/**
 * <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);
}