List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:de.forsthaus.UserWorkspace.java
static private Authentication getAuthentication() { return SecurityContextHolder.getContext().getAuthentication(); }
From source file:com.epam.ipodromproject.controller.MainPageController.java
@RequestMapping(value = { "home", "" }, method = RequestMethod.GET) public String goToHome(Model model) { User user = userService.getUserByUsername(SecurityContextHolder.getContext().getAuthentication().getName()); model.addAttribute("user", user); model.addAttribute("totalMoneyWon", userService.getTotalMoneyWon(user)); model.addAttribute("totalMoneyLost", userService.getTotalMoneyLost(user)); return "mainPage"; }
From source file:com.scistor.tab.auth.controller.HomeRestController.java
@RequestMapping(value = "/user", method = RequestMethod.GET) public User getUserInfo(HttpServletRequest request) { System.out.println(SecurityContextHolder.getContext().getAuthentication()); return userRepository.findByUsername(request.getUserPrincipal().getName()); }
From source file:by.bsuir.finance.controllers.SalaryController.java
@RequestMapping(value = "/view") public ModelAndView view() { ModelAndView model = new ModelAndView("salary/view"); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username List<Salary> salarys = salaryService.findByUsername(name); model.addObject("salaries", salarys); return model; }
From source file:org.cloudfoundry.identity.uaa.authentication.manager.CompositeAuthenticationManager.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Authentication a = SecurityContextHolder.getContext().getAuthentication(); OAuth2Authentication oauth2Authentication = null; if (a instanceof OAuth2Authentication) { oauth2Authentication = (OAuth2Authentication) a; }//from w w w . ja v a 2 s . com if (oauth2Authentication != null) { return oauth2Authentication.getUserAuthentication(); } else { return authentication; } }
From source file:se.inera.certificate.web.service.CitizenService.java
public Citizen getCitizen() { return (Citizen) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); }
From source file:br.com.sescacre.controleAcesso.bean.UsuarioBean.java
public UsuarioBean() { usuario = new Usuarios(); SecurityContext context = SecurityContextHolder.getContext(); if (context instanceof SecurityContext) { Authentication authentication = context.getAuthentication(); if (authentication instanceof Authentication) { usuario.setLogin(((User) authentication.getPrincipal()).getUsername()); }/* w w w.j a v a 2s. c o m*/ } }
From source file:de.qucosa.spring.AuthenticationConfiguration.java
@Bean @Scope("request") public Authentication authentication() { return SecurityContextHolder.getContext().getAuthentication(); }
From source file:com.mycompany.thymeleafspringapp.service.SimpleSigninAdapter.java
@Override public String signIn(String localUserId, Connection<?> connection, NativeWebRequest request) { String email = connection.fetchUserProfile().getEmail(); UserDetails userDetails = userService.loadUserByUsername(email); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken(userDetails, null, null)); return null;// ww w .j a v a 2 s. c om }
From source file:br.com.officium.beans.UsuarioBean.java
@PostConstruct public void ini() { usuario = new Usuario(); SecurityContext context = SecurityContextHolder.getContext(); if (context instanceof SecurityContext) { Authentication authentication = context.getAuthentication(); if (authentication instanceof Authentication) { try { usuario = getUsuarioDao().logon(((User) authentication.getPrincipal()).getUsername(), ((User) authentication.getPrincipal()).getPassword()); } catch (Exception ex) { Logger.getLogger(UsuarioBean.class.getName()).log(Level.SEVERE, null, ex); }/*from ww w.j ava2 s . co m*/ usuario.setUsername(((User) authentication.getPrincipal()).getUsername()); } } }