java jdbc spring 安全,apache commons dbcp

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6509200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:09:06  来源:igfitidea点击:

jdbc spring security, apache commons dbcp

javajakarta-eespring-securityapache-commons-dbcp

提问by AgostinoX

In a Spring Security, I defined a jdbc auth manager:

在 Spring Security 中,我定义了一个 jdbc 身份验证管理器:

<security:authentication-manager>
    <security:authentication-provider>
        <security:jdbc-user-service data-source-ref="securityDataSource"/>
    </security:authentication-provider>
</security:authentication-manager>

<bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://127.0.0.1:5432/mydb"/>
    ... user and password props ...
</bean>

At this point I've discovered that I need Jakarta Commons DBCP. I've added commons-dbcp-1.4, i get the following exception:

此时我发现我需要 Jakarta Commons DBCP。我添加了 commons-dbcp-1.4,但出现以下异常:

...java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory

This path actually isn't included in commons dbcp 1.4.
What am I missing again?

此路径实际上不包含在 commons dbcp 1.4 中。
我又错过了什么?

EDITED
Ok, added the dependency to common pool, it works because with the right credentials I no more get the "bad credentials" page. But I get an HTTP Status 403 - Access is denied.
Seems like my user is authenticated , but isn't authorized.
Any idea...? :-)

My http element is:

编辑
好的,将依赖项添加到公共池,它可以工作,因为使用正确的凭据我不再获得“错误凭据”页面。但是我收到一个 HTTP 状态 403 - 访问被拒绝。
似乎我的用户已通过身份验证,但未获得授权。
任何的想法...?:-)

我的 http 元素是:

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

and I have a "test" user that is bind to the "USER" role in the "authorities" table.

我有一个“测试”用户,它绑定到“权限”表中的“用户”角色。

thanks

谢谢

回答by El Guapo

Commons DBCP relies on the Commons Pools libraries, because of this, you actually need to download the commons-pool jar files, and include them in your path.

Commons DBCP 依赖于 Commons Pools 库,因此,您实际上需要下载 commons-pool jar 文件,并将它们包含在您的路径中。

Commons Pool Downloads

共享池下载

You may also need to download the commons-collections package, too.

您可能还需要下载 commons-collections 包。

回答by Rakesh

The jar file commons-dbcp-1.4 does not contain the class org.apache.commons.pool.keyedobjectpoolfactory
You need to add another jar to your project classpath - commons-pool-1.4.
You can download commons-pool-1.4 from here http://commons.apache.org/pool/download_pool.cgi

jar 文件 commons-dbcp-1.4 不包含类org.apache.commons.pool.keyedobjectpoolfactory
你需要在你的项目类路径中添加另一个 jar - commons-pool-1.4。
您可以从这里下载 commons-pool-1.4 http://commons.apache.org/pool/download_pool.cgi

回答by Owen

Try changing your test user's authority to ROLE_USER.

尝试将您的测试用户的权限更改为 ROLE_USER。

回答by Drizzt321

Don't forget you'll also need the Postgre JDBC drivers, just in case you hadn't included those already.

不要忘记您还需要 Postgre JDBC 驱动程序,以防万一您还没有包含这些驱动程序。