advancedAuthorization: Roles, Authorities (RBAC) & Custom Filters

Why would hasRole('ADMIN') fail even though the user clearly has an 'ADMIN' authority in the database?

hasRole() automatically looks for an authority literally named 'ROLE_ADMIN' — if the database/authority-loading code stores just 'ADMIN' without the ROLE_ prefix, the check will never match. Either store the role correctly prefixed as ROLE_ADMIN, or use hasAuthority('ADMIN') instead, which does no automatic prefixing.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.

Why would hasRole('ADMIN') fail even though the user clearly has an 'ADMIN' authority in the database?

Next Step

Continue to What is the significance of rule ORDER inside authorizeHttpRequests()?← Back to all Spring Security questions