Example usage for org.springframework.security.core GrantedAuthority getAuthority

List of usage examples for org.springframework.security.core GrantedAuthority getAuthority

Introduction

In this page you can find the example usage for org.springframework.security.core GrantedAuthority getAuthority.

Prototype

String getAuthority();

Source Link

Document

If the 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.

Usage

From source file:org.ff4j.security.SpringSecurityAuthorisationManager.java

/** {@inheritDoc} */
public Set<String> getCurrentUserPermissions() {
    Set<String> listOfRoles = new LinkedHashSet<String>();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!(auth instanceof AnonymousAuthenticationToken)) {
        for (GrantedAuthority grantedAuthority : auth.getAuthorities()) {
            listOfRoles.add(grantedAuthority.getAuthority());
        }/*w w  w  .  ja  v a 2 s .c  o m*/
    }
    return listOfRoles;
}

From source file:org.modeshape.example.springsecurity.jcr.security.SpringSecurityContext.java

@Override
public boolean hasRole(String roleName) {
    for (GrantedAuthority authority : auth.getAuthorities()) {
        if (roleName.equals(authority.getAuthority())) {
            logger.info("[{}] has [{}] role.", auth.getName(), roleName);
            return true;
        }//from w w w .  j a  va2  s  .c o m
    }

    return false;
}

From source file:whitelabel.cloud.webapp.security.spring.UserDetailsImpl.java

public boolean haveRole(String ruolo) {
    for (GrantedAuthority a : getAuthorities()) {
        if (a.getAuthority().equals(ruolo)) {
            return true;
        }//  ww  w . j  a va  2  s.  com
    }
    return false;
}

From source file:org.jasig.cas.userdetails.LdapUserDetailsServiceTests.java

private boolean hasAuthority(final UserDetails user, final String name) {
    for (final GrantedAuthority authority : user.getAuthorities()) {
        if (authority.getAuthority().equals(name)) {
            return true;
        }/*  w w  w  .  j  av a 2s .c om*/
    }
    return false;
}

From source file:com.websystique.springsecurity.controller.ControladorOperario.java

private String getRole() {
    Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) SecurityContextHolder.getContext()
            .getAuthentication().getAuthorities();
    String rolename = "";
    for (GrantedAuthority authority : authorities) {
        rolename = authority.getAuthority();
    }//ww  w  .  java 2  s .c  o  m
    return rolename;
}

From source file:it.geosolutions.geostore.core.security.SimpleGrantedAuthoritiesMapper.java

@Override
public Collection<? extends GrantedAuthority> mapAuthorities(
        Collection<? extends GrantedAuthority> authorities) {
    if (mappings.isEmpty()) {
        return authorities;
    }//from   w  w w .  j  a va  2s  . c o m
    List<GrantedAuthority> result = new ArrayList<GrantedAuthority>();
    for (GrantedAuthority authority : authorities) {
        if (mappings.containsKey(authority.getAuthority())) {
            result.add(new GrantedAuthorityImpl(mappings.get(authority.getAuthority())));
        } else {
            result.add(authority);
        }
    }
    return result;
}

From source file:com.mothsoft.alexis.web.CurrentUser.java

public boolean isHasAnalysisRole() {
    for (final GrantedAuthority authority : CurrentUserUtil.getCurrentUser().getAuthorities()) {
        if (authority.getAuthority().equals("ROLE_ANALYSIS")) {
            return true;
        }/* ww  w. j a  va2 s . c  o  m*/
    }
    return false;
}

From source file:de.qucosa.urn.RoleBasedUrnConfiguration.java

@Bean
@Scope("request")
public URNConfiguration urnConfiguration(Authentication authentication,
        URNConfigurationMap urnConfigurationMap) {
    GrantedAuthority firstGranted = authentication.getAuthorities().iterator().next();
    String role = firstGranted.getAuthority();
    if (urnConfigurationMap.hasConfigurationFor(role)) {
        return urnConfigurationMap.get(role);
    } else {//w  ww .j a  v  a 2s . c om
        log.warn(
                "No URN configuration for authenticated role '{}' found. URN creation will not work for this request!",
                role);
    }
    return null;
}

From source file:com.hp.autonomy.frontend.configuration.authentication.OneToOneOrZeroSimpleAuthorityMapper.java

@Override
public Collection<? extends GrantedAuthority> mapAuthorities(
        final Collection<? extends GrantedAuthority> authorities) {
    final Collection<GrantedAuthority> output = new HashSet<>();

    for (final GrantedAuthority authority : authorities) {
        final String mappedAuthority = authorityMap.get(authority.getAuthority());

        if (mappedAuthority != null) {
            output.add(new SimpleGrantedAuthority(mappedAuthority));
        }/*from w ww.  j  a  v  a2s .  com*/
    }

    return output;
}

From source file:demo.domain.GrantedAuthoritySerializer.java

@Override
public void serialize(GrantedAuthority value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException {
    jgen.writeString(value.getAuthority());
}