简体   繁体   中英

jdbc spring security, apache commons dbcp

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

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

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

This path actually isn't included in 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.
Seems like my user is authenticated, but isn't authorized.
Any idea...? :-)

My http element is:

<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 Pool Downloads

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

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

Try changing your test user's authority to ROLE_USER.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM