Spring Security HTTP Basic Authentication Example
HTTP basic authentication (BA) is a simple authentication mechanism. When a web client requests any secured web resources, server sends an HTTP response with status code 401 (Unauthorized) and WWW-Authenticate HTTP header like WWW-Authenticate: Basic realm="realm here". And browser pops up a login dialog prompting for User name and Password for that realm.
This example shows how to configure HTTP basic authentication using Spring Security framework.
Tools and Technologies used in this article :
We'll modify our previous post Spring Security 3 Hello World Example to configure HTTP Basic authentication.
1. Modify Spring Security Configuration
Just add <http-basic/> in Spring Security configuration xml to configure HTTP basic authentication.File : WEB-INF/spring-security.xml
2. Overall Project Structure
Start the server and deploy the web application. Try to open the URL http://
Browser will open the authentication dialog prompting for username and password.
For wrong credentials, following authentication failure message will also be displayed.
For correct username (srccodes) and password (password), you'll be able to view the secured page.