Hi Murali,
Yes, it is possible to use Acegi with RESTful web services in Spring. I've actually just managed to do that myself within the last few days. In order to get Acegi to automatically authenticate all your requests, you'll have to change your Acegi configuration to use HTTP BASIC authentication for any requests along your APIs URL paths. (or some other authentication scheme such as certificate based authentication).
You can do this by specifying a pattern for your RESTful API paths in your filterChainProxy (ie I just copied from my default and made changes as needed).
Here's what I did :
Code:
<bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
<property name="filterInvocationDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/restful-api/**/*=httpSessionContextIntegrationFilter,logoutFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,basicExceptionTranslationFilter,filterInvocationInterceptor
/**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,formExceptionTranslationFilter,filterInvocationInterceptor
</value>
</property>
</bean>
The changes I had to make were to change from the form processing filter to a BASIC processing filter and change to from the form processing exception translation filter to a BASIC translation filter, which you can see in the paths above. The beans I had to use for BASIC filters looked like this :
Code:
<bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationEntryPoint" ref="basicAuthenticationEntryPoint"/>
</bean>
<bean id="basicAuthenticationEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint">
<property name="realmName" value="My Authentication Realm"/>
</bean>
<bean id="basicExceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
<property name="authenticationEntryPoint" ref="basicAuthenticationEntryPoint"/>
</bean>
Note that the difference between using BASIC based authentication versus form based authentication isn't as simple as the Acegi manual would imply. You have to change the exception translation filter as well as the processing filter, otherwise all your failed authentication requests will get redirected to the login screen (as mine did until I figured this out). That little bit isn't mentioned in the Acegi documentation last I checked (which was a couple days ago).