List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:com.springsource.greenhouse.signin.AccountExposingHandlerInterceptorTest.java
@Before public void setup() { interceptor = new AccountExposingHandlerInterceptor(); account = new Account(1L, "Joe", "Schmoe", "joe@schmoe.com", "joe", "file://pic.jpg", new UriTemplate("http://localhost:8080/members/{profileKey}")); TestingAuthenticationToken authentication = new TestingAuthenticationToken(account, "password"); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:cn.org.once.cstack.aspects.CloudUnitAbstractAspect.java
protected User getAuthentificatedUser() throws ServiceException { UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); User user = userService.findByLogin(principal.getUsername()); return user;//w w w .j av a 2 s . c o m }
From source file:com.indusborn.ui.signin.AccountExposingHandlerInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.getPrincipal() instanceof UserVO) { request.setAttribute("userVO", auth.getPrincipal()); }/*from ww w .j a va 2 s. co m*/ return true; }
From source file:web.SecurityController.java
@RequestMapping(value = "/403", method = RequestMethod.GET) public ModelAndView accesssDenied() { ModelAndView model = new ModelAndView(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (!(auth instanceof AnonymousAuthenticationToken)) { UserDetails userDetail = (UserDetails) auth.getPrincipal(); System.out.println(userDetail); model.addObject("username", userDetail.getUsername()); }/*from w w w. j a v a 2s .c o m*/ model.setViewName("403"); return model; }
From source file:kievreclama.task.controllers.RootController.java
@RequestMapping(value = "/logout", method = RequestMethod.GET) public String logoutPage(HttpServletRequest request, HttpServletResponse response) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { new SecurityContextLogoutHandler().logout(request, response, auth); }//from w w w . j a v a 2s.c o m return "redirect:/task"; }
From source file:io.gravitee.management.rest.resource.AbstractResource.java
protected boolean isUserInRole(String role) { return SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream() .anyMatch(new Predicate<GrantedAuthority>() { @Override/*from w ww. j a va 2s. c o m*/ public boolean test(GrantedAuthority grantedAuthority) { return grantedAuthority.getAuthority().equalsIgnoreCase(role); } }); }
From source file:com.jayway.restassured.module.mockmvc.http.SecuredController.java
@RequestMapping(value = "/springSecurityGreeting", method = GET) public @ResponseBody Greeting greeting( @RequestParam(value = "name", required = false, defaultValue = "World") String name) { User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (user == null || !user.getUsername().equals("authorized_user")) { throw new IllegalArgumentException("Not authorized"); }/* w w w .j a va 2 s .c om*/ return new Greeting(counter.incrementAndGet(), String.format(template, name)); }
From source file:com.tlantic.integration.authentication.service.security.UserAuthProviderService.java
private Authentication signInUser(User user, List<GrantedAuthority> roles) { UserDetails springSecurityUser = new org.springframework.security.core.userdetails.User(user.getEmail(), user.getId(), roles);// w w w . j a v a2s . c om Authentication authentication = new UsernamePasswordAuthenticationToken(springSecurityUser, user.getId(), roles); SecurityContextHolder.getContext().setAuthentication(authentication); return authentication; }
From source file:com.porvak.bracket.socialize.signin.AccountExposingHandlerInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.getPrincipal() instanceof Account) { request.setAttribute("account", auth.getPrincipal()); }// w ww .j a va 2s. c om return true; }
From source file:com.tapas.evidence.repository.TeacherRepositoryImpl.java
@Override @SuppressWarnings("unchecked") public List<Teacher> findAll() { final Long tenantId = ((EvidenceUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal()).getTenantId(); Query query = this.entityManager.createNamedQuery(Teacher.QUERY_NAME_FIND_ALL_BY_DELETED_FLAG); query.setParameter("deleted", Boolean.FALSE); query.setParameter("tenantId", tenantId); return query.getResultList(); }