org.springframework.security.web.bind.annotation.AuthenticationPrincipal Java Examples

The following examples show how to use org.springframework.security.web.bind.annotation.AuthenticationPrincipal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleAnalyticsUpdateController.java    From wallride with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example #2
Source File: SecurityController.java    From spring-boot-spring-loaded-java8-example with Apache License 2.0 4 votes vote down vote up
@Layout("layouts/logged_in")
@RequestMapping("/hello")
public String hello(@AuthenticationPrincipal User user, final Model model) {
    model.addAttribute("name", user.getUsername());
    return "hello";
}