Spring Security 3.0: Method Security being ignored

I'm new to Spring Security and I'm having trouble getting Spring Method Security to work in my web application although (I believe) I've setup the web.xml, applicationContext.xml and applicationContext-security.xml to enable and use Spring method security. This web application uses GWT and RESTful services and I have successfully implemented security via user authentcation i.e. forcing users to login to the web app - and even implemented Single-Sign-On using SPNEGO with Keberos and Active Directory. However, when I add the <global-method-security> element to the security context and specify appropriate annotations against the desired Java methods, nothing appears to happen!

I'm specifically trying to get @PostFilter to work (but getting any method security to work would be great!), however the returned list is NOT filtered, no related errors are generated and no exceptions are listed in the Tomcat log files.

I'm sure there's something quite basic and fundamental that I've overlooked but none of the examples I've seen clearly state what ALL of the pre-requistes are to get method security to work e.g. do I really need to use AOP and if so, how? All the examples simply say to add the <global-method-security> element to the application context (with appropriate attributes i.e. pre-post-annotations="enabled") and then use the corresponding annotations along-side the methods you wish to secure.....then - like magic - it should work!

Anyway, here's my configuration files:


    <display-name>Jersey Rest Servlet</display-name>

    <!-- Hook into Spring Security framework -->








<?xml version="1.0" encoding="UTF-8"?>

    <context:component-scan base-package="com.myorg.webservices.impl" />

    <bean id="mongo" class="com.mongodb.Mongo">
        <constructor-arg name="host" value="localhost" />
        <constructor-arg name="port" value="27017" />

    <bean id="db" class="com.myorg.dao.DBFactory">
        <constructor-arg name="mongo" ref="mongo">
        <constructor-arg name="name" value="mydatabase" />



<?xml version="1.0" encoding="UTF-8"?>

    <!-- Enable annotations-based security -->
    <global-method-security pre-post-annotations="enabled" />

    <http use-expresions="true">
        <intercept-url> pattern="/**" access="isAuthenticated()" /l>
        <form-login />

                <user name="testadmin" password="password" authorities="supervisor, user" />
                <user name="testuser001" password="password" authorities="user" />


And finally, the java source file containing the method I wish to filter on.


package  com.myorg.client.domain;

import java.util.ArrayList;
import java.util.List;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;

public class DomainPageDecorator extends PageDecorator<DomainData> 
    public DomainPageDecorator (int numberOfRecordsOnPage)

    "       "
    "       "
    "       "

    /* Use Spring Method Security to only allow 'ACTIVE' objects through */
    @PostFilter("filterObject.getStatus()=='ACTIVE' ")
    public List<DomainObject> convertToList()
        List<DomainObject> dataList = new ArrayList<DomainObject>();

        for (int i = 0; i < data.getPage().getLength(); i++)
            dataList.add(new DomainObject(data.getPage().get(i) ) );

        return dataList;

    public DomainObject getFirstItem()
        return new DomainObject(data.getPage().get(0) );

Can anyone please tell me what am I missing or doing wrong?

NB: I work in a secured environment which prevents me from posting stack traces and large code segments etc onto the internet from my development machine. However, I should still be able provide any further information that's needed to help resolve this problem even though I'll be typing it all up :-( Apologies in advance for any typos


You can apply these annotations only to beans declared in some spring context file. From provided code it looks like your DomainPageDecorator class is not managed by spring. Make it managed:

  1. Declare it (via some annotation like @Component or directly in the xml).
  2. Retrieve it via Spring (instead of using new keyword). Use @Inject or XML.

Need Your Help

Decrease file size of QPixmap

c++ qt qpixmap qbytearray

when i resize a QPixmap with scaledToHeight and then transform it to an QByteArray, the size of this ByteArray is exactly the size of ByteArray from the unscaled QPixmap. Is there a possibility to ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.