<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:security="http://www.springframework.org/schema/security"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.0.4.xsd">
    
    <!-- Property Configurator -->
	<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	   		<property name="locations">
	   			<list>
	   				<value>/WEB-INF/config.properties</value>
	   			</list>
	   		</property>
	</bean> 
	<!-- End Property Configurator -->
	
	<!-- Data -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
			destroy-method="close">
			<property name="driverClassName" value="${jdbc.driver.class.name}"></property>
			<property name="url" value="${jdbc.url}"></property>
			<property name="username" value="${jdbc.username}"></property>
			<property name="password" value="${jdbc.password}"></property>
	</bean>
	
    <bean id="userDetailsManager" class="org.springframework.security.provisioning.JdbcUserDetailsManager">
   		<property name="dataSource" ref="dataSource"></property>
   		<property name="authenticationManager" ref="authenticationManager"></property>
    </bean>  
    <!-- End Data -->
    
    <security:http auto-config="true" use-expressions="true">
    	<security:intercept-url pattern="/login" access="permitAll"/> 
    	<security:intercept-url pattern="/genres/create" access="hasRole('ROLE_ADMIN')"/>
    	<security:intercept-url pattern="/*" access="hasAnyRole('ROLE_ADMIN','ROLE_USER')"/>
    	
    	<security:form-login login-page="/login"/>
    	
    	<security:logout invalidate-session="true"
    				logout-url="/logout"/> 
    </security:http>
    
    <security:authentication-manager alias="authenticationManager">
    	<security:authentication-provider user-service-ref="userDetailsManager">
    		<security:password-encoder ref="passwordEncoder">
    			<security:salt-source ref="saltSource"/>
    		</security:password-encoder>
    	</security:authentication-provider>
    </security:authentication-manager>
   
    <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"></bean>
	
	<bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
		<property name="userPropertyToUse" value="username"></property>
	</bean>
</beans>