liveBook · Manning

getAuthorities()

As explained in Spring Security in Action, Second Edition

getAuthorities() is a UserDetails method that returns the authorities granted to the user.

getAuthorities() is a UserDetails method that returns the collection of GrantedAuthority instances granted to a user. Authorities represent permitted actions such as reading, writing, or deleting data. section 3.2.1 section 7.1

Use the returned authorities to:

  • Represent fine-grained privileges; Spring Security can also use authorities to represent roles, which group privileges. section 3.2.1
  • Carry a user’s granted permissions into the authenticated user details after authentication. section 7.1
  • Support authorization rules that restrict actions such as reading, writing, or deleting resources. section 3.2.1

Permission-based access

If Jane has the delete authority and John has the read authority, authorization rules can permit Jane to delete product records and John to read documents. section 7.1

Listing 7.2 The getAuthorities() method from the UserDetails contract
public interface UserDetails extends Serializable {
  Collection<? extends GrantedAuthority> getAuthorities();

  // Omitted code
}

Inspect the UserDetails contract signature showing that getAuthorities() returns a collection of GrantedAuthority instances. section 7.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines the interface return type and authentication flow, but does not provide a concrete UserDetails implementation.
Examples
Uses read, write, and delete privileges, including Jane deleting product records and John reading documents.
What you can do after
Apply returned authorities to grant or restrict users’ permitted application actions.
How it connects
Connects UserDetails, GrantedAuthority, UserDetailsService, authentication, authorization, privileges, and roles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.