我一直在尝试使用Spring安全性来学习不同的东西。我设置了具有“用户”表和“权限”表的基本结构的授权。所以我的身份验证提供程序如下所示。
<authentication-provider>
<password-encoder hash='md5'>
<salt-source user-property="username"/>
</password-encoder>
<jdbc-user-service data-source-ref="dataSource"/>
</authentication-provider>
通过这种方式,我没有指定查询来获取用户详细信息,因为我使用默认的database schema。因此,尽管我没有使用“权限由用户名 - 查询”属性,Spring正在使用默认查询(“选择用户名,权限来自权限用户=?”和“选择用户名,密码,从用户名=? “)所以事情进展顺利。
现在我想尝试权限组。所以我根据架构创建表。我的问题如何激活群组权限? API documentation for JdbcDaoImpl表示使用“enableGroups”属性来启用“基于组的权限”。但“基于团体的当局”没有这样的财产。由于Spring有default query,我认为不需要明确地给它。
因此,有人可以帮助我使用默认查询启用基于组的权限。
答案 0 :(得分:5)
不幸的是, jdbc-user-service 不提供对 enableGroups 属性的访问权限。因此,您必须使用spring的bean命名空间手动配置此bean。 我想你可以尝试这样的事情:
<authentication-provider user-service-ref="jdbcDaoImpl">
<password-encoder hash='md5'>
<salt-source user-property="username"/>
</password-encoder>
</authentication-provider>
<beans:bean id="jdbcDaoImpl" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
<property name="enableGroups" value="true" />
<property name="enableAuthorities" value="false" />
<property name="dataSource" ref="dataSource" />
</beans:bean>