<para>Let's assume you're developing an enterprise application based on Spring. There are four security concerns you typically need to address: authentication, web request security, service layer security (i.e. your methods that implement business logic), and domain object instance security (i.e. different domain objects have different permissions). With these typical requirements in mind: <orderedlist>
<para>Let's assume you're developing an enterprise application based on Spring. There are four security concerns you typically need to address: authentication, web request security, service layer security (i.e. your methods that implement business logic), and domain object instance security (i.e. different domain objects have different permissions). With these typical requirements in mind: <orderedlist>
<listitem>
<listitem>
<para><emphasis>Authentication</emphasis>: The servlet specification provides an approach to authentication. However, you will need to configure the container to perform authentication which typically requires editing of container-specific "realm" settings. This makes a non-portable configuration, and if you need to write an actual Java class to implement the container's authentication interface, it becomes even more non-portable. With Spring Security you achieve complete portability - right down to the WAR level. Also, Spring Security offers a choice of production-proven authentication providers and mechanisms, meaning you can switch your authentication approaches at deployment time. This is particularly valuable for software vendors writing products that need to work in an unknown target environment.</para>
<para><emphasis>Authentication</emphasis>: The servlet specification provides an approach to authentication. However, you will need to configure the container to perform authentication which typically requires editing of container-specific "realm" settings. This makes a non-portable configuration, and if you need to write an actual Java class to implement the container's authentication interface, it becomes even more non-portable. With Spring Security you achieve complete portability - right down to the WAR level. Also, Spring Security offers a choice of production-proven authentication providers and mechanisms, meaning you can switch your authentication approaches at deployment time. This is particularly valuable for software vendors writing products that need to work in an unknown target environment.</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para><emphasis>Web request security:</emphasis> The servlet specification provides an approach to secure your request URIs. However, these URIs can only be expressed in the servlet specification's own limited URI path format. Spring Security provides a far more comprehensive approach. For instance, you
<para><emphasis>Web request security:</emphasis> The servlet specification provides an approach to secure your request URIs. However, these URIs can only be expressed in the servlet specification's own limited URI path format. Spring Security provides a far more comprehensive approach. For instance, you
can use Ant paths or regular expressions, you can consider parts
can use Ant paths or regular expressions, you can consider parts
of the URI other than simply the requested page (eg you can
of the URI other than simply the requested page (e.g. you can
consider HTTP GET parameters), and you can implement your own
consider HTTP GET parameters) and you can implement your own
runtime source of configuration data. This means your web
runtime source of configuration data. This means your web
request security can be dynamically changed during the actual
request security can be dynamically changed during the actual
execution of your webapp.</para>
execution of your webapp.</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para><emphasis>Service layer and domain object security:</emphasis>
<para><emphasis>Service layer and domain object security:</emphasis>
The absence of support in the servlet specification for services
The absence of support in the servlet specification for services
layer security or domain object instance security represent
layer security or domain object instance security represent
serious limitations for multi-tiered applications. Typically
serious limitations for multi-tiered applications. Typically
developers either ignore these requirements, or implement
developers either ignore these requirements, or implement
security logic within their MVC controller code (or even worse,
security logic within their MVC controller code (or even worse,
inside the views). There are serious disadvantages with this
inside the views). There are serious disadvantages with this
approach: <orderedlist>
approach:
<listitem>
<orderedlist>
<para><emphasis>Separation of concerns:</emphasis>
<listitem>
Authorization is a crosscutting concern and should
<para><emphasis>Separation of concerns:</emphasis>
be implemented as such. MVC controllers or views
Authorization is a crosscutting concern and should
implementing authorization code makes it more
be implemented as such. MVC controllers or views
difficult to test both the controller and
implementing authorization code makes it more
authorization logic, more difficult to debug, and
difficult to test both the controller and
will often lead to code duplication.</para>
authorization logic, more difficult to debug, and
</listitem>
will often lead to code duplication.</para>
<listitem>
</listitem>
<para><emphasis>Support for rich clients and web
<listitem>
services:</emphasis> If an additional client type
<para><emphasis>Support for rich clients and web
must ultimately be supported, any authorization code
services:</emphasis> If an additional client type
embedded within the web layer is non-reusable. It
must ultimately be supported, any authorization code
should be considered that Spring remoting exporters
embedded within the web layer is non-reusable. It
only export service layer beans (not MVC
should be considered that Spring remoting exporters
controllers). As such authorization logic needs to
only export service layer beans (not MVC
be located in the services layer to support a
controllers). As such authorization logic needs to
multitude of client types.</para>
be located in the services layer to support a
</listitem>
multitude of client types.</para>
<listitem>
</listitem>
<para><emphasis>Layering issues:</emphasis> An MVC
<listitem>
controller or view is simply the incorrect
<para><emphasis>Layering issues:</emphasis> An MVC
architectural layer to implement authorization
controller or view is simply the incorrect
decisions concerning services layer methods or
architectural layer to implement authorization
domain object instances. Whilst the Principal may be
decisions concerning services layer methods or
passed to the services layer to enable it to make
domain object instances. Whilst the Principal may be
the authorization decision, doing so would introduce
passed to the services layer to enable it to make
an additional argument on every services layer
the authorization decision, doing so would introduce