每一个认证对象都有属于它自己的拦截器来负责处理它每一次请求。包括如下的一系列操作。
拦截器有如下几种。
1 : 针对类的方法的拦截器 :MethodSecurityInterceptor
在appfuse中用到了这种方式。如下:
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- Generic manager that can be used to do basic CRUD operations on any objects -->
<bean id="manager" parent="txProxyTemplate">
<property name="target">
<bean class="org.appfuse.service.impl.BaseManager">
<property name="dao" ref="dao"/>
</bean>
</property>
</bean>
<!-- Transaction declarations for business services. To apply a generic transaction proxy to
all managers, you might look into using the BeanNameAutoProxyCreator -->
<bean id="userManager" parent="txProxyTemplate">
<property name="target">
<bean class="org.appfuse.service.impl.UserManagerImpl">
<property name="userDao" ref="userDao"/>
</bean>
</property>
<!-- Override default transaction attributes b/c of UserExistsException -->
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED,-UserExistsException</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
<!-- This property is overriden in applicationContext-security.xml to add
method-level role security -->
<property name="preInterceptors">
<list>
<ref bean="userSecurityInterceptor"/>
</list>
</property>
</bean>
在 bean "userManager" 中的preInterceptors中有一个<ref
bean="userSecurityInterceptor"/>。
bean "userSecurityInterceptor"的定义如下 :
<bean id="userSecurityInterceptor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property
name="advice" ref="userSecurityAdvice"/>
<property
name="patterns" value=".*saveUser"/>
</bean>
可以看到,当我们调用userManager的时候,通过spring的aop机制在它执行的前边要先执行userSecurityInterceptor.
|