Announcement Announcement Module
Collapse
No announcement yet.
using TransactionProxyFactoryBean with another Inteceptor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using TransactionProxyFactoryBean with another Inteceptor

    Hi,

    I'm using the very convenient TransactionProxyFactoryBean. Is there any way to add another Interceptor ?

    My bean definitions are:
    <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager"><ref bean="myTransactionManager"/></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="store*">PROPAGATION_REQUIRED,-RollbackException</prop>
    <prop key="clean*">PROPAGATION_REQUIRED,-RollbackException</prop>
    <prop key="delete*">PROPAGATION_REQUIRED,-RollbackException</prop>
    ...
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <bean id="RoleManager" parent="baseTransactionProxy" >
    <property name="target" >
    <bean class="xxx.model.managers.uam.RoleManagerImpl">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>
    </property>
    </bean>

  • #2
    The Acegi Security samples use both transactions and security interceptors. Here's two examples

    Code:
    	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource"><ref local="dataSource"/></property>
    	</bean>
    	
    	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        	<property name="transactionManager"><ref bean="transactionManager"/></property>
    		<property name="transactionAttributeSource">
    			<value>
    				sample.contact.ContactManager.create=PROPAGATION_REQUIRED
    				sample.contact.ContactManager.getAllRecipients=PROPAGATION_REQUIRED,readOnly
    				sample.contact.ContactManager.getAll=PROPAGATION_REQUIRED,readOnly
    				sample.contact.ContactManager.getById=PROPAGATION_REQUIRED,readOnly
    				sample.contact.ContactManager.delete=PROPAGATION_REQUIRED
    				sample.contact.ContactManager.deletePermission=PROPAGATION_REQUIRED
    				sample.contact.ContactManager.addPermission=PROPAGATION_REQUIRED
    			</value>
    		</property>
    	</bean>
    
       <bean id="contactManagerSecurity" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
          <property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
          <property name="objectDefinitionSource">
             <value>
    				sample.contact.ContactManager.create=ROLE_USER
    				sample.contact.ContactManager.getAllRecipients=ROLE_USER
    				sample.contact.ContactManager.getAll=ROLE_USER,AFTER_ACL_COLLECTION_READ
    				sample.contact.ContactManager.getById=ROLE_USER,AFTER_ACL_READ
    				sample.contact.ContactManager.delete=ACL_CONTACT_DELETE
    				sample.contact.ContactManager.deletePermission=ACL_CONTACT_ADMIN
    				sample.contact.ContactManager.addPermission=ACL_CONTACT_ADMIN
             </value>
          </property>
       </bean>
    
    
       <bean id="contactManager" class="org.springframework.aop.framework.ProxyFactoryBean">
          <property name="proxyInterfaces"><value>sample.contact.ContactManager</value></property>
          <property name="interceptorNames">
             <list>
                <idref local="transactionInterceptor"/>
                <idref bean="contactManagerSecurity"/>
                <idref local="contactManagerTarget"/>
             </list>
          </property>
       </bean>
    
       <bean id="contactManagerTarget" class="sample.contact.ContactManagerBackend">
    	   <property name="contactDao"><ref local="contactDao"/></property>
    	   <property name="basicAclExtendedDao"><ref bean="basicAclExtendedDao"/></property>
       </bean>
    plus

    Code:
       <bean id="domainManager" class="com.acegitech.dns.domain.DomainManagerImpl">
    	   <property name="domainDao"><ref local="domainDao"/></property>
    	   <property name="basicAclExtendedDao"><ref bean="basicAclExtendedDao"/></property>
       </bean>
    
       <bean id="domainManagerSecurity" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
          <property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
          <property name="objectDefinitionSource">
             <value>
    				com.acegitech.dns.domain.DomainManager.createDomain=ACL_DOMAIN_CREATE
    				com.acegitech.dns.domain.DomainManager.createResourceRecord=ACL_RESOURCE_RECORD_CREATE
    				com.acegitech.dns.domain.DomainManager.deleteDomain=ACL_DOMAIN_DELETE
    				com.acegitech.dns.domain.DomainManager.deleteResourceRecord=ACL_RESOURCE_RECORD_DELETE
    				com.acegitech.dns.domain.DomainManager.findAllDomainsLike=ROLE_USER,AFTER_ACL_COLLECTION_READ
    				com.acegitech.dns.domain.DomainManager.findAllResourceRecordsInDomain=ROLE_USER,AFTER_ACL_COLLECTION_READ
    				com.acegitech.dns.domain.DomainManager.obtainAdministrativePermission=ROLE_SUPERVISOR
    				com.acegitech.dns.domain.DomainManager.updateDomain=ACL_DOMAIN_WRITE
    				com.acegitech.dns.domain.DomainManager.updateResourceRecord=ACL_RESOURCE_RECORD_WRITE
             </value>
          </property>
       </bean>
    
    	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        	<property name="transactionManager"><ref bean="transactionManager"/></property>
    		<property name="transactionAttributeSource">
    			<value>
    				com.acegitech.dns.domain.DomainManagerImpl.*=PROPAGATION_REQUIRED
    				com.acegitech.dns.domain.DomainManager.*=PROPAGATION_REQUIRED
    			</value>
    		</property>
    	</bean>
    
       <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
    
       <bean id="methodSecurityAdvisor" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodDefinitionSourceAdvisor" autowire="constructor"/>
    
       <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor" autowire="constructor"/>
    I personally prefer the DefaultAdvisorAutoProxyCreator approach, but you'll need to write an Advisor for your MethodInterceptor if one doesn't already exist.

    Comment


    • #3
      TransactionProxyFactoryBean has two properties preInterceptors and postInterceptors that helps to apply more Interceptors.

      Comment


      • #4
        The only limitation of TFP is that pre and post interceptors need to be singletons (shared instances). This is normally fine for "enterprise services" type aspects. Use ProxyFactoryBean or an auto proxy creator if you need to have per-proxy advice.

        Comment


        • #5
          Around Advice with TFB

          I need to wrap an existing BO which uses TFB for transaction management
          with an around advice. You mention that ProxyFactoryBean should
          be used instead in more complex scenrios.

          Is there an example of how to configure ProxyFactoryBean to do the hibernate transaction stuff?

          Comment

          Working...
          X