Skip to main content

Spring

Securing Spring MVC with SiteMinder Pre‑Authentication – A Step‑by‑Step Guide

Enterprise Java applications frequently live behind a corporate Single Sign-On (SSO) gateway such as Broadcom (formerly CA) SiteMinder. SiteMinder authenticates users at the reverse-proxy layer — before any request ever reaches your application server — and then injects the verified identity into a well-known HTTP request header (typically SM_USER). Your Spring Boot application simply trusts that header and builds a security context from it, with no login form and no password handling of its own. This pattern is called pre-authentication: the heavy lifting of credential verification is delegated to an external system, and your app only needs to map the already-authenticated identity to application-level roles. Spring Security has first-class support for this via RequestHeaderAuthenticationFilter and PreAuthenticatedAuthenticationProvider. This tutorial walks through a complete Spring Boot 3.x / Spring Security 6.x configuration, covering Maven dependencies, the security filter chain using the modern lambda DSL, a UserDetailsService implementation, and tips for testing locally without a real SiteMinder agent.

Leveraging Virtual Threads in Spring Boot 3.4+: Building High-Throughput Services

I've been shipping Java services for over a decade. I've tuned Tomcat thread pools, profiled connection leaks, and once reluctantly rewrote a critical service in WebFlux because blocking threads were killing us at scale. So when Java 21 landed with virtual threads baked in, I didn't just read the JEP — I immediately threw it at a production-like load test. The results were not subtle. This post is what I wish existed back then: an honest, methodical walkthrough of enabling virtual threads in Spring Boot 3.4, with real benchmark methodology, the gotchas that will actually bite you in production, and a clear-eyed take on when virtual threads won't help at all.

Spring Boot RestTemplate with Basic Auth: A Modern Guide

Communicating between microservices is a fundamental aspect of modern application development. Often, these services need to be secured. One of the simplest and most widely supported methods for securing REST APIs is Basic Authentication. In this guide, we’ll walk through how to configure and use Spring Boot’s RestTemplate to consume a REST API protected with Basic Auth. We’ll cover the modern, recommended approach using Spring Security’s component-based configuration, updating older patterns you might find in other tutorials. Project Setup First, ensure your Spring Boot project includes the spring-boot-starter-web dependency. This starter conveniently bundles everything we need, including Spring MVC for creating the REST service, Tomcat as the embedded server, and RestTemplate support. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> You’ll also need the spring-boot-starter-security dependency to enable security features. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>

Custom Validation in Spring Boot: Beyond the Basics!

We’ve all been there – building a Spring Boot application, slapping on a @NotBlank or @Size annotation, and feeling pretty good about our data integrity. But what happens when our validation needs get a little… funkier? What if we need to check if a String contains specific keywords, or ensure two fields have a particular relationship? That’s where Spring’s custom validation truly shines! While the built-in validators are fantastic for common scenarios, understanding how to roll your own opens up a whole new world of robust data handling. In this post, we’re going to dive into creating custom validators, making our Spring Boot apps even smarter. Why Custom Validation? Imagine a scenario where you’re building a user registration form. You might have these requirements: Password Complexity: Must contain at least one uppercase, one lowercase, one digit, and one special character. Username Uniqueness (Client-side): While server-side uniqueness is a given, you might want to prevent common or reserved usernames. Date Range Check: An ‘end date’ must always be after a ‘start date’. These go beyond what @NotNull or @Min can handle. That’s our cue for custom validation!

Building Your First Spring RESTful API: A “Hello World” Guide

Let's dive into the exciting world of Spring Boot and RESTful APIs. If you’re looking to build robust, scalable web services, Spring Boot is an excellent choice and understanding how to create a simple REST API is a fundamental first step. In this tutorial, we’ll walk through creating a “Hello World” RESTful service that exposes JSON data. This example will cover the basic setup of a Spring Boot project and demonstrating how to handle HTTP GET requests. Prerequisites Before we begin, make sure you have the following installed: Java Development Kit (JDK) 8 or higher: You can download it from the Oracle website. Apache Maven: For project management and dependency handling. Download from the Maven website. An Integrated Development Environment (IDE): IntelliJ IDEA, Eclipse, or VS Code with Java extensions are all great choices. Step 1: Create a Spring Boot Project The easiest way to start a Spring Boot project is by using the Spring Initializr. Go to the website and configure your project as follows: Project: Maven Project Language: Java Spring Boot: Choose the latest stable version (e.g., 2.7.x or 3.x.x) Group: com.ankurm.restapi Artifact: hello-world Name: hello-world Package name: com.ankurm.restapi.helloworld Packaging: Jar Java: 17 (or your preferred version) Dependencies: Add Spring Web Click “Generate” to download the project as a ZIP file. Extract it to your desired location.