简体   繁体   English

jdbc spring 安全,apache 公用 dbcp

[英]jdbc spring security, apache commons dbcp

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.在这一点上,我发现我需要 Jakarta Commons DBCP。 I've added commons-dbcp-1.4, i get the following exception:我添加了 commons-dbcp-1.4,我得到以下异常:

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

This path actually isn't included in commons dbcp 1.4.此路径实际上不包含在 commons dbcp 1.4 中。
What am I missing again?我又错过了什么?

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.但我得到一个 HTTP 状态 403 - 访问被拒绝。
Seems like my user is authenticated, but isn't authorized.似乎我的用户已通过身份验证,但未经授权。
Any idea...?任何想法...? :-) :-)

My http element is:我的 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谢谢

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 package。

The jar file commons-dbcp-1.4 does not contain the class org.apache.commons.pool.keyedobjectpoolfactory jar 文件 commons-dbcp-1.4 不包含 class org.apache.commons.pool.keyedobjectpoolfactory
You need to add another jar to your project classpath - commons-pool-1.4.您需要将另一个 jar 添加到您的项目类路径 - commons-pool-1.4。
You can download commons-pool-1.4 from here http://commons.apache.org/pool/download_pool.cgi您可以从这里下载 commons-pool-1.4 http://commons.apache.org/pool/download_pool.cgi

Try changing your test user's authority to ROLE_USER.尝试将您的测试用户的权限更改为 ROLE_USER。

Don't forget you'll also need the Postgre JDBC drivers, just in case you hadn't included those already.不要忘记您还需要 Postgre JDBC 驱动程序,以防万一您还没有包含这些驱动程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache-Commons-DBCP问题 - Apache-Commons-DBCP Issue org.apache.commons.dbcp.DelegatingPreparedStatement无法强制转换为com.mysql.jdbc.PreparedStatement - org.apache.commons.dbcp.DelegatingPreparedStatement cannot be cast to com.mysql.jdbc.PreparedStatement org.apache.commons.dbcp.SQLNestedException:无法加载JDBC驱动程序类&#39;$ {driver}&#39; - org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${driver}' 在重启spring-jdbc,commons-dbcp,tomcat时无法连接到数据库 - Failing to connect to database on restart spring-jdbc, commons-dbcp,tomcat apache commons dbcp connection pool error:使用Spring Transactions在Spring + Hibernate应用程序中等待空闲对象超时 - apache commons dbcp connection pool error: Timeout waiting for idle object in a Spring + Hibernate app using Spring Transactions Spring MVC Web应用程序找不到org.apache.commons.dbcp.BasicDataSource类 - Spring MVC web app cannot find org.apache.commons.dbcp.BasicDataSource class 无法在spring-servlet.xml文件中创建org.apache.commons.dbcp.BasicDataSource的bean - unable to create bean of org.apache.commons.dbcp.BasicDataSource in spring-servlet.xml file Apache Commons DBCP 连接对象问题,线程:org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper 中的 ClassCastException - Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper 使用 Spring 配置 apache dbcp PoolingDataSource - Configuring apache dbcp PoolingDataSource with Spring 带有Tomcat DBCP和多个数据源的Spring JDBC - Spring JDBC with Tomcat DBCP and multiple datasources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM