spring security里user表和authorities表名字改了该如何操作

    xiaoxiao2026-08-13  13

    大家都知道,如果使用ss的官方配置的话,必须用户表严格定义为users,权限表严格定义为authorities,

    然而在工程里面可能表的名字不可以严格遵守这种命名规则

    这就需要我们进行自定义配置,之前我也找了很多方法,没有解决,最后参考别人的一篇博客,获得了启发,参照这里

    在xml里加上

    <security:authentication-manager> <security:authentication-provider> <security:jdbc-user-service data-source-ref="dataSource" users-by-username-query = "select username,password,enabled from cpt_users where username = ?" authorities-by-username-query = "select username,authority from cpt_authorities where username = ?" /> </security:authentication-provider> </security:authentication-manager>也就是自己重写查询语句,具体的查询语句请根据数据库来进行书写,即可实现这个功能,

    同时也附上我的informix数据库的数据源配置

    <!-- 配置数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.informix.jdbc.IfxDriver"/> <property name="url" value="jdbc:informix-sqli://XXXXXXX"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean>即可

    转载请注明原文地址: https://ju.6miu.com/read-1311147.html
    最新回复(0)