List of usage examples for org.springframework.security.core GrantedAuthority getAuthority
String getAuthority();
GrantedAuthority
can be represented as a String
and that String
is sufficient in precision to be relied upon for an access control decision by an AccessDecisionManager (or delegate), this method should return such a String
. From source file:org.wicketopia.spring.security.SpringSecurityProvider.java
@Override public boolean checkRoles(Set<String> roles) { SecurityContext securityContext = SecurityContextHolder.getContext(); if (securityContext == null || securityContext.getAuthentication() == null || securityContext.getAuthentication().getAuthorities() == null) { return false; }//from w w w .ja va2 s . co m for (GrantedAuthority authority : securityContext.getAuthentication().getAuthorities()) { if (roles.contains(authority.getAuthority())) { return true; } } return false; }
From source file:com.olegchir.flussonic_userlinks.auth.AuthSuccessHandler.java
/** Builds the target URL according to the logic defined in the main class Javadoc. */ protected String determineTargetUrl(Authentication authentication) { boolean isUser = false; boolean isAdmin = false; Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority grantedAuthority : authorities) { if (grantedAuthority.getAuthority().equals("ROLE_USER")) { isUser = true;// w w w . jav a 2 s . co m break; } else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) { isAdmin = true; break; } } if (isUser) { return "/dashboard"; } else if (isAdmin) { return "/admin_dashboard"; } else { throw new IllegalStateException(); } }
From source file:fi.vm.sade.organisaatio.resource.OrganisaatioDevResource.java
/** * Hakee autentikoituneen kyttjn roolit/*from ww w . j a va 2 s .c om*/ * @return Operaatio palauttaa samat kuin /cas/myroles. HUOM! Testikyttn tarkoitettu. */ @GET @Path("/myroles") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") @PreAuthorize("hasRole('ROLE_APP_ORGANISAATIOHALLINTA')") public String getRoles() { StringBuilder ret = new StringBuilder("["); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); ret.append("\""); ret.append(auth.getName()); ret.append("\","); for (GrantedAuthority ga : auth.getAuthorities()) { ret.append("\""); ret.append(ga.getAuthority().replace("ROLE_", "")); ret.append("\","); } ret.setCharAt(ret.length() - 1, ']'); return ret.toString(); }
From source file:org.owasp.webgoat.plugin.DisplayUser.java
public DisplayUser(WebGoatUser user) { this.username = user.getUsername(); this.admin = false; for (GrantedAuthority authority : user.getAuthorities()) { this.admin = (authority.getAuthority().contains("WEBGOAT_ADMIN")) ? true : false; }/*from www . j a v a 2 s. co m*/ // create userHash on the fly //TODO: persist userHash try { this.userHash = genUserHash(user.getUsername(), user.getPassword()); } catch (Exception ex) { //TODO: implement better fallback operation this.userHash = "Error generating user hash"; } }
From source file:tn.rnu.isi.gestioninscription.security.MySimpleUrlAuthenticationSuccessHandler.java
/** * Builds the target URL according to the logic defined in the main class * Javadoc.//from w w w .j av a2 s .com */ protected String determineTargetUrl(Authentication authentication) { boolean isEtudiant = false; boolean isAdmin = false; Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority grantedAuthority : authorities) { if (grantedAuthority.getAuthority().equals("ETUDIANT")) { isEtudiant = true; break; } else if (grantedAuthority.getAuthority().equals("ADMIN")) { isAdmin = true; break; } } if (isEtudiant) { return "/pages/index.xhtml"; } else if (isAdmin) { return "/admin/index.xhtml"; } else { throw new IllegalStateException(); } }
From source file:com.bigbang.iowaservices.handlers.CustomAuthenticationSuccessHandler.java
/** * Builds the target URL according to the logic defined in the main class * Javadoc./*w w w . j a v a2s . c om*/ */ protected String determineTargetUrl(Authentication authentication) { boolean isUser = false; boolean isAdmin = false; Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority grantedAuthority : authorities) { if (grantedAuthority.getAuthority().equals("ROLE_USER")) { isUser = true; break; } else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) { isAdmin = true; break; } } if (isUser) { return "/homepage.html"; } else if (isAdmin) { return "/addSkill.xhtml"; } else { throw new IllegalStateException(); } }
From source file:org.owasp.webgoat.controller.Start.java
private String getRole() { Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) SecurityContextHolder.getContext() .getAuthentication().getAuthorities(); String role = "N/A"; for (GrantedAuthority authority : authorities) { authority.getAuthority(); role = authority.getAuthority(); role = StringUtils.lowerCase(role); role = StringUtils.remove(role, "role_"); break;// www. j av a 2 s . co m } return role; }
From source file:com.callcenter.service.UserService.java
private Role findCurrentUserRole() { final Collection<GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication() .getAuthorities();//from w w w . j a va 2s. c o m final List<String> roleNames = new ArrayList<String>(); for (final GrantedAuthority grantedAuthority : authorities) { roleNames.add(grantedAuthority.getAuthority()); } return Role.findRoleByNameIn(roleNames); }
From source file:br.com.jreader.util.security.URLAuthenticationSuccessHandler.java
private String determineTargetUrl(Authentication authentication) { boolean isCommon = false; boolean isAdmin = false; Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); OUTER: for (GrantedAuthority grantedAuthority : authorities) { switch (grantedAuthority.getAuthority()) { case "ROLE_USER": isCommon = true;/* ww w . ja v a2s . c om*/ break; case "ROLE_ADMIN": isAdmin = true; break; } } if (isCommon) { return "/protected/main.xhtml"; } else if (isAdmin) { return "/protected/main.xhtml?admin=true"; } else { throw new IllegalStateException(); } }
From source file:at.ac.univie.isc.asio.security.SpringSecurityAuthorizer.java
@Override public void check(final Invocation invocation) throws RuntimeException { final Permission required = invocation.requires(); final Authentication authentication = fetchAndValidateAuthentication(); for (final GrantedAuthority granted : authentication.getAuthorities()) { if (required.name().equals(granted.getAuthority())) { return; }/* w w w .ja va 2 s.c om*/ } log.debug("not authorized to invoke - required {} - granted {}", required, authentication.getAuthorities()); throw new AccessDeniedException(Pretty.format("requires %s rights", required)); }