Class SimpleAuthorityMapper

  • All Implemented Interfaces:
    org.springframework.beans.factory.InitializingBean, GrantedAuthoritiesMapper

    public final class SimpleAuthorityMapper
    extends java.lang.Object
    implements GrantedAuthoritiesMapper, org.springframework.beans.factory.InitializingBean
    Simple one-to-one GrantedAuthoritiesMapper which allows for case conversion of the authority name and the addition of a string prefix (which defaults to ROLE_ ).
    Since:
    3.1
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()  
      java.util.Set<GrantedAuthority> mapAuthorities​(java.util.Collection<? extends GrantedAuthority> authorities)
      Creates a mapping of the supplied authorities based on the case-conversion and prefix settings.
      void setConvertToLowerCase​(boolean convertToLowerCase)
      Whether to convert the authority value to lower case in the mapping.
      void setConvertToUpperCase​(boolean convertToUpperCase)
      Whether to convert the authority value to upper case in the mapping.
      void setDefaultAuthority​(java.lang.String authority)
      Sets a default authority to be assigned to all users
      void setPrefix​(java.lang.String prefix)
      Sets the prefix which should be added to the authority name (if it doesn't already exist)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleAuthorityMapper

        public SimpleAuthorityMapper()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • mapAuthorities

        public java.util.Set<GrantedAuthority> mapAuthorities​(java.util.Collection<? extends GrantedAuthority> authorities)
        Creates a mapping of the supplied authorities based on the case-conversion and prefix settings. The mapping will be one-to-one unless duplicates are produced during the conversion. If a default authority has been set, this will also be assigned to each mapping.
        Specified by:
        mapAuthorities in interface GrantedAuthoritiesMapper
        Parameters:
        authorities - the original authorities
        Returns:
        the converted set of authorities
      • setPrefix

        public void setPrefix​(java.lang.String prefix)
        Sets the prefix which should be added to the authority name (if it doesn't already exist)
        Parameters:
        prefix - the prefix, typically to satisfy the behaviour of an AccessDecisionVoter.
      • setConvertToUpperCase

        public void setConvertToUpperCase​(boolean convertToUpperCase)
        Whether to convert the authority value to upper case in the mapping.
        Parameters:
        convertToUpperCase - defaults to false
      • setConvertToLowerCase

        public void setConvertToLowerCase​(boolean convertToLowerCase)
        Whether to convert the authority value to lower case in the mapping.
        Parameters:
        convertToLowerCase - defaults to false
      • setDefaultAuthority

        public void setDefaultAuthority​(java.lang.String authority)
        Sets a default authority to be assigned to all users
        Parameters:
        authority - the name of the authority to be assigned to all users.