Spring Security basics : How to configure your first security-config.xml

To get up and running with basic Spring Security your application needs a entry in the web.xml and  security-config.xml.
So lets have a look at the configuration needed to enable Spring Security in your application and what they really mean.
Step 1:
The first entry you need to make is in the web.xml
Spring Security web xml configuration
Spring Security web xml configuration
From Spring’s documentation “This provides a hook into the Spring Security web infrastructure.DelegatingFilterProxyis a Spring Framework class which delegates to a filter implementation which is defined as a Spring bean in your application context. In this case, the bean is named springSecurityFilterChain, which is an internal infrastructure bean created by the namespace to handle web security.”
Step 2:
Create security-config.xml, all the spring security setting will be configured using this file.
security config xml XSD config
security config xml XSD config Note the security namespace and schema location
Step 3: Use auto-config, this configuration actually adds quite a few services to the application because we have used the auto-config attribute. For example, form-based login processing is automatically enabled.
auto config configuration
auto config configuration
Step 4: Configure URl’s for security based on User roles
Secure Urls for access based on User Roles
Secure Urls for access based on User Roles
Step 5: Add some mock users to check/test the login form user authentication.
Mock User configuration for Login Form test
Mock User configuration for Login Form test
Thats all you require to get basic security for you application, try it with the mock user credentials.


Basic Authentication Login Page using Spring Security
Basic Authentication Login Page using Spring Security

Comments

Popular posts from this blog

Java Interview : Threads

Spring Framework Interview Notes : Part Two Wiring

Card Dealer In Java in Less than 5 minutes