By default, the Pentaho distribution comes with the Hibernate-based security data access object (DAO) enabled. If you already have existing security tables in a relational database, you might want to consider the JDBC back-end for its simplicity and flexibility. This page shows you how to switch to the "JDBC" DAO. The instructions below describe a sample security database using HSQLDB.

Note: Changing to the JDBC Security DAO means that you will no longer be able to use the user/role administration functionality found in the Pentaho Admin Console.

  1. Edit pentaho-spring-beans.xml
    Change the Spring XML files to use the JDBC DAOs instead of the Hibernate ones. Open pentaho-solutions/system/pentaho-spring-beans.xml and look for the following section:
    <beans>
      <!-- some lines omitted -->
      <import resource="applicationContext-spring-security.xml" />
      <import resource="applicationContext-common-authorization.xml" />
      <import resource="applicationContext-spring-security-jdbc.xml" />
      <import resource="applicationContext-pentaho-security-jdbc.xml" />
    </beans>
    
  2. Create the security tables
    Copy the below SQL into a file called userdb.script.
    The sample Spring XML files (i.e. applicationContext-spring-security-jdbc.xml and applicationContext-pentaho-security-jdbc.xml) assume a HSQLDB database and the tables below. If you already have security tables setup, or you wish to alter the sample, you'll need to adjust your SQL queries in the aforementioned Spring XML files.

    CREATE SCHEMA PUBLIC AUTHORIZATION DBA
    CREATE MEMORY TABLE USERS(USERNAME VARCHAR(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR(50) NOT NULL,ENABLED BOOLEAN NOT NULL,
    DESCRIPTION VARCHAR(100))
    CREATE MEMORY TABLE AUTHORITIES(AUTHORITY VARCHAR(50) NOT NULL PRIMARY KEY,DESCRIPTION VARCHAR(100))
    CREATE MEMORY TABLE GRANTED_AUTHORITIES(USERNAME VARCHAR(50) NOT NULL,AUTHORITY VARCHAR(50) NOT NULL,CONSTRAINT FK_GRANTED_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME),CONSTRAINT FK_GRANTED_AUTHORITIES_AUTHORITIES FOREIGN KEY(AUTHORITY) REFERENCES AUTHORITIES(AUTHORITY))
    CREATE USER SA PASSWORD ""
    GRANT DBA TO SA
    SET WRITE_DELAY 10
    SET SCHEMA PUBLIC
    INSERT INTO USERS VALUES('admin','secret',TRUE)
    INSERT INTO USERS VALUES('joe','password',TRUE)
    INSERT INTO USERS VALUES('pat','password',TRUE)
    INSERT INTO USERS VALUES('suzy','password',TRUE)
    INSERT INTO USERS VALUES('tiffany','password',TRUE)
    INSERT INTO AUTHORITIES VALUES('Admin','Super User')
    INSERT INTO AUTHORITIES VALUES('Anonymous','User has not logged in')
    INSERT INTO AUTHORITIES VALUES('Authenticated','User has logged in')
    INSERT INTO AUTHORITIES VALUES('ceo','Chief Executive Officer')
    INSERT INTO AUTHORITIES VALUES('cto','Chief Technology Officer')
    INSERT INTO AUTHORITIES VALUES('dev','Developer')
    INSERT INTO AUTHORITIES VALUES('devmgr','Development Manager')
    INSERT INTO AUTHORITIES VALUES('is','Information Services')
    INSERT INTO GRANTED_AUTHORITIES VALUES('joe','Admin')
    INSERT INTO GRANTED_AUTHORITIES VALUES('joe','ceo')
    INSERT INTO GRANTED_AUTHORITIES VALUES('joe','Authenticated')
    INSERT INTO GRANTED_AUTHORITIES VALUES('suzy','cto')
    INSERT INTO GRANTED_AUTHORITIES VALUES('suzy','is')
    INSERT INTO GRANTED_AUTHORITIES VALUES('suzy','Authenticated')
    INSERT INTO GRANTED_AUTHORITIES VALUES('pat','dev')
    INSERT INTO GRANTED_AUTHORITIES VALUES('pat','Authenticated')
    INSERT INTO GRANTED_AUTHORITIES VALUES('tiffany','dev')
    INSERT INTO GRANTED_AUTHORITIES VALUES('tiffany','devmgr')
    INSERT INTO GRANTED_AUTHORITIES VALUES('tiffany','Authenticated')
    INSERT INTO GRANTED_AUTHORITIES VALUES('admin','Admin')
    INSERT INTO GRANTED_AUTHORITIES VALUES('admin','Authenticated')

  3. Start the database
    The security database will need to be running before the first user logs in.

    java -cp lib\hsqldb.jar org.hsqldb.Server -database.0 userdb -dbname.0 userdb -port 9002
    exit

  4. The default JDBC configuration should work with the above database and tables. If you want to change the database host or anything else about the configuration, see Security Data Access Objects.
  5. Start the application server
    Now that the database is running and the security tables have been created, start the application server.
  6. Stop the database
    When you shutdown your application server, you'll want to shutdown the security database as well. The command to do that is below.

    java -cp lib\hsqldb.jar org.hsqldb.util.ShutdownServer -url "jdbc:hsqldb:hsql://localhost:9002/userdb" -user "sa" -password ""
    exit