List of usage examples for org.springframework.security.core Authentication getAuthorities
Collection<? extends GrantedAuthority> getAuthorities();
AuthenticationManager
to indicate the authorities that the principal has been granted. From source file:com.epam.reportportal.auth.SsoEndpoint.java
@RequestMapping({ "/sso/me", "/sso/user" }) public Map<String, Object> user(Authentication user) { return ImmutableMap.<String, Object>builder().put("user", user.getName()).put("authorities", user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList())) .build();// w ww .j a va 2 s .com }
From source file:de.blizzy.documentr.web.filter.AuthenticationCreationTimeFilter.java
private int getHashCode(Authentication authentication) { int result = StringUtils.defaultString(authentication.getName()).hashCode(); for (GrantedAuthority authority : authentication.getAuthorities()) { result ^= authority.hashCode();/*w w w.j av a2 s . c om*/ } return result; }
From source file:fr.univrouen.poste.web.ProfilChoiceController.java
@RequestMapping public String profilChoice(@RequestParam(required = false) String profil) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities()); if (profil != null) { logger.info(auth.getName() + " a slectionn le profil " + profil); if ("membre".equals(profil)) { authorities.remove(new GrantedAuthorityImpl("ROLE_CANDIDAT")); }//from w w w . ja v a2 s .co m if ("candidat".equals(profil)) { authorities.remove(new GrantedAuthorityImpl("ROLE_MEMBRE")); } auth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), authorities); SecurityContextHolder.getContext().setAuthentication(auth); } if (auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_CANDIDAT")) && auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_MEMBRE"))) { return "profilChoice"; } else { return "index"; } }
From source file:fr.univrouen.poste.services.ReturnReceiptService.java
public final void sendDepotStatusIfRequired(Authentication auth) { String emailAddress = auth.getName(); boolean isCandidat = auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_CANDIDAT")); if (isCandidat) { MailReturnReceiptModeTypes mailReturnReceiptMode = AppliConfig.getCacheMailReturnReceiptModeType(); if (MailReturnReceiptModeTypes.EACH_SESSION.equals(mailReturnReceiptMode)) { String messageBody = ""; User candidat = User.findUsersByEmailAddress(emailAddress, null, null).getSingleResult(); List<PosteCandidature> candidatures = PosteCandidature.findPosteCandidaturesByCandidat(candidat) .getResultList();/*from w w w .java2 s . c o m*/ for (PosteCandidature candidature : candidatures) { messageBody = messageBody + "\n*Poste n" + candidature.getPoste().getNumEmploi() + "*"; for (PosteCandidatureFile candidatureFile : candidature.getCandidatureFiles()) { String filename = candidatureFile.getFilename(); String fileSize = candidatureFile.getFileSizeFormatted(); String sentDate = dateFormatter.print(candidatureFile.getSendTime(), Locale.getDefault()); messageBody = messageBody + "\n - " + filename + " - " + fileSize + " [" + sentDate + "]"; } } String mailFrom = AppliConfig.getCacheMailFrom(); String mailSubject = AppliConfig.getCacheMailSubject(); String mailMessage = AppliConfig.getCacheTexteMailCandidatReturnReceipt(); mailMessage = mailMessage.replaceAll("@@messageBody@@", messageBody); emailService.sendMessage(mailFrom, emailAddress, mailSubject, mailMessage); } } }
From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManager.java
public boolean isUserIsAdmin() { SecurityContext context = this.getSecurityContextHolder(); if (context == null) { return false; }/*from w w w .j av a2s . c om*/ Authentication authentication = context.getAuthentication(); if (authentication == null) { return false; } Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); return authorities.contains(new SimpleGrantedAuthority(AUTHORIZED_AUTHORITY)); }
From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor.java
@Override public boolean isAdmin() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); return a != null && AuthorityUtils.authorityListToSet(a.getAuthorities()).contains("uaa.admin"); }
From source file:nl.surfnet.coin.api.saml.SAMLAuthenticationManager.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final SAMLAuthenticationToken newAuthenticationToken = new SAMLAuthenticationToken( authentication.getPrincipal(), authentication.getAuthorities()); newAuthenticationToken.setAuthenticated(true); newAuthenticationToken.setDetails(authentication.getDetails()); return newAuthenticationToken; }
From source file:net.solarnetwork.central.dras.aop.SecurityAspectSupport.java
/** * Test if the current user has a specific role. * /*from www .j av a 2 s. co m*/ * <p>If more than one role is provided, any role is allowed to match, * i.e. the set of roles is treated as an "or" style match.</p> * * @param role the roles to test for * @return <em>true</em> if the current user has the role */ protected final boolean currentUserHasRole(final String... role) { // see if we return ALL programs, or just those for the current user Authentication auth = SecurityContextHolder.getContext().getAuthentication(); for (GrantedAuthority ga : auth.getAuthorities()) { for (String r : role) { if (r.equalsIgnoreCase(ga.getAuthority())) { return true; } } } return false; }
From source file:at.ac.univie.isc.asio.security.WhoamiResource.java
@GET @Produces(MediaType.APPLICATION_JSON)/* w ww . j a v a 2 s . c om*/ public AuthInfo getAuthInfo() { final Authentication authentication = security.getAuthentication(); final Identity identity = AuthTools.findIdentity(security); return AuthInfo.from(authentication.getName(), identity, authentication.getAuthorities()); }
From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor.java
@Override public Collection<? extends GrantedAuthority> getAuthorities() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); return a == null ? Collections.<GrantedAuthority>emptySet() : a.getAuthorities(); }