我正在使用 jdbc-user-service 进行春季安全登录。它在 Mysql 上工作,但不在 oracle 上。我正在使用 oracle 11 XE。
我在标签中提到的查询是正确的,因为当我在 oracle 控制台上运行这些查询时,它们会返回预期的行。
数据源是:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${datasource.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
</bean>
在 sessionFactory bean hibernate dialect for oracle 中给出。
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
相同的代码适用于 mysql 而不适用于 oracle。应用程序控件被重定向到我在 spring 安全文件中设置的登录页面。这意味着它正在正确获取用户名和密码。
<form-login login-page="/landing" default-target-url="/home"
authentication-failure-url="/landing?msg=cw" />
spring security xml 中的身份验证提供程序代码是:
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select USERNAME as username, PASSWORD as password,'true' as enabled from
users where USERNAME=?"
authorities-by-username-query=" select u.USERNAME
as username, r.ROLE as authority from users u, roles r, user_roles
ur where u.USER_ID = ur.USER_ID and ur.ROLE_ID = r.id and u.USER_ID = (SELECT
USER_ID from users where USERNAME = ?)" />
</authentication-provider>
</authentication-manager>
为了在 Spring Security 中使用 oracle,是否需要进行任何配置?
更新:我设置了 spring 安全调试,这是我尝试登录后打印的内容。
INFO : Spring Security Debugger -
************************************************************
Request received for '/j_spring_security_check':
org.apache.catalina.connector.RequestFacade@7262b6
servletPath:/j_spring_security_check
pathInfo:null
Security filter chain: [
ConcurrentSessionFilter
SecurityContextPersistenceFilter
LogoutFilter
UsernamePasswordAuthenticationFilter
BasicAuthenticationFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
]
************************************************************
INFO : Spring Security Debugger -
************************************************************
Request received for '/landing?msg=cw':
org.apache.catalina.connector.RequestFacade@bf1a4a
servletPath:/landing
pathInfo:null
Security filter chain: [
ConcurrentSessionFilter
SecurityContextPersistenceFilter
LogoutFilter
UsernamePasswordAuthenticationFilter
BasicAuthenticationFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
]
************************************************************