我想從數據庫中獲取認證角色。桌子在那裏,這裏是我的上下文:users-by-username-query返回沒有結果
<!-- Configures in-memory implementation of the UserDetailsService implementation -->
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select * from users where email=?"
authorities-by-username-query="select u.email, ur.authority from users u, usersroles ur where u.id = ur.userid and u.email = ?"
/>
</security:authentication-provider>
</security:authentication-manager>
用戶通過電子郵件進行身份驗證。當DB控制檯這樣的查詢,它返回一個obejct,但是當我看看日誌,我發現:
16:18:55,517 DEBUG JdbcTemplate:637 - Executing prepared SQL query
16:18:55,518 DEBUG JdbcTemplate:572 - Executing prepared SQL statement [select * from users where email=?]
16:18:55,519 DEBUG DataSourceUtils:110 - Fetching JDBC Connection from DataSource
16:18:55,519 DEBUG DriverManagerDataSource:162 - Creating new JDBC DriverManager Connection to [jdbc:h2:file:../lib/Money]
16:18:55,582 DEBUG DataSourceUtils:327 - Returning JDBC Connection to DataSource
16:18:55,607 DEBUG JdbcUserDetailsManager:154 - Query returned no results for user ''
16:18:55,610 DEBUG DaoAuthenticationProvider:134 - User '' not found
16:18:55,610 DEBUG UsernamePasswordAuthenticationFilter:346 - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
我在做什麼錯?
用戶和密碼從前端代碼發送。我猜,一切都很好。我發送一個簡單的JSON用戶名和密碼。我覺得autenticationManager有問題。下面是代碼:
<!-- Configures a custom login filter bean -->
<bean id="loginFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureHandler" ref="restAuthenticationFailureHandler"/>
<property name="authenticationSuccessHandler" ref="restAuthenticationSuccessHandler"/>
<property name="filterProcessesUrl" value="/api/login/"/>
<property name="usernameParameter" value="username"/>
<property name="passwordParameter" value="password"/>
<property name="postOnly" value="true"/>
</bean>
'用戶「」'這是你的線索......該電子郵件莫名其妙地沒有設置好的 –
讓我們看看,因爲那裏有一些錯誤的執行查詢的一些代碼,如日誌 – Ben
說@Ben我更新了問題與更多信息 –