concept authority in category spring

This is an excerpt from Manning's book Spring Security in Action.
Depending on the chosen architecture for the system, you find authentication and authorization at the level of the entire system, as well as for any of the components. And as we’ll see further along in this book, with Spring Security, you’ll sometimes prefer to use authorization even for different tiers of the same component. In chapter 16, we’ll discuss more on global methods security, which refers to this aspect. The design gets even more complicated as you can have a predefined set of roles and authorities.
Figure 7.3 A user has one or more authorities (actions a user can do). The UserDetailsService obtains all the details about the user, including the authorities, during the authentication process. The application uses the authorities, represented by the GrantedAuthority interface, for authorization after it successfully authenticates the user.
![]()
Listing 7.1 shows you the definition of the GrantedAuthority contract. The authority is an action that a user can do with a resource of the system. An authority has a name that the getAuthority() behavior of the object returns as a String. We’ll use the name of the authority when defining the custom authorization rule. Often an authorization rule can look like this: “Jane is allowed to delete the product records” or “John is allowed to read the document records”. In these cases, “delete” and “read” are the granted authorities. The application allows the users “Jane” and “John” to perform these actions. You’ll often encounter these actions having names like “read”, “write” or “delete”.
Listing 7.1 The GrantedAuthority contract
public interface GrantedAuthority extends Serializable { String getAuthority(); }The UserDetails, which is the contract describing the user in Spring Security, has a collection of GrantedAuthority instances, as presented in figure 7.3. This way, a user may be allowed one or more privileges. The getAuthorities() method returns the collection of GrantedAuthority instances. In listing 7.2, you can review this method in the UserDetails contract. We will implement this method such that it returns all the authorities granted for the user. After the authentication ends, the authorities are part of the details about the user that logged in, which the application can use to grant permissions.