<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<!-- =================================================================== -->
	<!-- Session Factory =================================================== -->
	<!-- =================================================================== -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="mappingDirectoryLocations">
			<ref bean="mappingResources" />
		</property>
		<property name="hibernateProperties">
			<ref bean="hibernateProperties" />
		</property>
		<property name="entityInterceptor">
			<ref bean="auditingHibernateInterceptor" />
		</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>
		<!--  property name="entityInterceptorBeanName">
			<value>"auditingHibernateInterceptor"</value>
			</property -->
	</bean>
	
	<!-- =================================================================== -->
	<!-- DAO objects ======================================================= -->
	<!-- =================================================================== -->
	<bean id="hibernateModelDao"
		class="com.oberthurcs.common.dao.hibernate.HibernateModelDao">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<bean id="hibernateUserDao"
		class="com.oberthurcs.common.dao.hibernate.HibernateUserDao">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	
	<!-- =================================================================== -->
	<!-- AuditingDaoAdvisor AOP ============================================ -->
	<!-- =================================================================== -->
	<!-- bean
		id="listBeanFactory"
		class="org.springframework.beans.factory.support.DefaultListableBeanFactory">
		</bean-->
	<!-- bean id="autoProxyCreator"
		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
		</bean>
		<bean id="auditingDaoAdvisor"
		class="com.oberthurcs.common.dao.AuditableDaoAdvisor">
		</bean -->
		
	<!-- =================================================================== -->
	<!--  AuditableHibernateInterceptor ==================================== -->
	<!-- =================================================================== -->
	<bean id="auditingHibernateInterceptor"
		class="com.oberthurcs.common.dao.AuditingHibernateInterceptor">
	</bean>


    	<!-- Get datasource properties from file -->
    	<bean id="propertyConfigurer" 
    	    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	    <property name="location">
    	        <value>classpath:dataSource.properties</value>
    	    </property>
    	    <!-- Override properties in file with system properties -->
    	    <property name="systemPropertiesModeName">
    	        <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    	    </property>
    	</bean>
    
    	<!-- DBCP Basic datasource -->
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    	    destroy-method="close">
    	    <property name="driverClassName">
    	        <value>${dataSource.driverClassName}</value>
    	    </property>
    	    <property name="url">
    	        <value>${dataSource.url}</value>
    	    </property>
    	    <property name="username">
    	        <value>${dataSource.username}</value>
    	    </property>
    	    <property name="password">
    	        <value>${dataSource.password}</value>
    	    </property>
    	</bean>

    	<!-- Hibernate properties -->
    	<bean id="hibernateProperties" class="com.oberthurcs.common.dao.hibernate.HibernateProperties">
    	    <constructor-arg>
    	        <props>
    	            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    	            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    	            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
    	        </props>
    	    </constructor-arg>
    	</bean>


	<!-- =================== SECURITY SYSTEM DEFINITIONS ================== -->

	<!-- RunAsManager -->
	<bean id="runAsManager"
		class="net.sf.acegisecurity.runas.RunAsManagerImpl">
		<property name="key">
			<value>my_run_as_password</value>
		</property>
	</bean>

	<!-- ~~~~~~~~~~~~~~~~~~~~ AUTHENTICATION DEFINITIONS ~~~~~~~~~~~~~~~~~~ -->

	<bean id="runAsAuthenticationProvider"
		class="net.sf.acegisecurity.runas.RunAsImplAuthenticationProvider">
		<property name="key">
			<value>my_run_as_password</value>
		</property>
	</bean>

	<bean id="authenticationManager"
		class="net.sf.acegisecurity.providers.ProviderManager">
		<property name="providers">
			<list>
				<ref bean="runAsAuthenticationProvider" />
				<ref bean="daoAuthenticationProvider" />
			</list>
		</property>
	</bean>

	<bean id="passwordEncoder"
		class="net.sf.acegisecurity.providers.encoding.ShaPasswordEncoder" />

	<bean id="daoAuthenticationProvider"
		class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
		<property name="authenticationDao">
			<ref bean="hibernateUserDao" />
		</property>
		<property name="userCache">
			<ref bean="userCache" />
		</property>
		<property name="passwordEncoder">
			<ref bean="passwordEncoder" />
		</property>
	</bean>

	<bean id="userCache"
		class="net.sf.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
		<property name="minutesToIdle">
			<value>5</value>
		</property>
	</bean>

	<!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider -->
	<bean id="loggerListener"
		class="net.sf.acegisecurity.providers.dao.event.LoggerListener" />

	<bean id="basicProcessingFilter"
		class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter">
		<property name="authenticationManager">
			<ref bean="authenticationManager" />
		</property>
		<property name="authenticationEntryPoint">
			<ref bean="basicProcessingFilterEntryPoint" />
		</property>
	</bean>

	<bean id="basicProcessingFilterEntryPoint"
		class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint">
		<property name="realmName">
			<value>Member Portal Realm</value>
		</property>
	</bean>

	<bean id="autoIntegrationFilter"
		class="net.sf.acegisecurity.ui.AutoIntegrationFilter" />

	<!-- ~~~~~~~~~~~~~~~~~~~~ AUTHORIZATION DEFINITIONS ~~~~~~~~~~~~~~~~~~~ -->

	<!-- An access decision voter that reads ROLE_* configuaration settings -->
	<bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter" />

	<!-- An access decision manager used by the business objects -->
	<bean id="businessAccessDecisionManager"
		class="net.sf.acegisecurity.vote.AffirmativeBased">
		<property name="allowIfAllAbstainDecisions">
			<value>false</value>
		</property>
		<property name="decisionVoters">
			<list>
				<ref bean="roleVoter" />
			</list>
		</property>
	</bean>

	<!-- ===================== HTTP CHANNEL REQUIREMENTS ==================== -->

	<!-- You will need to uncomment the "Acegi Channel Processing Filter"
		<filter-mapping> in web.xml for the following beans to be used -->

	<bean id="channelProcessingFilter"
		class="net.sf.acegisecurity.securechannel.ChannelProcessingFilter">
		<property name="channelDecisionManager">
			<ref bean="channelDecisionManager" />
		</property>
		<property name="filterInvocationDefinitionSource">
			<value>
				CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
				\A/login.jsp.*\Z=REQUIRES_SECURE_CHANNEL
				\A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL
				\A.*\Z=REQUIRES_SECURE_CHANNEL
			</value>
		</property>
	</bean>

	<bean id="channelDecisionManager"
		class="net.sf.acegisecurity.securechannel.ChannelDecisionManagerImpl">
		<property name="channelProcessors">
			<list>
				<ref bean="secureChannelProcessor" />
				<ref bean="insecureChannelProcessor" />
			</list>
		</property>
	</bean>

	<bean id="secureChannelProcessor"
		class="net.sf.acegisecurity.securechannel.SecureChannelProcessor" />
	<bean id="insecureChannelProcessor"
		class="net.sf.acegisecurity.securechannel.InsecureChannelProcessor" />

	<!-- ===================== HTTP REQUEST SECURITY ==================== -->

	<bean id="authenticationProcessingFilter"
		class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
		<property name="authenticationManager">
			<ref bean="authenticationManager" />
		</property>
		<property name="authenticationFailureUrl">
			<value>/login.jsp?login_error=1</value>
		</property>
		<property name="defaultTargetUrl">
			<value>/</value>
		</property>
		<property name="filterProcessesUrl">
			<value>/j_acegi_security_check</value>
		</property>
	</bean>

	<bean id="securityEnforcementFilter"
		class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter">
		<property name="filterSecurityInterceptor">
			<ref bean="filterInvocationInterceptor" />
		</property>
		<property name="authenticationEntryPoint">
			<ref bean="authenticationProcessingFilterEntryPoint" />
		</property>
	</bean>

	<bean id="authenticationProcessingFilterEntryPoint"
		class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
		<property name="loginFormUrl">
			<value>/login.jsp</value>
		</property>
		<property name="forceHttps">
			<value>true</value>
		</property>
	</bean>

	<bean id="accessDecisionManager"
		class="net.sf.acegisecurity.vote.AffirmativeBased">
		<property name="allowIfAllAbstainDecisions">
			<value>false</value>
		</property>
		<property name="decisionVoters">
			<list>
				<ref bean="roleVoter" />
			</list>
		</property>
	</bean>

	<!-- Note the order that entries are placed against the objectDefinitionSource is critical.
		The FilterSecurityInterceptor will work from the top of the list down to the FIRST pattern that matches the request URL.
		Accordingly, you should place MOST SPECIFIC (ie a/b/c/d.*) expressions first, with LEAST SPECIFIC (ie a/.*) expressions last -->
	<bean id="filterInvocationInterceptor"
		class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor">
		<property name="authenticationManager">
			<ref bean="authenticationManager" />
		</property>
		<property name="accessDecisionManager">
			<ref bean="accessDecisionManager" />
		</property>
		<property name="runAsManager">
			<ref bean="runAsManager" />
		</property>
		<property name="objectDefinitionSource">
			<value>
				<!-- TODO Customize to Member-Portal -->
				CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
				\A/secure/super.*\Z=ROLE_WE_DONT_HAVE
				\A/secure/.*\Z=ROLE_SUPERVISOR,ROLE_TELLER
			</value>
		</property>
	</bean>

	<!-- =================================================================== -->
	<!-- PERSISTENCE DEFINITIONS =========================================== -->
	<!-- =================================================================== -->
	<bean id="mappingResources" class="java.util.ArrayList">
		<constructor-arg>
			<list>
				<value>classpath:com/oberthurcs/mp/model/objects</value>
			</list>
		</constructor-arg>
	</bean>

	<!-- =================================================================== -->
	<!-- Transaction Setup ================================================= -->
	<!-- =================================================================== -->
	<bean name="transactionAttributes"
		class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
		<property name="properties">
			<props>
				<prop key="get*">readOnly</prop>
				<prop key="find*">readOnly</prop>
				<prop key="edit*">readOnly</prop>
				<prop key="load*">readOnly</prop>
				<prop key="create*">
					PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE
				</prop>
				<prop key="save*">
					PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE
				</prop>
				<prop key="update*">
					PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE
				</prop>
				<prop key="delete*">
					PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE
				</prop>
			</props>
		</property>
	</bean>

	<bean id="nameMatchTxInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager">
			<ref bean="transactionManager" />
		</property>
		<property name="transactionAttributeSource">
			<ref bean="transactionAttributes" />
		</property>
	</bean>

	<bean id="attributes"
		class="org.springframework.metadata.commons.CommonsAttributes" />

	<bean id="objectDefinitionSource"
		class="net.sf.acegisecurity.intercept.method.MethodDefinitionAttributes">
		<property name="attributes">
			<ref local="attributes" />
		</property>
	</bean>

	<!-- We don't validate config attributes, as it's unsupported by MethodDefinitionAttributes -->
	<bean id="securityInterceptor"
		class="net.sf.acegisecurity.intercept.method.MethodSecurityInterceptor">
		<property name="validateConfigAttributes">
			<value>false</value>
		</property>
		<property name="authenticationManager">
			<ref bean="authenticationManager" />
		</property>
		<property name="accessDecisionManager">
			<ref bean="accessDecisionManager" />
		</property>
		<property name="runAsManager">
			<ref bean="runAsManager" />
		</property>
		<property name="objectDefinitionSource">
			<ref bean="objectDefinitionSource" />
		</property>
	</bean>

	<bean id="autoTxProxyCreator"
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<idref local="nameMatchTxInterceptor" />
				<idref local="securityInterceptor" />
			</list>
		</property>
		<property name="beanNames">
			<list>
				<idref local="serviceManagerTarget" />
			</list>
		</property>
	</bean>
	<!-- =================================================================== -->
	<!-- Service Manager =================================================== -->
	<!-- =================================================================== -->
	<bean id="serviceManagerTarget"
		class="com.oberthurcs.mp.service.hibernate.ServiceManagerImpl"
		singleton="false">
		<property name="dao">
			<ref bean="hibernateModelDao" />
		</property>
	</bean>

	<bean id="serviceManager"
		class="org.springframework.aop.framework.ProxyFactoryBean">
		<property name="proxyInterfaces">
			<value>com.oberthurcs.mp.service.ServiceManager</value>
		</property>
		<property name="interceptorNames">
			<list>
				<value>serviceManagerTarget</value>
			</list>
		</property>
	</bean>
	<!-- =================================================================== -->
	<!-- URL mapper for the Open Session In View interceptor =============== -->
	<!-- =================================================================== -->
	<bean id="urlMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="interceptors">
			<list>
				<ref bean="openSessionInViewInterceptor" />
			</list>
		</property>
		<property name="mappings">
			<props>
				<prop key="/**/*.html">transactionManager</prop>
			</props>
		</property>
	</bean>
	<!-- =================================================================== -->
	<!--  Open Session In View Interceptor ================================= -->
	<!-- =================================================================== -->
	<bean name="openSessionInViewInterceptor"
		class="org.springframework.orm.hibernate.support.OpenSessionInViewInterceptor">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
</beans>
