Example usage for org.apache.shiro.realm.jdbc JdbcRealm setCredentialsMatcher

List of usage examples for org.apache.shiro.realm.jdbc JdbcRealm setCredentialsMatcher

Introduction

In this page you can find the example usage for org.apache.shiro.realm.jdbc JdbcRealm setCredentialsMatcher.

Prototype

public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) 

Source Link

Document

Sets the CrendialsMatcher used during an authentication attempt to verify submitted credentials with those stored in the system.

Usage

From source file:com.aegeus.core.AuthenticationConfiguration.java

License:Apache License

@Bean
public JdbcRealm realm() {
    ConfigObject config = config();//from w  w  w  . ja  v  a  2 s . c o  m

    String uri = String.format("jdbc:%s://%s:%d/%s", config.getWorkflow().getMetaStore().getType(),
            config.getWorkflow().getMetaStore().getHost(), config.getWorkflow().getMetaStore().getPort(),
            config.getWorkflow().getMetaStore().getDb());

    // initialize meta store database connection
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(uri);
    ds.setUser(config.getWorkflow().getMetaStore().getUsername());
    ds.setPassword(config.getWorkflow().getMetaStore().getPassword());

    HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
    matcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);

    JdbcRealm realm = new JdbcRealm();
    realm.setDataSource(ds);
    realm.setPermissionsLookupEnabled(true);
    realm.setAuthenticationQuery("SELECT pass FROM users WHERE user = ?");
    realm.setPermissionsQuery(
            "SELECT p.permission FROM permissions p INNER JOIN users u ON p.user_id = u.id WHERE u.user = ?");
    realm.setUserRolesQuery(
            "SELECT r.role FROM roles r INNER JOIN users u ON u.id = r.user_id WHERE u.user = ?");
    realm.setCredentialsMatcher(matcher);
    realm.init();

    return realm;
}