As stated before you may implement your own way of providing access rules (i.e. via JDBC). You have to implement the interface and specify the property in your persistence.xml with the classname of your implementation of the interface Take a look at its javadoc documentation for further reference.

Accessing persistence properties

Your custom access rules provider may need additional configuration parameters. You can define them via the persistence properties in your persistence.xml. All you have to do, is to implement the interface net.sf.jpasecurity.persistence.PersistenceInformationReceiver. Then you will have the persistence properties injected when your persistence provider is initialized.

Implementing an Access Rules Provider

When you take a look at the methods of net.sf.jpasecurity.rules.AccessRulesProvider, you may notice that you need to create objects of type This objects may be created using a net.sf.jpasecurity.jpql.parser.JpqlParser in conjunction with an, but you may subclass to inherit this functionality. Then you have to override initializeAccessRules and call compileRules from within.


Implementing a JDBC access rules provider">

The following code shows how to implement an access rules provider that reads its access rules from a database. You may specify the needed parameters in your persistence.xml.

public class JdbcAccessRulesProvider extends AbstractAccessRulesProvider {

  public static final String ACCESS_RULES_JDBC_URL_PROPERTY = "";
  public static final String ACCESS_RULES_JDBC_USERNAME_PROPERTY = "";
  public static final String ACCESS_RULES_JDBC_PASSWORD_PROPERTY = "";  
  public static final String ACCESS_RULES_JDBC_TABLE_PROPERTY = "";
  public static final String ACCESS_RULES_JDBC_COLUMN_PROPERTY = "";

  protected void initializeAccessRules() {
    Map<String, String> properties = getPersistenceProperties();
    String url = getPersistenceProperty(ACCESS_RULES_JDBC_URL_PROPERTY);
    String username = getPersistenceProperty(ACCESS_RULES_JDBC_USERNAME_PROPERTY);
    String password = getPersistenceProperty(ACCESS_RULES_JDBC_PASSWORD_PROPERTY);
    String table = getPersistenceProperty(ACCESS_RULES_JDBC_TABLE_PROPERTY);
    String column = getPersistenceProperty(ACCESS_RULES_JDBC_COLUMN_PROPERTY);
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    Collection<String> accessRules = new HashSet<String>();
    try {
      connection = DriverManager.getConnection(url, username, password);
      statement = connection.createStatement();
      resultSet = statement.executeQuery("SELECT " + column + " FROM " + table);
      while ( {
    } catch (SQLException e) {
      throw new PersistenceException("Error reading access rules", e);
    } finally {
  private String getPersistenceProperty(String propertyName) {
    String propertyValue = getPersistenceProperties().get(propertyName);
    if (propertyValue == null) {
      throw new PersistenceException("Error reading acces rules, property " + propertyName + " must be set");
    return propertyValue;
  private void close(ResultSet resultSet) {
    if (resultSet != null) {
      try {
      } catch (SQLException e) {

  private void close(Statement statement) {
    if (statement != null) {
      try {
      } catch (SQLException e) {

  private void close(Connection connection) {
    if (connection != null) {
      try {
      } catch (SQLException e) {

In your persistence.xml you can specify the needed parameters like following.

<persistence ...>

  <persistence-unit name="..." ...>


      <property name="" value="jdbc:your.db.url" />
      <property name="" value="your_username" />
      <property name="" value="your_password" />
      <property name="" value="your_table_with_access_rules" />
      <property name="" value="your_column_containing_the_access_rules" />