List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:example.springdata.jpa.security.SecurityEvaluationContextExtension.java
@Override public SecurityExpressionRoot getRootObject() { return new SecurityExpressionRoot(SecurityContextHolder.getContext().getAuthentication()) { }; }
From source file:it.reply.orchestrator.service.security.OAuth2TokenService.java
/** * Get the current OAuth2 token.// w w w . ja v a 2 s .com * * @return the OAuth2 token. * @throws IllegalStateException * if the security is disabled, the user is not authenticated or the call is made of an * HTTP session. */ public String getOAuth2Token() { if (!oidcProperties.isEnabled()) { throw new IllegalStateException("Security is not enabled"); } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null || !(auth instanceof IndigoOAuth2Authentication)) { throw new IllegalStateException("User is not authenticated"); } IndigoOAuth2Authentication indigoAuth = (IndigoOAuth2Authentication) auth; return indigoAuth.getToken().getValue(); }
From source file:com.mastercard.test.spring.security.SpringSecurityJUnit4ClassRunnerBasicTests.java
public User getUser() { return (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); }
From source file:org.jblogcms.core.security.service.SecurityServiceImpl.java
@Override public AccountDetails getCurrentAccount() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); try {/*w ww . ja v a 2 s . co m*/ if (!auth.getName().equals("anonymousUser")) { return ((AccountDetails) auth.getPrincipal()); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.shredzone.cilla.service.impl.SecurityServiceImpl.java
@Override public boolean hasRole(String role) { return SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream() .map(GrantedAuthority::getAuthority).anyMatch(isEqual(role)); }
From source file:edu.uiowa.icts.util.DebugRolesTag.java
/** * <p>doStartTag.</p>//from ww w . j a v a 2s . co m * * @return a int. */ public int doStartTag() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); if (authorities != null) { iterator = authorities.iterator(); } else { log.debug("no authorities, list is null"); } } else { log.debug("authentication object is null"); } if (iterator != null && iterator.hasNext()) { pageContext.setAttribute("role", iterator.next().getAuthority()); return EVAL_BODY_INCLUDE; } return SKIP_BODY; }
From source file:id.co.sigma.zk.spring.security.SecurityUtil.java
public static WebAuthenticationDetails getAuthDetails() { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { try {//from w w w.j a v a 2 s. c o m Object p = auth.getDetails(); if (p instanceof WebAuthenticationDetails) return (WebAuthenticationDetails) p; } catch (RuntimeException e) { e.printStackTrace(); throw e; } } return null; }
From source file:com.goldCityWeb.controller.ME_SettingController.java
/** * //from w w w . j av a 2s .c om * @param model * @param request * @return */ @RequestMapping(value = "/index") public String renZheng(Model model, HttpServletRequest request) { SysUsers user = (SysUsers) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Company company = companyService.queryCompanyByUserId(user.getId()); model.addAttribute("company", company); List<CompanyType> ctList = companyService.queryAllCompanyType(); model.addAttribute("ctList", ctList); /*if(company!=null){ String pre = SettingUtils.getCommonSetting("base.image.url"); if(!StringUtils.isBlank(company.getLicence())){ company.setLicence(pre + company.getLicence()); } if(!StringUtils.isBlank(company.getLogo())){ company.setLogo(pre + company.getLogo()); } if(!StringUtils.isBlank(company.getReal_auth())){ company.setReal_auth(pre + company.getReal_auth()); } if(!StringUtils.isBlank(company.getTrade_license())){ company.setTrade_license(pre + company.getTrade_license()); } }*/ return "merchant/renZheng"; }
From source file:cn.org.once.cstack.utils.AuthentificationUtils.java
public User getAuthentificatedUser() throws ServiceException { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return userService.findByLogin(auth.getName()); }
From source file:mb.MbKorisnik.java
public String vratiTipKorisnika() { Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder .getContext().getAuthentication().getAuthorities(); String role = ""; for (SimpleGrantedAuthority a : authorities) { role += a.getAuthority() + " "; }/*w w w . j av a 2s. c o m*/ return role; }