2012-11-07 184 views
0

我正在使用jdbc-user-service进行spring安全登录。它正在使用Mysql,但不在oracle上。我正在使用oracle 11 XE。春季安全登录不能与oracle

我在标记中提到的查询是正确的,因为那些在Oracle控制台上运行时会返回预期的行。

的数据源是:

在SessionFactory的豆
<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> 

冬眠方言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" /> 

春季安全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> 

有什么需要,才能在春季安全使用Oracle进行配置?

更新:我设置春季安全调试,这是我尝试登录后打印什么。

INFO : Spring Security Debugger - 

************************************************************ 

Request received for '/j_spring_security_check': 

[email protected] 

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': 

[email protected] 

servletPath:/landing 
pathInfo:null 

Security filter chain: [ 
ConcurrentSessionFilter 
SecurityContextPersistenceFilter 
LogoutFilter 
UsernamePasswordAuthenticationFilter 
BasicAuthenticationFilter 
RequestCacheAwareFilter 
SecurityContextHolderAwareRequestFilter 
AnonymousAuthenticationFilter 
SessionManagementFilter 
ExceptionTranslationFilter 
FilterSecurityInterceptor 
] 


************************************************************ 
+0

你能发布错误吗? –

+0

我没有看到任何错误背后。即使凭据正确,它也会返回登录页面。 –

+0

增加日志级别以进行调试并查看弹簧安全性正在打印什么消息。 –

回答

0

请确保您有ojdbc6.jar或在classpath将ojdbc14.jar(待定Oracle版本)。

+0

是的,我在类路径中有ojdbc14.jar。 –

1

我有同样的问题,经过几小时的研究,我找到了解决方案。 Spring安全性的用户详细信息需要启用布尔值并且Oracle上的“true”不起作用。我修复它替换此:

users-by-username-query=" 
select USERNAME as username, PASSWORD as password,'true' as enabled from 
users where USERNAME=?" 

要这样:

users-by-username-query=" 
select USERNAME as username, PASSWORD as password,1 as enabled from 
users where USERNAME=?" 

它的工作原理!我发现解决方案的读数为here

+0

谢谢。这是我的一个很老的帖子。后来,我用DaoAuthenticationManager用自定义认证取代了Spring安全代码。感谢您的时间和努力。 –