Skip to content


Subversion checkout URL

You can clone with
Download ZIP
JDBI-based Shiro realm implemntation.
Branch: master
Pull request Compare This branch is 6 commits behind Multifarious:master.

io.ifar: shiro-jdbi-realm

JdbiRealm for Shiro.

Database-backed UserDAO-based Shiro Realm with database access implemented via DBI.

Designed for use with Dropwizard.


The bundle includes all the pieces needed for a simple database-backed Realm that can be used to authenticate and authorize users.

Usage / Configuration

Include the maven dependency.

You need to configure database access. For example, via a DatabaseConfiguration section of your .yml config file.

Add a JdbiRealmLoaderListener that will inject a DBI instance into the JdbiShiroRealm instances.

import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.jdbi.DBIFactory;
import org.apache.shiro.web.env.EnvironmentLoaderListener;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.eclipse.jetty.server.session.SessionHandler;
import org.skife.jdbi.v2.DBI;
public class ExampleService extends Service<ExampleConfiguration> {
    public void run(ExampleConfiguration config,
                    Environment environment) throws ClassNotFoundException {

        // setup Shiro
        environment.setSessionHandler(new SessionHandler());
        environment.addServletListeners(new EnvironmentLoaderListener());
        environment.addFilter(new ShiroFilter(), "/*").setName("shiro-filter");

        // create a DBI
        final DBIFactory factory = new DBIFactory();
        final DBI jdbi =, config.getDatabaseConfiguration(), "hsqldb");

        // make sure each JdbiRealm has the DBI.
        environment.addServletListeners(new JdbiRealmLoaderListener(jdbi));

Alternatively, if using an IOC container like Spring or Guice you can do the full configuration of the JdbiShiroRealm via those frameworks.


The database needs to exist and have the expected tables. See the changelogs in the ./src/main/resources/liquibase folder.

Classes in this package can be used for creating Users and assigning them Roles. Currently Roles and Permissions need to be pre-configured, e.g., via SQL.

Related Shiro and Dropwizard Configuration

The JdbiShiroRealm instance can be created and assignd to the securityManager via the Shiro .ini

# Users, roles, and permissions from the database, accessed via DBI.
jdbiRealm =
securityManager.realm = $jdbiRealm

You can optionally set the jdbiRealm.credentialsMatcher and other inherited properties on the realm instance such as the AuthorizingRealm's authorizationCache.

Access with Maven


Include the following in your pom.xml:



Snapshots are available from the following Maven repository:

  <name>Multifarious, Inc. Snapshot Repository</name>


None as yet, but when there are, they will be published via Maven Central.


The license is BSD 2-clause. This information is also present in the LICENSE.txt file and in the pom.xml.

Something went wrong with that request. Please try again.