本文整理汇总了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";
}
示例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;
}
}
示例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<>();
}
}
示例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<>();
}
}
示例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;
}
示例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:/";
}
示例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";
}
示例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}";
}
示例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";
}
示例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";
}
示例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";
}
示例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";
}
示例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);
}
示例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);
}
示例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";
}