测试SpringSide里的Spring sercurity

#jdbc settings

#jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
#jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=SpringSide;SelectMethod=Cursor;
#jdbc.username=sa
#jdbc.password=kenter1643

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/webgame
jdbc.username=root
jdbc.password=kenter1643

#hibernate settings

#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.ehcache_config_file=/ehcache/ehcache-hibernate-local.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
	default-lazy-init="true">

	<description>Spring公共配置文件 </description>

	<!-- 定义受环境影响易变的变量 -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<!-- 标准配置 -->
				<value>classpath*:/application.properties</value>
				<!-- 本地开发环境配置 -->
				<value>classpath*:/application.local.properties</value>
				<!-- 服务器生产环境配置 -->
				<!-- <value>file:/var/myapp/application.server.properties</value> -->
			</list>
		</property>
	</bean>

	<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
	<context:component-scan base-package="org.springside.examples.miniweb" />

	<!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<!-- Connection Info -->
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />

		<!-- Connection Pooling DBCP -->
		<property name="initialSize" value="5" />
		<property name="maxActive" value="100" />
		<property name="maxIdle" value="30" />
		<property name="maxWait" value="1000" />
		<property name="poolPreparedStatements" value="true" />
		<property name="defaultAutoCommit" value="false" />
	</bean>

	<!-- 数据源配置,使用应用服务器的数据库连接池 -->
	<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->

	<!-- Hibernate配置 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="namingStrategy">
			<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
				</prop>
				<prop key="hibernate.cache.provider_configuration_file_resource_path">${hibernate.ehcache_config_file}</prop>
			</props>
		</property>
		<property name="packagesToScan" value="org.springside.examples.miniweb.entity.*" />
	</bean>

	<!-- 事务管理器配置,单数据源事务 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 事务管理器配置,多数据源JTA事务-->
	<!--
		<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager or
		WebLogicJtaTransactionManager" />
	-->

	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

 

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans"
	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-2.5.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"
	default-autowire="byType" default-lazy-init="true">

	<beans:description>使用SpringSecurity的安全配置文件</beans:description>

	<!-- 在此定义URL与授权的关系. 而用户、角色、授权及三者的关系则保存在数据库中. -->
	<http auto-config="true" access-decision-manager-ref="accessDecisionManager">
		<intercept-url pattern="/user/user!save*" access="A_MODIFY_USER" />
		<intercept-url pattern="/user/user!delete*" access="A_MODIFY_USER" />
		<intercept-url pattern="/user/user*" access="A_VIEW_USER" />
		<intercept-url pattern="/user/role!save*" access="A_MODIFY_ROLE" />
		<intercept-url pattern="/user/role!delete*" access="A_MODIFY_ROLE" />
		<intercept-url pattern="/user/role*" access="A_VIEW_ROLE" />
		<form-login login-page="/login.action" default-target-url="/user/user.action" authentication-failure-url="/login.action?error=true" />
		<logout logout-success-url="/" />
		<remember-me key="e37f4b31-0c45-11dd-bd0b-0800200c9a66" />
	</http>

	<authentication-provider user-service-ref="userDetailsService">
		<!-- 可设置hash使用sha1或md5散列密码后再存入数据库 -->
		<password-encoder hash="plaintext" />
	</authentication-provider>

	<beans:bean id="userDetailsService" class="org.springside.examples.miniweb.service.security.UserDetailServiceImpl" />

	<!-- 将授权的默认前缀由ROLE_改为A_ -->
	<beans:bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased">
		<beans:property name="decisionVoters">
			<beans:list>
				<beans:bean class="org.springframework.security.vote.RoleVoter">
					<beans:property name="rolePrefix" value="A_" />
				</beans:bean>
				<beans:bean class="org.springframework.security.vote.AuthenticatedVoter" />
			</beans:list>
		</beans:property>
	</beans:bean>
</beans:beans>

 

 


 
 

你可能感兴趣的:(spring,Hibernate,bean,jdbc,Security)