Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Security区分大小写_Java_Spring_Spring Security - Fatal编程技术网

Java Spring Security区分大小写

Java Spring Security区分大小写,java,spring,spring-security,Java,Spring,Spring Security,我的MySql数据库区分大小写,在hibernate中一切正常,数据库中的表名与我的类相同。但是在Spring安全性上,默认身份验证不起作用,使用表名的第一个字母构建SQL时使用小写而不是大写。有没有办法让SpringSecurity像hibernate一样理解大写字母?或者我只需要构建一个自定义身份验证来将表名更改为大写字母 <!-- Session Factory Hibernate --> <bean id="sessionFactory" class="org.

我的MySql数据库区分大小写,在hibernate中一切正常,数据库中的表名与我的类相同。但是在Spring安全性上,默认身份验证不起作用,使用表名的第一个字母构建SQL时使用小写而不是大写。有没有办法让SpringSecurity像hibernate一样理解大写字母?或者我只需要构建一个自定义身份验证来将表名更改为大写字母

<!-- Session Factory Hibernate -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

    <property name="packagesToScan" value="br.com.empresa.domain" />
    <property name="dataSource">
        <ref local="mySQLdataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
            <!-- Novos geradores de ids recomendados pela documentação do hibernate -->
            <prop key="hibernate.id.new_generator_mappings">false</prop> 
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>

</bean>

<!-- Conexão com o Banco de Dados -->
<bean id="mySQLdataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/db" />    --> 
    <property name="username" value="root" />
    <property name="password" value="asd123456" />

</bean>

<!-- It is responsible for validating the user's credentials -->
<security:authentication-manager>

    <!-- It is responsible for providing credential validation to the AuthenticationManager -->
    <security:authentication-provider>
        <security:password-encoder ref="passwordEncoder" />
        <security:jdbc-user-service
            data-source-ref="mySQLdataSource" />
    </security:authentication-provider>

</security:authentication-manager>

<bean
    class="org.springframework.security.crypto.password.StandardPasswordEncoder"
    id="passwordEncoder" />

org.hibernate.dialogue.mysqldialogue
创建下降
假的
真的
--> 

我假设您使用JdbcDaoImpl(通过jdbc用户服务元素)。如果这是真的,那么您可以为默认查询提供自己的SQL

<jdbc-user-service 
    users-by-username-query="select username, password, enabled from Users where username = ?" 
    authorities-by-username-query="select username, authority from Authorities where username = ?" 
/>


spring security如何访问数据库?您是如何配置的?@Kent添加了我的配置,如果您需要用户名不区分大小写,那么只需在
WHERE
子句中使用本机函数,如
lower()
(或
upper()
),如
WHERE lower(username)=lower(?)
@Maksym Demidas,这正是我在互联网上找到的方式,很好,但是为什么SpringSecurity的行为不像hibernate?我放置@Table(name=“Users”)注释。无论如何,Spring应该与hibernate有更好的集成,那么注释就足够了。因为Spring安全性即使没有hibernate也必须工作。因此JdbcDaoImpl使用普通的JDBC调用而不是Hibernate。如果需要,可以提供自己的DAO,该DAO实现UserDetailsService并使用Hibernate。Spring Security将能够使用它。感谢您的帮助,我尝试了上面的配置,它比我在Internet上找到的配置更准确。经过一些建议,我决定更改MySql上的区分大小写选项。mysql根目录上my.ini上的小写字母表命名变量。我只是把小写字母放在表中,问题就解决了,现在MySql不区分大小写了。