com.vii.brillien.services.sso.shiro
Class BrillienRealm

java.lang.Object
  extended by org.apache.shiro.realm.CachingRealm
      extended by org.apache.shiro.realm.AuthenticatingRealm
          extended by org.apache.shiro.realm.AuthorizingRealm
              extended by com.vii.brillien.services.sso.shiro.BrillienRealm
All Implemented Interfaces:
org.apache.shiro.authc.LogoutAware, org.apache.shiro.authz.Authorizer, org.apache.shiro.authz.permission.PermissionResolverAware, org.apache.shiro.authz.permission.RolePermissionResolverAware, org.apache.shiro.cache.CacheManagerAware, org.apache.shiro.realm.Realm, org.apache.shiro.util.Initializable, org.apache.shiro.util.Nameable

public class BrillienRealm
extends org.apache.shiro.realm.AuthorizingRealm

Specialized AuthorizingRealm to make Brillien-like DataSources available


Field Summary
protected  String authenticationQuery
           
protected  String datasourcePresence
           
protected static String DEFAULT_AUTHENTICATION_QUERY
          The default query used to retrieve account data for the user.
protected static String DEFAULT_PERMISSIONS_QUERY
          The default query used to retrieve permissions that apply to a particular role.
protected static String DEFAULT_USER_ROLES_QUERY
          The default query used to retrieve the roles that apply to a user.
protected  boolean permissionsLookupEnabled
           
protected  String permissionsQuery
           
protected  String userRolesQuery
           
 
Constructor Summary
BrillienRealm()
           
 
Method Summary
protected  org.apache.shiro.authc.AuthenticationInfo buildAuthenticationInfo(String username, char[] password)
           
protected  org.apache.shiro.authc.AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token)
           
protected  org.apache.shiro.authz.AuthorizationInfo doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals)
          This implementation of the interface expects the principals collection to return a String username keyed off of this realm's name
protected  Connection getConnection()
           
 String getDatasourcePresence()
           
protected  Set<String> getPermissions(Connection conn, String username, Collection<String> roleNames)
           
protected  Set<String> getRoleNamesForUser(Connection conn, String username)
           
protected  void retrieveConnection(Connection c)
           
 void setAuthenticationQuery(String authenticationQuery)
          Overrides the default query used to retrieve a user's password during authentication.
 void setDatasourcePresence(String datasourcePresence)
           
 void setPermissionsLookupEnabled(boolean permissionsLookupEnabled)
          Enables lookup of permissions during authorization.
 void setPermissionsQuery(String permissionsQuery)
          Overrides the default query used to retrieve a user's permissions during authorization.
 void setUserRolesQuery(String userRolesQuery)
          Overrides the default query used to retrieve a user's roles during authorization.
 
Methods inherited from class org.apache.shiro.realm.AuthorizingRealm
afterCacheManagerSet, checkPermission, checkPermission, checkPermission, checkPermissions, checkPermissions, checkPermissions, checkRole, checkRole, checkRoles, checkRoles, checkRoles, clearCachedAuthorizationInfo, doClearCache, getAuthorizationCache, getAuthorizationCacheKey, getAuthorizationCacheName, getAuthorizationInfo, getPermissionResolver, getRolePermissionResolver, hasAllRoles, hasRole, hasRole, hasRoles, hasRoles, isAuthorizationCachingEnabled, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, isPermittedAll, onInit, setAuthorizationCache, setAuthorizationCacheName, setAuthorizationCachingEnabled, setName, setPermissionResolver, setRolePermissionResolver
 
Methods inherited from class org.apache.shiro.realm.AuthenticatingRealm
assertCredentialsMatch, clearCachedAuthenticationInfo, getAuthenticationCache, getAuthenticationCacheKey, getAuthenticationCacheKey, getAuthenticationCacheName, getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, init, isAuthenticationCachingEnabled, isAuthenticationCachingEnabled, setAuthenticationCache, setAuthenticationCacheName, setAuthenticationCachingEnabled, setAuthenticationTokenClass, setCredentialsMatcher, supports
 
Methods inherited from class org.apache.shiro.realm.CachingRealm
clearCache, getAvailablePrincipal, getCacheManager, getName, isCachingEnabled, onLogout, setCacheManager, setCachingEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.shiro.util.Initializable
init
 

Field Detail

DEFAULT_AUTHENTICATION_QUERY

protected static final String DEFAULT_AUTHENTICATION_QUERY
The default query used to retrieve account data for the user.

See Also:
Constant Field Values

DEFAULT_USER_ROLES_QUERY

protected static final String DEFAULT_USER_ROLES_QUERY
The default query used to retrieve the roles that apply to a user.

See Also:
Constant Field Values

DEFAULT_PERMISSIONS_QUERY

protected static final String DEFAULT_PERMISSIONS_QUERY
The default query used to retrieve permissions that apply to a particular role.

See Also:
Constant Field Values

datasourcePresence

protected String datasourcePresence

authenticationQuery

protected String authenticationQuery

userRolesQuery

protected String userRolesQuery

permissionsQuery

protected String permissionsQuery

permissionsLookupEnabled

protected boolean permissionsLookupEnabled
Constructor Detail

BrillienRealm

public BrillienRealm()
Method Detail

getDatasourcePresence

public String getDatasourcePresence()

setDatasourcePresence

public void setDatasourcePresence(String datasourcePresence)
                           throws BrillienException
Throws:
BrillienException

getConnection

protected Connection getConnection()
                            throws BrillienException
Throws:
BrillienException

retrieveConnection

protected void retrieveConnection(Connection c)
                           throws BrillienException
Throws:
BrillienException

setAuthenticationQuery

public void setAuthenticationQuery(String authenticationQuery)
Overrides the default query used to retrieve a user's password during authentication. When using the default implementation, this query must take the user's username as a single parameter and return a single result with the user's password as the first column. If you require a solution that does not match this query structure, you can override doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken) or just getPasswordForUser(java.sql.Connection,String)

Parameters:
authenticationQuery - the query to use for authentication.
See Also:
DEFAULT_AUTHENTICATION_QUERY

setUserRolesQuery

public void setUserRolesQuery(String userRolesQuery)
Overrides the default query used to retrieve a user's roles during authorization. When using the default implementation, this query must take the user's username as a single parameter and return a row per role with a single column containing the role name. If you require a solution that does not match this query structure, you can override doGetAuthorizationInfo(PrincipalCollection) or just getRoleNamesForUser(java.sql.Connection,String)

Parameters:
userRolesQuery - the query to use for retrieving a user's roles.
See Also:
DEFAULT_USER_ROLES_QUERY

setPermissionsQuery

public void setPermissionsQuery(String permissionsQuery)
Overrides the default query used to retrieve a user's permissions during authorization. When using the default implementation, this query must take a role name as the single parameter and return a row per permission with three columns containing the fully qualified name of the permission class, the permission name, and the permission actions (in that order). If you require a solution that does not match this query structure, you can override doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection) or just getPermissions(java.sql.Connection,String,java.util.Collection)

Permissions are only retrieved if you set permissionsLookupEnabled to true. Otherwise, this query is ignored.

Parameters:
permissionsQuery - the query to use for retrieving permissions for a role.
See Also:
DEFAULT_PERMISSIONS_QUERY, setPermissionsLookupEnabled(boolean)

setPermissionsLookupEnabled

public void setPermissionsLookupEnabled(boolean permissionsLookupEnabled)
Enables lookup of permissions during authorization. The default is "false" - meaning that only roles are associated with a user. Set this to true in order to lookup roles and permissions.

Parameters:
permissionsLookupEnabled - true if permissions should be looked up during authorization, or false if only roles should be looked up.

doGetAuthenticationInfo

protected org.apache.shiro.authc.AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token)
                                                                     throws org.apache.shiro.authc.AuthenticationException
Specified by:
doGetAuthenticationInfo in class org.apache.shiro.realm.AuthenticatingRealm
Throws:
org.apache.shiro.authc.AuthenticationException

buildAuthenticationInfo

protected org.apache.shiro.authc.AuthenticationInfo buildAuthenticationInfo(String username,
                                                                            char[] password)

doGetAuthorizationInfo

protected org.apache.shiro.authz.AuthorizationInfo doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals)
This implementation of the interface expects the principals collection to return a String username keyed off of this realm's name

Specified by:
doGetAuthorizationInfo in class org.apache.shiro.realm.AuthorizingRealm
See Also:
AuthorizingRealm.getAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)

getRoleNamesForUser

protected Set<String> getRoleNamesForUser(Connection conn,
                                          String username)
                                   throws SQLException
Throws:
SQLException

getPermissions

protected Set<String> getPermissions(Connection conn,
                                     String username,
                                     Collection<String> roleNames)
                              throws SQLException
Throws:
SQLException


Copyright © 2011. All Rights Reserved.