Spring security(二)
Spring security用户权限数据库配置:将用户角色和用户名都放在一张表里面(suser)
在上文中xml配置文件换成:
<bean id="datasource" class= "org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- 权限管理操作 -->
<security:authentication-manager> <security:authentication-provider> <!-- 密码加密方式. md5--> <security:password-encoder hash="md5"/> <!-- 注入dataSource验证数据库中的用户名.密码.账号状态.和权限相关; --> <security:jdbc-user-service data-source-ref="dataSource" users-by-username-query="select username,password,enable as status from suser where username=?" authorities-by-username-query="select username,authorities as 'authority' from suser where username=?"/> </security:authentication-provider> </security:authentication-manager>