Spring Security和DerbyDB(javaDB)

时间:2013-10-22 14:27:58

标签: java spring spring-mvc spring-security derby

我正在参与一个涉及Spring MVC,Spring Security和DerbyDB的学校项目。

我有一个问题我无法解决,我需要帮助,提前谢谢。

当我尝试使用真实用户登录时(打印在网页上),这是消息:

Your login attempt was not successful, try again.

Reason: PreparedStatementCallback; bad SQL grammar [select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?]; nested exception is java.sql.SQLException: Column '3' not found.

以下是控制台中的消息:

SQL error codes for 'Apache Derby' found
2013-10-22 16:07:16 [DEBUG] SQLErrorCodeSQLExceptionTranslator:283 - Unable to translate SQLException with SQL state 'S0022', error code '0, will now try the fallback translator
2013-10-22 16:07:16 [DEBUG] SQLStateSQLExceptionTranslator:95 - Extracted SQL state class 'S0' from value 'S0022'
2013-10-22 16:07:16 [DEBUG] UsernamePasswordAuthenticationFilter:346 - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: PreparedStatementCallback; bad SQL grammar [select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?]; nested exception is java.sql.SQLException: Column '3' not found.
2013-10-22 16:07:16 [DEBUG] UsernamePasswordAuthenticationFilter:347 - Updated SecurityContextHolder to contain null Authentication

我的数据源bean:

   <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
    <property name="url" value="jdbc:derby:/home/couty/capDB;create=true" />
    <property name="username" value="root" />
    <property name="password" value="password" />
   </bean>

spring-security.xml:

<http auto-config="true">
        <intercept-url pattern="/welcome*" access="ROLE_USER" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"

                users-by-username-query='select LOGIN, PASSWORD from theaterDB."User" where LOGIN = ?'/>

                <!-- authorities-by-username-query="select u.login, ur.role from User u, UserRole ur where u.id = ur.user_id and u.login =?  " --> 

        </authentication-provider>
    </authentication-manager>

如你所见: 我正在尝试访问/欢迎页面时登录。 我使用的JDBC驱动程序是DERBY,而不是ORACLE。为什么?因为我已经有了德比和甲骨文似乎很痛苦。我不知道它会发生什么变化。

1 个答案:

答案 0 :(得分:0)

我认为你必须添加一个“启用”的附加列来进行查询。这样的事情 - 选择从剧院数据库启用的LOGIN,PASSWORD。“用户”,其中LOGIN = ?.

我有同样的问题,这在我的案例中起作用;)