Results 1 to 3 of 3

Thread: Unit testing protected Controllers

  1. #1
    Join Date
    Oct 2004
    Location
    Houston
    Posts
    8

    Default Unit testing protected Controllers

    I am trying to test controllers that are being protected by a "SecurityInterceptor". Here is my *-servlet.xml configuration:

    Code:
    <bean id="secureHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="interceptors">
    		    <list>
    			<ref local="securityInterceptor"/>
    		    </list>
    		</property>
    		<property name="urlMap">
    		    <map>
                            <entry key="/getserverlist.do">
                                <ref local="secure_getserverlist"/>
                            </entry>
        		    </map>
    		</property>
    	</bean>
    
    <bean id="securityInterceptor" class="presentation.interceptor.authentication.SecurityInterceptor"/> 
    
    <bean id="secure_getserverlist" class="presentation.controller.GetServerListController"/>
    Now in my test I am going to want to get the bean for the GetServerListController. However, unlike the other beans that are mapped to say '/login.do' where I can just simply call something like this - ctx.getBean("/login.do"); I am not able to do the same given that the path '/getserverlist.do' is not actually a bean id now but rather it is an entry in a Map as a property to the 'secureHandlerMapping' bean.

    Perhaps the plan is to create a new Url handler mapping class extending AbstractUrlHandlerMapping that not only has setter methods for the urlMap property but also getters. Sound right, another solution? I am all ears right now.

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default Re: Unit testing protected Controllers

    Quote Originally Posted by hneiper
    I am trying to test controllers that are being protected by a "SecurityInterceptor"
    Why reinvent the wheel? There are more security approaches out there than you can poke a stick at. Could you use Acegi Security, which what most Spring developers are using? It has URL mapping services already, comprehensive unit tested. I've personally used Acegi Security to build a content management system, and others have done the same thing, so it's likely to meet most needs (or at least provide extension hooks to do so).

  3. #3
    Join Date
    Oct 2004
    Location
    Houston
    Posts
    8

    Default Re: Unit testing protected Controllers

    Quote Originally Posted by Ben Alex
    Why reinvent the wheel?
    Well, basically because I am not reinventing the wheel. Maybe protected is not really a correct description. Plain and simple the Interceptor is just being used to check the state of certain objects managed by the Controller. I wish I could elaborate on more of the details around what is taking place in the Interceptor, but I am afraid that this is not possible do to the policies I have to live by set forth by my company. Anyhow, beyond that your suggestion has merit but not for the context of this topic.

    So now that you have offered nothing to this discussion other than to tell us that you "used such and such" and "you did so and so" - if anyone else has any suggestions as to what a solution might be in the context of the topic - again I would be glad to listen.

Similar Threads

  1. help with testing controllers
    By pir8ped in forum Web
    Replies: 9
    Last Post: Apr 28th, 2006, 06:13 PM
  2. Base Unit Test for Controllers?
    By ryan.tyer in forum Web
    Replies: 1
    Last Post: Apr 28th, 2005, 06:34 PM
  3. Please help! Unit testing code for JPetStore
    By lakershen in forum Container
    Replies: 4
    Last Post: Jan 13th, 2005, 05:00 PM
  4. Replies: 2
    Last Post: Jan 6th, 2005, 02:49 AM
  5. Replies: 2
    Last Post: Dec 2nd, 2004, 08:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •