Previous: Getting started with JPA Security | Up: Getting started with JPA Security | Next: Integration with Java EE Security |
In order to use JPA Security you have to enable it for your persistence unit. This can be done by modifying your "persistence.xml" to point to JPA Security. Additionally you have to configure JPA Security to use your original persistence provider.
persistence.xml ExampleSupposed you have an existing JPA application. Your persistence.xml may look similar to this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="your-persistence-unit-name" transaction-type="..."> <provider>your.persistence.provider.ClassName</provider> <class>your.persistent.ClassName</class> <!-- More class-mappings go here --> ... <properties> <!-- persistence-provider-specific properties go here --> ... </properties> </persistence-unit> </persistence>
After integrating JPA Security your "persistence.xml" may look like this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="your-persistence-unit-name" transaction-type="..."> <provider>net.sf.jpasecurity.persistence.SecurePersistenceProvider</provider> <class>your.persistent.ClassName</class> <!-- More class-mappings go here --> ... <properties> <property name="net.sf.jpasecurity.persistence.provider" value="your.persistence.provider.ClassName" /> <!-- persistence-provider-specific properties go here --> ... </properties> </persistence-unit> </persistence>
We changed the <provider> tag to point to JPA Security's implementation of the PersistenceProvider interface and added the property net.sf.jpasecurity.persistence.provider to point to your original persistence provider. That is all you need to integrate JPA Security.