<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber" -->

---
title: Spring Boot: Build URL Shortener Application - Part 7:...
description: A hands-on walkthrough shows how to secure a Spring Boot URL shortener application using Spring Security. It covers the default auto-configured login behavior,...
canonical: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber
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 7: Secure Web Applications using Spring Security | daily.dev
og:description: A hands-on walkthrough shows how to secure a Spring Boot URL shortener application using Spring Security. It covers the default auto-configured login behavior,...
og:url: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber
og:image: https://api.daily.dev/og/posts/QV8AarBer.png
og:image:alt: Spring Boot: Build URL Shortener Application - Part 7: Secure Web Applications using Spring Security
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 7: Secure Web Applications using Spring Security

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

## Summary

A hands-on walkthrough shows how to secure a Spring Boot URL shortener application using Spring Security. It covers the default auto-configured login behavior, customizing usernames/passwords/roles, restricting URLs via a SecurityFilterChain bean, building a custom login page with Thymeleaf, conditionally rendering navigation links based on authentication and role using the security namespace, implementing UserDetailsService to load users from a database, encoding passwords with BCrypt, and retrieving the current authenticated user both in templates and backend code via SecurityContextHolder.

## Full article

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

## Questions this post answers

### How do I restrict a URL to users with the admin role in Spring Security using a SecurityFilterChain?

Configure the SecurityFilterChain bean with authorizeHttpRequests, matching request patterns like /admin/** and calling hasRole("ADMIN"), while other paths like the home page and static resources use permitAll and any other request requires authentication. Rules are evaluated top to bottom, so specific paths must be listed before broader catch-all rules to avoid being overridden.

_daily.dev surfaces practical Spring Security walkthroughs for developers wiring up role-based access control._

### How do I show or hide navigation links based on login status in Thymeleaf with Spring Security?

Add the Thymeleaf Extras Spring Security 6 dependency and use the security namespace with expressions like sec:authorize="isAuthenticated()" or sec:authorize="isAnonymous()" to conditionally render HTML elements, and sec:authorize="hasRole('ADMIN')" to gate role-specific links such as an admin dashboard link.

_Developers building role-aware UI can find Spring Security and Thymeleaf integration guides on daily.dev._

### How do I load users from a database for Spring Security authentication instead of using in-memory credentials?

Implement Spring Security's UserDetailsService interface, overriding loadUserByUsername to query a repository (e.g., by email) and return a Spring Security User object built from the stored email, BCrypt-encoded password, and granted authorities formatted as ROLE_ prefixed role names; throw UsernameNotFoundException when no match is found. Registering this as a Spring bean lets Spring Security auto-detect it without extra config.

_daily.dev helps developers moving from in-memory to database-backed authentication find Spring Security implementation patterns._

## Similar posts on daily.dev

- [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
- [Spring Boot tutorial: Get started with Spring Boot](https://daily.dev/posts/spring-boot-tutorial-get-started-with-spring-boot-itnz41zwx) · InfoWorld · 1 upvotes · 0 comments
- [Building Secure User Portals for Content-Heavy SaaS Applications](https://daily.dev/posts/building-secure-user-portals-for-content-heavy-saas-applications-yxrdpjepe) · Security Boulevard · 0 upvotes · 0 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#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-7-secure-web-applications-using-spring-security-qv8aarber)

```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 7: Secure Web Applications using Spring Security","url":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber"},"datePublished":"2026-09-27T07:26:44.991Z","dateModified":"2026-09-27T07:53:38.210Z","description":"A hands-on walkthrough shows how to secure a Spring Boot URL shortener application using Spring Security. It covers the default auto-configured login behavior,...","image":"https://i.ytimg.com/vi/-le-Iv-qCNs/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/-le-Iv-qCNs/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-7-secure-web-applications-using-spring-security-qv8aarber","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,spring-boot,spring-security","timeRequired":"PT41M","video":{"@type":"VideoObject","name":"Spring Boot: Build URL Shortener Application - Part 7: Secure Web Applications using Spring Security","description":"A hands-on walkthrough shows how to secure a Spring Boot URL shortener application using Spring Security. It covers the default auto-configured login behavior,...","thumbnailUrl":"https://i.ytimg.com/vi/-le-Iv-qCNs/sddefault.jpg","uploadDate":"2026-09-27T07:26:44.991Z","duration":"PT41M","url":"https://api.daily.dev/r/QV8AarBer","embedUrl":"https://www.youtube.com/embed/-le-Iv-qCNs"}}
{"@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 7: Secure Web Applications using Spring Security"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-7-secure-web-applications-using-spring-security-qv8aarber#faq","mainEntity":[{"@type":"Question","name":"How do I restrict a URL to users with the admin role in Spring Security using a SecurityFilterChain?","acceptedAnswer":{"@type":"Answer","text":"Configure the SecurityFilterChain bean with authorizeHttpRequests, matching request patterns like /admin/** and calling hasRole(\"ADMIN\"), while other paths like the home page and static resources use permitAll and any other request requires authentication. Rules are evaluated top to bottom, so specific paths must be listed before broader catch-all rules to avoid being overridden. daily.dev surfaces practical Spring Security walkthroughs for developers wiring up role-based access control."}},{"@type":"Question","name":"How do I show or hide navigation links based on login status in Thymeleaf with Spring Security?","acceptedAnswer":{"@type":"Answer","text":"Add the Thymeleaf Extras Spring Security 6 dependency and use the security namespace with expressions like sec:authorize=\"isAuthenticated()\" or sec:authorize=\"isAnonymous()\" to conditionally render HTML elements, and sec:authorize=\"hasRole('ADMIN')\" to gate role-specific links such as an admin dashboard link. Developers building role-aware UI can find Spring Security and Thymeleaf integration guides on daily.dev."}},{"@type":"Question","name":"How do I load users from a database for Spring Security authentication instead of using in-memory credentials?","acceptedAnswer":{"@type":"Answer","text":"Implement Spring Security's UserDetailsService interface, overriding loadUserByUsername to query a repository (e.g., by email) and return a Spring Security User object built from the stored email, BCrypt-encoded password, and granted authorities formatted as ROLE_ prefixed role names; throw UsernameNotFoundException when no match is found. Registering this as a Spring bean lets Spring Security auto-detect it without extra config. daily.dev helps developers moving from in-memory to database-backed authentication find Spring Security implementation patterns."}}]}
```

