List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor.java
@Override public boolean isClient() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); if (!(a instanceof OAuth2Authentication)) { return false; }//from ww w .j a v a 2s . co m return ((OAuth2Authentication) a).isClientOnly(); }
From source file:com.hp.autonomy.hod.caching.AbstractHodCacheResolver.java
@Override protected Collection<String> getCacheNames(final CacheOperationInvocationContext<?> context) { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!(authentication instanceof HodAuthentication)) { throw new IllegalStateException("There is no HOD authentication token in the security context holder"); }//from ww w. j a v a 2s . co m final HodAuthenticationPrincipal principal = ((HodAuthentication) authentication).getPrincipal(); final Set<String> contextCacheNames = context.getOperation().getCacheNames(); final Collection<String> resolvedCacheNames = new HashSet<>(); for (final String cacheName : contextCacheNames) { resolvedCacheNames.add(resolveName(cacheName, principal)); } return resolvedCacheNames; }
From source file:org.drugis.addis.security.SignInUtilService.java
/** * Programmatically signs in the user with the given the user ID. *///from w w w.j av a 2s . c o m public void signin(Connection<?> connection, String userId) { SocialUserDetails socialUserDetails = simpleSocialUsersDetailService.loadUserByUserId(userId); SecurityContextHolder.getContext() .setAuthentication(new SocialAuthenticationToken(connection, socialUserDetails, null, null)); }
From source file:co.edu.utb.softeng.springtodos.controllers.AuthController.java
@RequestMapping(value = { "/isLoggedIn" }, method = RequestMethod.GET) public @ResponseBody Object isLoggedIn() { Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return user instanceof UserDetails; }
From source file:BSxSB.Controllers.LoginController.java
@RequestMapping(value = "/index", method = RequestMethod.GET) public String login(Model model, @RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); Students currentStudent = StudentDAO.getStudent(name); if (currentStudent != null) { model.addAttribute("student", currentStudent); return "student"; }/*from ww w.ja v a 2 s . c o m*/ Admins currentAdmin = AdminDAO.getAdmin(name); if (currentAdmin != null) { SchoolDAO schoolDAO = new SchoolDAO(); ScheduleBlockDAO scheduleBlockDAO = new ScheduleBlockDAO(); List<Schools> schools = schoolDAO.allSchools(); for (Schools school : schools) { List<Scheduleblocks> scheduleBlocks = scheduleBlockDAO .getSchoolsScheduleBlocks(school.getSchoolid()); String SB2Strings = ""; for (Scheduleblocks sb : scheduleBlocks) { SB2Strings += sb.toString(); } school.setScheduleblocks(SB2Strings); } model.addAttribute("school", schools); return "admin"; } List<Schools> schools = SchoolDAO.allSchools(); if (schools != null) { model.addAttribute("school", schools); } return "index"; }
From source file:com.github.carlomicieli.nerdmovies.security.SpringSecurityService.java
@Override public void authenticate(MailUser user) { MailUserDetails det = new MailUserDetails(user); Authentication authentication = new UsernamePasswordAuthenticationToken(det, det.getPassword(), det.getAuthorities());//from w ww . j av a 2 s. c o m SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:com.marklogic.samplestack.domain.ClientRole.java
/** * Provides the database client role implied by the security context for the spring application. * @return The ClientRole enum value that corresponds to the current logged-in user. *//*from w ww. jav a 2 s.c o m*/ public static ClientRole securityContextRole() { SecurityContext secContext = SecurityContextHolder.getContext(); Collection<? extends GrantedAuthority> auths = secContext.getAuthentication().getAuthorities(); if (auths.contains(new SimpleGrantedAuthority("ROLE_CONTRIBUTORS"))) { return SAMPLESTACK_CONTRIBUTOR; } else { return SAMPLESTACK_GUEST; } }
From source file:com.lateralthoughts.commons.security.SecurityUtils.java
public static Authentication currentAuthentication() { return SecurityContextHolder.getContext().getAuthentication(); }
From source file:pl.java.scalatech.audit.SpringSecurityAuditorAware.java
@Override public User getCurrentAuditor() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String login = ANONYMOUS;//from w w w . j a v a2 s .c o m if (auth != null) { login = auth.getName(); } log.info("+++++++++++++++++++ +++++++++++++++++++++++++++++ login from security context : {}", login); Optional<User> user = userRepository.findByLogin(login); User loaded = user.orElseThrow(() -> new IllegalArgumentException("user not exists")); log.info("+++++++++++++++++ +++++++++++++++++++++++++++++ {}", loaded); return loaded; }
From source file:cz.fi.muni.pa036.airticketbooking.service.SecurityServiceImpl.java
public boolean isCurrentlyLoggedUserAdmin() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) auth.getAuthorities(); Iterator<SimpleGrantedAuthority> authoritiesIterator = authorities.iterator(); while (authoritiesIterator.hasNext()) { if (authoritiesIterator.next().getAuthority().equals("ROLE_ADMIN")) { return true; }// w w w. j a v a 2 s . c o m } return false; }