View RSS Feed

Spring Framework

Configuring Spring Security

Rate this Entry
by , 11-27-2011 at 11:45 PM (1525 Views)
In the last tip, I introduced Spring Security and outlined the modules that are available. In this tip, we will look at configuring namespaces. Using Spring, the nice thing about Spring Security is that all the security elements are configured as beans in the application context. It is not uncommon to have a Acegi configuration containing dozens of bean declarations that span multiple pages.

Another nice feature is that Spring Security has its own security-specific namespace to simplify the security configuration in Spring. The namespace, along with some sensible default behavior, can significantly reduce the typical security configuration to about a dozen line of XML.

So if you are looking to use Acegi, the next thing you should do is to include the security namespace in the XML file by adding the namespace declaration:

Java Code:
<beans:beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<-- Put your security elements here
</beans:beans>
In this configuration, I have made the security namespace into the primary namespace. This allows for you to avoid adding security: prefixes on all of the elements. In the next tip, we will look at how to secure web requests.

Submit "Configuring Spring Security" to Facebook Submit "Configuring Spring Security" to Digg Submit "Configuring Spring Security" to del.icio.us Submit "Configuring Spring Security" to StumbleUpon Submit "Configuring Spring Security" to Google

Comments