<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s" -->

---
title: Spring Boot: Build URL Shortener Application - Part 10:...
description: Part 10 of a Spring Boot URL shortener tutorial series walks through building the 'My URLs' and admin dashboard pages, including pagination fixes and bulk...
canonical: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy | daily.dev
og:description: Part 10 of a Spring Boot URL shortener tutorial series walks through building the 'My URLs' and admin dashboard pages, including pagination fixes and bulk...
og:url: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s
og:image: https://api.daily.dev/og/posts/KWQ8Phq8S.png
og:image:alt: Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy

**[SivaLabs \(YouTube\)](https://daily.dev/sources/sivalabs-youtube)** · 23 min read · 0 upvotes · 0 comments

## Summary

Part 10 of a Spring Boot URL shortener tutorial series walks through building the 'My URLs' and admin dashboard pages, including pagination fixes and bulk delete via checkboxes using derived query methods like deleteByIdIn. The main focus shifts to security: enabling method-level security with @EnableMethodSecurity and @PreAuthorize annotations instead of centralizing all rules in WebSecurityConfig, and configuring a RoleHierarchy bean so that the admin role automatically inherits all permissions of the user role, demonstrated by making the admin account able to see the 'My URLs' page without being explicitly assigned the user role.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=WsLyB-8ZpuI>

## Questions this post answers

### How do I make admin role inherit all permissions of a user role in Spring Security?

Define a RoleHierarchy bean using RoleHierarchyImpl.fromHierarchy() and specify a rule such as 'ROLE_ADMIN > ROLE_USER'. This tells Spring Security that any authority granted to ROLE_USER is automatically available to a user holding ROLE_ADMIN, so an admin account assigned only ROLE_ADMIN can still pass a hasRole('USER') check without being separately assigned ROLE_USER.

_daily.dev surfaces practical Spring Security guides for developers wiring up role hierarchies like this._

### How do I enable method-level security annotations like @PreAuthorize in Spring Boot instead of configuring everything in WebSecurityConfig?

Add the @EnableMethodSecurity annotation to a configuration class, which activates annotation-based method security such as @PreAuthorize. Then place expressions like @PreAuthorize("hasRole('ADMIN')") at the class or method level on controllers, letting you restrict access per-endpoint instead of listing every admin-specific URL pattern in the centralized security config.

_Developers weighing centralized versus annotation-based security setups can find similar comparisons on daily.dev._

## Similar posts on daily.dev

- [Granular Authorization in Spring Boot: Beyond Role Checks](https://daily.dev/posts/granular-authorization-in-spring-boot-beyond-role-checks-bfjgs4egt) · Sergio Lema · 18 upvotes · 1 comments
- [Secure Your APIs: OAuth2 and JWT for Beginners](https://daily.dev/posts/secure-your-apis-oauth2-and-jwt-for-beginners-hh8guukwi) · JetBrains · 5 upvotes · 0 comments
- [System Design Drill Day 14: URL Shortener and Unique ID Generation](https://daily.dev/posts/system-design-drill-day-14-url-shortener-and-unique-id-generation-fwoorwvvg) · C\# Corner · 13 upvotes · 1 comments

---

Tags: [#java](https://daily.dev/tags/java), [#spring](https://daily.dev/tags/spring), [#spring-boot](https://daily.dev/tags/spring-boot), [#spring-security](https://daily.dev/tags/spring-security)

[View this post on daily.dev](https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy","url":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s"},"datePublished":"2026-09-27T07:26:37.659Z","dateModified":"2026-09-27T07:53:34.016Z","description":"Part 10 of a Spring Boot URL shortener tutorial series walks through building the 'My URLs' and admin dashboard pages, including pagination fixes and bulk...","image":"https://i.ytimg.com/vi/WsLyB-8ZpuI/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/WsLyB-8ZpuI/sddefault.jpg","isAccessibleForFree":true,"articleSection":"SivaLabs (YouTube)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SivaLabs (YouTube)","logo":"https://media.daily.dev/image/upload/s--8ATVo4an--/f_auto,q_auto/v1790493987/logos/sivalabs-youtube?_a=BAMAMicg0","url":"https://daily.dev/sources/sivalabs-youtube"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,spring,spring-boot,spring-security","timeRequired":"PT23M","video":{"@type":"VideoObject","name":"Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy","description":"Part 10 of a Spring Boot URL shortener tutorial series walks through building the 'My URLs' and admin dashboard pages, including pagination fixes and bulk...","thumbnailUrl":"https://i.ytimg.com/vi/WsLyB-8ZpuI/sddefault.jpg","uploadDate":"2026-09-27T07:26:37.659Z","duration":"PT23M","url":"https://api.daily.dev/r/KWQ8Phq8S","embedUrl":"https://www.youtube.com/embed/WsLyB-8ZpuI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SivaLabs (YouTube)","item":"https://daily.dev/sources/sivalabs-youtube"},{"@type":"ListItem","position":3,"name":"Spring Boot: Build URL Shortener Application - Part 10: Method Level Security and Role Hierarchy"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-10-method-level-security-and-role-hierarchy-kwq8phq8s#faq","mainEntity":[{"@type":"Question","name":"How do I make admin role inherit all permissions of a user role in Spring Security?","acceptedAnswer":{"@type":"Answer","text":"Define a RoleHierarchy bean using RoleHierarchyImpl.fromHierarchy() and specify a rule such as 'ROLE_ADMIN \u003e ROLE_USER'. This tells Spring Security that any authority granted to ROLE_USER is automatically available to a user holding ROLE_ADMIN, so an admin account assigned only ROLE_ADMIN can still pass a hasRole('USER') check without being separately assigned ROLE_USER. daily.dev surfaces practical Spring Security guides for developers wiring up role hierarchies like this."}},{"@type":"Question","name":"How do I enable method-level security annotations like @PreAuthorize in Spring Boot instead of configuring everything in WebSecurityConfig?","acceptedAnswer":{"@type":"Answer","text":"Add the @EnableMethodSecurity annotation to a configuration class, which activates annotation-based method security such as @PreAuthorize. Then place expressions like @PreAuthorize(\"hasRole('ADMIN')\") at the class or method level on controllers, letting you restrict access per-endpoint instead of listing every admin-specific URL pattern in the centralized security config. Developers weighing centralized versus annotation-based security setups can find similar comparisons on daily.dev."}}]}
```

