简体   繁体   中英

Spring Security Case Sensitive

My MySql database is case sensitive, everything works fine in hibernate, table name in the data base are the same of my classes. But on Spring Security, the default authentication doesn't work well, building the SQL with the first letter of the table name with lower case instead of upper case. Is there any way to make spring security understand upper case like hibernate does? Or Do I need to build a custom authentication only to change the table name to capital letter?

<!-- 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" />

I suppose that you use JdbcDaoImpl (via jdbc-user-service element). If it's true then you can provide your own SQL for default queries.

<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 = ?" 
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM