List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:cz.cvut.fel.wpa.tracker.pres.bb.LoginBean.java
public String login() { Authentication request = new UsernamePasswordAuthenticationToken(username, password); try {//from www . jav a 2 s.c o m Authentication result = authenticationManager.authenticate(request); SecurityContextHolder.getContext().setAuthentication(result); } catch (org.springframework.security.core.AuthenticationException e) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Invalid credentials!", "The username/password combination is not valid.")); return "login"; } FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Login ok", "login ok.")); return "issues?faces-redirect=true"; }
From source file:com.morevaadin.vaadin7.springsecurity.util.ViewChangeSecurityChecker.java
@Override public boolean isViewChangeAllowed(ViewChangeEvent event) { if (event.getNewView() instanceof LoginView) { return true; }/*from w ww. ja v a2 s . c o m*/ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication == null ? false : authentication.isAuthenticated(); }
From source file:net.seedboxer.web.controller.rs.SeedBoxerAPI.java
protected User getUser() { SeedBoxerUserDetails ud = (SeedBoxerUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); return ud.getUser(); }
From source file:com.ignite.controller.ClientController.java
@RequestMapping(value = "/client", method = RequestMethod.GET) public ModelAndView client() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); List<Account> accounts = accountDao.getAccountsForClient(clientDao.getClient(name)); return new ModelAndView("client", "accountList", accounts); }
From source file:com.task.springsec.SecurityUtil.java
/** * Return the current Authentication object. *//*from w w w . ja v a 2 s .c om*/ public static MyUser getUser() { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { try { Object p = auth.getPrincipal(); if (p instanceof MyUser) return (MyUser) p; } catch (RuntimeException e) { e.printStackTrace(); throw e; } } return null; }
From source file:com.cami.web.controller.LeController.java
@RequestMapping(value = "/welcome**", method = RequestMethod.GET) public ModelAndView welcomePage() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username final Role user = roleService.retrieveAUser(name); final Role userConnected = roleService.retrieveAUser(name); ModelAndView model = new ModelAndView(); model.addObject("user", user); model.addObject("userConnected", userConnected); model.setViewName("hello"); return model; }
From source file:org.key2gym.business.services.BasicBean.java
protected boolean callerHasRole(String role) { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext() .getAuthentication().getAuthorities().contains(new SimpleGrantedAuthority(role)); }
From source file:net.gplatform.sudoor.server.security.controller.SpringSecurityResource.java
@GET @Path("Authentication") @Produces(MediaType.APPLICATION_JSON)/*from w ww .j a va 2 s. c o m*/ public Authentication getAuthentication() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication; }
From source file:cz.cvut.kbss.wpa.back.EditUserBean.java
public AdminDTO getAdmin() { if (admin == null) { //load from credential CurrentUserDetails cud = (CurrentUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();/*from w w w . j a v a 2 s.c om*/ admin = (AdminDTO) cud.getUserDto(); admin.setPassword(""); } return admin; }
From source file:com.epam.ipodromproject.controller.ArchivedBetsController.java
@RequestMapping(value = "getArchiveBetsPage", method = RequestMethod.GET) public String getArchivePage(@RequestParam(value = "page") Integer page, @RequestParam(value = "resultsPerPage") Integer resultsPerPage, Model model) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); int totalPages = (int) betService.getTotalArchiveBetsPagesMadeByUser(username, resultsPerPage); if (page < 1) { page = 1;// ww w . j av a 2s . c om } else if (page > totalPages) { page = totalPages; } model.addAttribute("bets", betService.getArchivedBetsPageMadeByUser(username, page, resultsPerPage)); return "lists/archiveBetsDropList"; }