Here is my implementation but I think there is a better way to do it with autoproxying if you have a lot of class which need proxy (Maybe there are beans declare that are not needed, I did not have the time to read the doc on everything I took from the sample example)
applicationcontext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:/jdbc.properties</value>
</property>
</bean>
<!--ACEGI CONFIGURATION-->
<!-- RunAsManager -->
<bean id="runAsManager" class="net.sf.acegisecurity.runas.RunAsManagerImpl">
<property name="key"><value>my_run_as_password</value></property>
</bean>
<!-- TEST-->
<bean id="runAsAuthenticationProvider" class="net.sf.acegisecurity.runas.RunAsImplAuthenticationProvider">
<property name="key"><value>my_run_as_password</value></property>
</bean>
<bean id="authByAdapterProvider" class="net.sf.acegisecurity.adapters.AuthByAdapterProvider">
<property name="key"><value>my_password</value></property>
</bean>
<!--END OF TEST-->
<bean id="remoteAuthenticationManager" class="net.sf.acegisecurity.providers.rcp.RemoteAuthenticationManagerImpl">
<property name="authenticationManager">
<ref bean="authenticationManager"/>
</property>
</bean>
<bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
<ref local="runAsAuthenticationProvider"/>
<ref local="authByAdapterProvider"/>
</list>
</property>
</bean>
<bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="authenticationDao">
<ref local="inMemoryDaoImpl"/>
</property>
</bean>
<bean id="inMemoryDaoImpl" class="net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl">
<property name="userMap">
<value>
admin=admin,ROLE_USER,ROLE_SUPERVISOR
dianne=emu,ROLE_USER
scott=wombat,ROLE_TELLER
peter=opal,disabled,ROLE_TELLER
</value>
</property>
</bean>
<bean id="accessDecisionManager" class="net.sf.acegisecurity.vote.AffirmativeBased">
<property name="allowIfAllAbstainDecisions">
<value>false</value>
</property>
<property name="decisionVoters">
<list>
<ref local="roleVoter"/>
</list>
</property>
</bean>
<bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/>
<bean id="basicProcessingFilter" class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter">
<property name="authenticationManager">
<ref local="authenticationManager"/>
</property>
<property name="authenticationEntryPoint">
<ref local="basicProcessingFilterEntryPoint"/>
</property>
</bean>
<bean id="basicProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint">
<property name="realmName">
<value>Contacts Realm</value>
</property>
</bean>
<bean id="httpSessionIntegrationFilter" class="net.sf.acegisecurity.ui.webapp.HttpSessionIntegrationFilter"/>
<!--<bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter"/>-->
<!--END OF ACEGI CONFIGURATION-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>be/fgov/caamihziv/fdm/usermanagement/User.hbm.xml</value>
<value>be/fgov/caamihziv/fdm/usermanagement/Group.hbm.xml</value>
<value>be/fgov/caamihziv/fdm/usermanagement/RegionalOffice.hbm.xml</value>
<value>be/fgov/caamihziv/fdm/usermanagement/InsuranceAgency.hbm.xml</value>
<value>be/fgov/caamihziv/fdm/membermanagement/Member.hbm.xml</value>
<value>be/fgov/caamihziv/fdm/membermanagement/registrationmanagement/RegistrationMotives.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- ===================== SECURITY DEFINITIONS ======================= -->
<bean id="UserManagementSecurityManager" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager"><ref local="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="accessDecisionManager"/></property>
<property name="runAsManager"><ref local="runAsManager"/></property>
<property name="objectDefinitionSource">
<value>
be.fgov.caamihziv.fdm.usermanagement.service.UserManagementService.*=ROLE_SUPERVISOR
</value>
</property>
</bean>
<bean id="UserManagementManager" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>be.fgov.caamihziv.fdm.usermanagement.service.UserManagementService</value></property>
<property name="interceptorNames">
<list>
<idref local="UserManagementSecurityManager"/>
</list>
</property>
<property name="target">
<ref bean="groupTarget"/>
</property>
</bean>
<!--BUSINESS DEFINITION-->
<bean id="groupTarget" class="be.fgov.caamihziv.fdm.usermanagement.service.UserManagementServiceImpl">
<!--<property name="proxyInterfaces"><value>be.fgov.caamihziv.fdm.usermanagement.service.UserManagementService</value></property>-->
<property name="groupDao">
<ref local="groupDao"/>
</property>
<property name="userDao">
<ref local="userDao"/>
</property>
<property name="regionalOfficeDao">
<ref local="regionalOfficeDao"/>
</property>
<property name="insuranceAgencyDao">
<ref local="insuranceAgencyDao"/>
</property>
</bean>
<bean id="group" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="UserManagementManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="upd*">PROPAGATION_REQUIRED</prop>
<prop key="login">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="groupDao" class="be.fgov.caamihziv.fdm.usermanagement.service.GroupDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="userDao" class="be.fgov.caamihziv.fdm.usermanagement.service.UserDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="regionalOfficeDao" class="be.fgov.caamihziv.fdm.usermanagement.service.RegionalOfficeDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="insuranceAgencyDao" class="be.fgov.caamihziv.fdm.usermanagement.service.InsuranceAgencyDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="memberTarget" class="be.fgov.caamihziv.fdm.membermanagement.service.MemberManagementServiceImpl">
<property name="memberDao">
<ref local="memberDao"/>
</property>
</bean>
<bean id="member" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="memberTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="upd*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="memberDao" class="be.fgov.caamihziv.fdm.membermanagement.service.MemberDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="registrationTarget" class="be.fgov.caamihziv.fdm.membermanagement.registrationmanagement.service.RegistrationManagementServiceImpl">
<property name="registrationMotivesDao">
<ref local="registrationMotivesDao"/>
</property>
</bean>
<bean id="registration" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="registrationTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="upd*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="registrationMotivesDao" class="be.fgov.caamihziv.fdm.membermanagement.registrationmanagement.service.RegistrationMotivesDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- ===================== HTTP REQUEST SECURITY ==================== -->
<!-- BASIC Regular Expression Syntax (for beginners):
\A means the start of the string (ie the beginning of the URL)
\Z means the end of the string (ie the end of the URL)
. means any single character
* means null or any number of repetitions of the last expression (so .* means zero or more characters)
Some examples:
Expression: \A/my/directory/.*\Z
Would match: /my/directory/
/my/directory/hello.html
Expression: \A/.*\Z
Would match: /hello.html
/
Expression: \A/.*/secret.html\Z
Would match: /some/directory/secret.html
/another/secret.html
Not match: /anothersecret.html (missing required /)-->
<bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter">
<property name="filterSecurityInterceptor"><ref local="filterInvocationInterceptor"/></property>
<property name="authenticationEntryPoint"><ref local="basicProcessingFilterEntryPoint"/></property>
</bean>
<bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager">
<ref local="authenticationManager"/>
</property>
<property name="accessDecisionManager">
<ref local="accessDecisionManager"/>
</property>
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/secure/**=ROLE_USER
</value>
</property>
</bean>
</beans>
-->
Web.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>CAAMI-HZIV FDM</display-name>
<description>Fichiers des Membres</description>
<!--
- Location of the Log4J config file, for initialization and refresh checks.
- Applied by Log4jConfigListener.
-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/log4j.properties</param-value>
</context-param>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderServlet.
-
- Can be set to "/WEB-INF/applicationContext-hibernate.xml" for the Hibernate
- implementation, "/WEB-INF/applicationContext-ojb.xml" for the Apache OJB one,
- or "/WEB-INF/applicationContext-jdbc.xml" for the JDBC one.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Note that it is preferable to use ContextLoaderListener in a servlet container
- that follows the Servlet 2.4 initialization order (many Servlet 2.3 containers do).
-
- Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- to access it anywhere in the web application, outside of the framework.
-
- The root context is the parent of all servlet-specific contexts.
- This means that its beans are automatically available in these child contexts,
- both for getBean(name) calls and (external) bean references.
-->
<!--ACEGI CONFIGURATION-->
<filter>
<filter-name>Acegi_HTTP_BASIC_Authorization_Filter</filter-name>
<filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter</param-value>
</init-param>
</filter>
<filter>
<filter-name>Acegi_Security_System_for_Spring_HttpSession_Integration_Filter</filter-name>
<filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>net.sf.acegisecurity.ui.webapp.HttpSessionIntegrationFilter</param-value>
</init-param>
</filter>
<filter>
<filter-name>Acegy_http_request_security_filter</filter-name>
<filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Acegi_HTTP_BASIC_Authorization_Filter</filter-name>
<url-pattern>/secure/remoting/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Acegi_Security_System_for_Spring_HttpSession_Integration_Filter</filter-name>
<url-pattern>/secure/remoting/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Acegy_http_request_security_filter</filter-name>
<url-pattern>/secure/remoting/*</url-pattern>
</filter-mapping>
<!-- Listener to initialize the spring application context -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>-->
<!--
- Dispatcher servlet definition for HTTP remoting via Hessian, Burlap, and
- Spring's HTTP invoker (see remoting-servlet.xml for the controllers).
-->
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet>
<servlet-name>secure_remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>20</load-on-startup>
</servlet>
<!--
- Dispatcher servlet mapping for HTTP remoting via Hessian, Burlap, and
- Spring's HTTP invoker (see remoting-servlet.xml for the controllers).
-->
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>secure_remoting</servlet-name>
<url-pattern>/secure/remoting/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
servlet.xml
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
- Dispatcher servlet for HTTP remoting via Hessian, Burlap, and Spring's
- HTTP invoker (see remoting-servlet.xml for the controllers).
-->
<beans>
<!--HTTPEXPORTER for the login-->
<bean name="/RemoteAuthenticationManager" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="remoteAuthenticationManager"/>
</property>
<property name="serviceInterface">
<value>net.sf.acegisecurity.providers.rcp.RemoteAuthenticationManager</value>
</property>
</bean>
</beans>
secureservlet.xml
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
- Dispatcher servlet for HTTP remoting via Hessian, Burlap, and Spring's
- HTTP invoker (see remoting-servlet.xml for the controllers).
-->
<beans>
<!--HTTPEXPORTER for the usermanagement service -->
<bean name="/GroupService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service"><ref bean="group"/></property>
<property name="serviceInterface">
<value>be.fgov.caamihziv.fdm.usermanagement.service.UserManagementService</value>
</property>
</bean>
<bean name="/MemberManagementService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service"><ref bean="member"/></property>
<property name="serviceInterface">
<value>be.fgov.caamihziv.fdm.membermanagement.service.MemberManagementService</value>
</property>
</bean>
<bean name="/RegistrationManagementService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service"><ref bean="registration"/></property>
<property name="serviceInterface">
<value>be.fgov.caamihziv.fdm.membermanagement.registrationmanagement.service.RegistrationManagementService</value>
</property>
</bean>
</beans>
I hope this help.