Real World Example

Marketplace Roles at Flipkart-Style Companies

Marketplaces like Flipkart, Amazon and Meesho have the same three groups ShopEase has: buyers, sellers (with a separate seller portal) and internal staff. Staff are further split by permission: a support agent can see orders and issue small refunds, a finance user can approve large refunds, and only a few admins can block sellers. This is exactly roles (coarse) plus authorities (fine).

URLRuleWho gets in
GET /api/products/**permitAllEveryone, even without login
/api/cart/**, /api/orders/**hasRole CUSTOMERCustomers (and, via hierarchy, sellers and admins)
/api/seller/**hasRole SELLERSellers and admins
POST /api/orders/*/refundhasAuthority order:refundSupport staff and admins
/api/admin/**hasRole ADMINAdmins only

ShopEase Security Config

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    static RoleHierarchy roleHierarchy() {
        return RoleHierarchyImpl.withDefaultRolePrefix()
                .role("ADMIN").implies("SELLER")
                .role("SELLER").implies("CUSTOMER")
                .build();
    }

    @Bean
    SecurityFilterChain api(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .requestMatchers(HttpMethod.GET, "/api/products/**", "/api/categories/**").permitAll()
                .requestMatchers("/api/auth/**").permitAll()
                .requestMatchers("/api/seller/**").hasRole("SELLER")
                .requestMatchers(HttpMethod.POST, "/api/orders/*/refund").hasAuthority("order:refund")
                .requestMatchers("/api/admin/**").hasRole("ADMIN")
                .requestMatchers("/api/cart/**", "/api/orders/**").hasRole("CUSTOMER")
                .anyRequest().authenticated())
            .httpBasic(Customizer.withDefaults());
        return http.build();
    }
}

Note: Later in this level we replace HTTP Basic with JWT. The authorization rules stay exactly the same: rules only look at the authorities in the SecurityContext, not at how the user logged in.