Skip to main content

27 posts tagged with "spring-boot"

View All Tags

From HTML Error Pages to Beautiful JSON: Fixing JWT Authentication Errors in Spring Boot

· 13 min read
Mahmut Salman
Software Developer

"Why is my API returning HTML error pages?!" I stared at my console in disbelief. My React frontend was trying to parse JSON, but Spring Security was happily serving up a Whitelabel Error Page for failed authentication attempts. This took me 3 hours to fix. Let me show you how to make Spring Security play nice with modern frontends. 🎨✨

Mastering Two-Tier Exception Handling in Spring Boot: A Complete Guide

· 11 min read
Mahmut Salman
Software Developer

Ever wondered why sometimes your Spring Boot exceptions are caught by @RestControllerAdvice and other times they're not? Or why your custom AccessDeniedHandler returns 403 before your controller even executes? I spent hours debugging this mystery until I understood Spring Boot's two-tier exception handling architecture. Let me save you the confusion. 🎯

Wait, You're Exposing Your Password?! Understanding Input vs Output DTOs in Spring Boot

· 14 min read
Mahmut Salman
Software Developer

I'll never forget the day I accidentally exposed user passwords in my API responses. I returned the entire User entity from a GET endpoint, thinking "Spring Boot will handle it!" Spoiler alert: It returned EVERYTHING—including hashed passwords, internal IDs, and timestamps. My code reviewer nearly had a heart attack. 😱 That's when I learned about DTOs. Let me save you from this nightmare.

The Mystery of the 403 Login: Understanding Spring Security's Two-Stage Authentication

· 11 min read
Mahmut Salman
Software Developer

"My login endpoint is returning 403 Forbidden! But I configured it as .permitAll() in SecurityConfig! Why is the JwtFilter still blocking it?" I spent 2 hours debugging this. Turns out, I had a fundamental misunderstanding of how Spring Security works. The JwtFilter doesn't "skip" endpoints - it runs on EVERYTHING. Let me explain the magic. 🎩✨

My 'Aha!' Moment: Why Public/Private Actually Matters (And I Was Wrong About Security)

· 14 min read
Mahmut Salman
Software Developer

"Why make something private? Just make everything public. If the coder knows which method to call, they call it. Problem solved, right?" That was me a week ago. I was so wrong. Here's my journey from "public/private is just fancy nonsense" to "holy crap, this actually makes sense!" 🤯

Why Create Custom Exceptions? It's Not Just About the Name!

· 10 min read
Mahmut Salman
Software Developer

"Why create InvalidCredentialsException extending RuntimeException? Isn't it just to get a descriptive name instead of generic RuntimeException?" No! The name is only a small part. The real power is type-safe error handling - allowing Spring to distinguish between different errors and handle them differently without string parsing. Let's see why custom exceptions are essential, not just fancy naming.

Dev vs Prod: Why You Can't Store Secrets in Files on Production Servers

· 9 min read
Mahmut Salman
Software Developer

"Why do we use application.properties for secrets in development but environment variables in production?" Because file-based secrets are fine for your local machine (only you have access), but dangerous on production servers (many people have access, files can be compromised). Let's understand why this distinction matters and how to properly manage secrets across environments.

Why My Object Changes Don't Stick: In-Memory vs Database Persistence

· 9 min read
Mahmut Salman
Software Developer

"I changed the object's failedLoginAttempts field, but when I query the database again, it's back to the old value! In high school, changing object properties just worked - why do I need to call save() in Spring Boot?" This is the fundamental difference between in-memory objects (what you learned in school) and database-backed objects (what you use in production). Let's understand why object changes don't automatically persist to the database.

Why Two Methods for JWT Token Generation? Understanding Single Responsibility Principle

· 12 min read
Mahmut Salman
Software Developer

"Why do we need both generateToken() (public) and createToken() (private) instead of just one method?" Because separation of concerns makes your code extensible. The public method handles what claims to add (business logic), while the private method handles how to build the JWT (technical details). This lets you add new token types without repeating code. Let's understand why this design pattern is essential.