List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:fr.mael.microrss.util.SecurityUtil.java
public User getCurrentUser() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object principal = auth.getPrincipal(); if (principal == null || !(principal instanceof User)) { throw new AccessDeniedException("User is not logged in"); }/* ww w.j av a 2 s .c om*/ User user = (User) principal; //TODO the id is lost when the server is restarted //will it happen in production ? if (user.getId() == null) { throw new AccessDeniedException("User is not logged in"); } return user; }
From source file:org.atomsphere.management.authentication.AuthenticationUtils.java
public static Authentication getAuthentication() { return SecurityContextHolder.getContext().getAuthentication(); }
From source file:security.LoginService.java
public static UserAccount getPrincipal() { UserAccount result;/*from ww w. j a v a2s . co m*/ SecurityContext context; Authentication authentication; Object principal; // If the asserts in this method fail, then you're // likely to have your Tomcat's working directory // corrupt. Please, clear your browser's cache, stop // Tomcat, update your Maven's project configuration, // clean your project, clean Tomcat's working directory, // republish your project, and start it over. context = SecurityContextHolder.getContext(); Assert.notNull(context); authentication = context.getAuthentication(); Assert.notNull(authentication); principal = authentication.getPrincipal(); Assert.isTrue(principal instanceof UserAccount); result = (UserAccount) principal; Assert.notNull(result); Assert.isTrue(result.getId() != 0); return result; }
From source file:com.banco.controller.AdminController.java
@RequestMapping(value = "/Usuarios") public String administrarUsuarios(Model m) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username User user = userService.getUserByUsername(name); m.addAttribute("session_user", user); m.addAttribute("lst", userService.getAll()); return "admin_usuarios"; }
From source file:com.cfitzarl.cfjwed.core.security.SecurityContextWrapper.java
public static Authentication getAuthentication() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new UnauthorizedException("Unauthorized access detected"); }/*from w w w .j a va 2s . co m*/ return authentication; }
From source file:psiprobe.controllers.apps.ReloadContextController.java
@Override protected void executeAction(String contextName) throws Exception { Context context = getContainerWrapper().getTomcatContainer().findContext(contextName); if (context != null) { context.reload();/* ww w . j a va 2 s .c o m*/ // Logging action Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); // get username logger logger.info(getMessageSourceAccessor().getMessage("probe.src.log.reload"), name, contextName); } }
From source file:com.sasav.blackjack.controller.AccountController.java
@RequestMapping(value = "/deposit", method = RequestMethod.GET) public ModelAndView depositPage() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String login = auth.getName(); AccountTransaction deposit = accountMaster.createTransactionForUser(login); ModelAndView mv = new ModelAndView("deposit"); mv.addObject("depositAcc", deposit); return mv;/*from ww w.j a v a2 s. c o m*/ }
From source file:com.banco.controller.BankController.java
@RequestMapping(value = "/index") public String registrar(Model model) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username User user = userService.getUserByUsername(name); model.addAttribute("session_user", user); return "home"; }
From source file:com.hp.autonomy.frontend.configuration.authentication.LoginSuccessHandler.java
@Override protected String determineTargetUrl(final HttpServletRequest request, final HttpServletResponse response) { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); for (final GrantedAuthority grantedAuthority : authentication.getAuthorities()) { if (roleDefault.equalsIgnoreCase(grantedAuthority.getAuthority())) { return configUrl; }// w w w .ja v a 2s. c om } return applicationUrl; }
From source file:com.healthcit.analytics.service.ReportTemplateService.java
@RemoteMethod public String getAllReportTemplates() { Long userId = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId(); JSONArray templates = manager.getAllReports(userId); log.debug("Size is " + templates.size()); return /*manager.getAllReports().toString()*/ templates.toString(); }