当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationPrincipal类代码示例

本文整理汇总了Java中org.springframework.security.web.bind.annotation.AuthenticationPrincipal的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationPrincipal类的具体用法?Java AuthenticationPrincipal怎么用?Java AuthenticationPrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationPrincipal类属于org.springframework.security.web.bind.annotation包,在下文中一共展示了AuthenticationPrincipal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reserve

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:garbagetown,项目名称:springboot-tourreservation,代码行数:20,代码来源:ReserveTourController.java

示例2: updateUserAvailability

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:T-PWK,项目名称:freezo,代码行数:26,代码来源:UsersController.java

示例3: measurementsPage

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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<>();
	}
}
 
开发者ID:wysekm,项目名称:DistributedSystemMonitoring,代码行数:23,代码来源:MeasurementController.java

示例4: addMeasurement

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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<>();
	}
}
 
开发者ID:wysekm,项目名称:DistributedSystemMonitoring,代码行数:19,代码来源:MeasurementController.java

示例5: getCart

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@RequestMapping
public String getCart(@AuthenticationPrincipal User activeUser){
    Customer customer = customerService.getCustomerByUsername (activeUser.getUsername());
    int cartId = customer.getCart().getCartId();

    return "redirect:/customer/cart/"+cartId;
}
 
开发者ID:OliviaLiyuanWei,项目名称:Foodtastic-e-foodstore-website,代码行数:8,代码来源:CartController.java

示例6: update

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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:/";
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:10,代码来源:PasswordController.java

示例7: create

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:9,代码来源:TodoController.java

示例8: update

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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}";
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:9,代码来源:TodoController.java

示例9: delete

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:8,代码来源:TodoController.java

示例10: confirm

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:garbagetown,项目名称:springboot-tourreservation,代码行数:16,代码来源:ReserveTourController.java

示例11: list

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:garbagetown,项目名称:springboot-tourreservation,代码行数:8,代码来源:ManageReservationController.java

示例12: index

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:ksoichiro,项目名称:ability,代码行数:9,代码来源:OrganizationController.java

示例13: createToken

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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);
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:10,代码来源:UserController.java

示例14: deleteUser

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:T-PWK,项目名称:freezo,代码行数:22,代码来源:UsersController.java

示例15: greet

import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@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";
}
 
开发者ID:mmeany,项目名称:spring-boot-web-app-base,代码行数:11,代码来源:AdminController.java


注:本文中的org.springframework.security.web.bind.annotation.AuthenticationPrincipal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。