Java源码示例:org.springframework.security.web.bind.annotation.AuthenticationPrincipal

示例1
@RequestMapping(method = RequestMethod.POST)
public String update(
		@PathVariable String language,
		@Validated @ModelAttribute(FORM_MODEL_KEY) GoogleAnalyticsUpdateForm form,
		BindingResult errors,
		@AuthenticationPrincipal AuthorizedUser authorizedUser,
		RedirectAttributes redirectAttributes) {
	redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form);
	redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors);

	if (errors.hasErrors()) {
		return "redirect:/_admin/{language}/analytics/edit?step.edit";
	}

	GoogleAnalyticsUpdateRequest request = new GoogleAnalyticsUpdateRequest();
	request.setBlogId(Blog.DEFAULT_ID);
	request.setTrackingId(form.getTrackingId());
	request.setProfileId(form.getProfileId());
	request.setCustomDimensionIndex(form.getCustomDimensionIndex());
	request.setServiceAccountId(form.getServiceAccountId());
	request.setServiceAccountP12File(form.getServiceAccountP12File());

	GoogleAnalytics updatedGoogleAnalytics;
	try {
		updatedGoogleAnalytics = blogService.updateGoogleAnalytics(request);
	} catch (GoogleAnalyticsException e) {
		errors.reject("GoogleAnalytics");
		return "redirect:/_admin/{language}/analytics/edit?step.edit";
	}

	redirectAttributes.getFlashAttributes().clear();
	redirectAttributes.addFlashAttribute("updatedGoogleAnalytics", updatedGoogleAnalytics);
	return "redirect:/_admin/{language}/analytics";
}
 
示例2
@Layout("layouts/logged_in")
@RequestMapping("/hello")
public String hello(@AuthenticationPrincipal User user, final Model model) {
    model.addAttribute("name", user.getUsername());
    return "hello";
}