概括:
<!-- 從數據庫中讀取用戶信息驗證身份 -->
<bean id ="daoAuthenticationProvider"
class= "org.acegisecurity.providers.dao.DaoAuthenticationProvider" >
<property name ="userDetailsService" ref= "inMemDaoImpl" />
</bean >
<!-- 基於內存實現方式-->
<bean id ="inMemDaoImpl"
class= "org.acegisecurity.userdetails.memory.InMemoryDaoImpl" >
<property name ="userMap">
<value >
test=1,ROLE_USER
lisi=1,ROLE_SUPERVISOR
zhangsan=1,ROLE_SUPERVISOR,disabled
</value >
</property >
</bean >
分析:
具體開發步驟:
項目目錄如下: 其中readme主要用來記錄本次驗證目的
講解:
<bean id="userDetailsService"
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
<property name="jdbcTemplate" ref="JdbcTemplate"> </property>
</bean>
<bean id="JdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="userDetailsService"
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
自定義方式數據結構
<bean id="userDetailsService"
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
<property name="jdbcTemplate" ref="JdbcTemplate"> </property>
<!-- 配置查詢條件 -->
<property name="usersByUsernameQuery">
<value>
select t.user_name,t.pwd,t.enabled from test_user t where t.user_name=?
</value>
</property>
<property name="authoritiesByUsernameQuery">
<value>
select t.user_name,t.auths from test_auths t where t.user_name=?
</value>
</property>
</bean>
<bean id="JdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>