Class JdbcRealm

    • 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_SALTED_AUTHENTICATION_QUERY

        protected static final String DEFAULT_SALTED_AUTHENTICATION_QUERY
        The default query used to retrieve account data for the user when saltStyle is COLUMN.
        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
      • authenticationQuery

        protected String authenticationQuery
      • userRolesQuery

        protected String userRolesQuery
      • permissionsQuery

        protected String permissionsQuery
      • permissionsLookupEnabled

        protected boolean permissionsLookupEnabled
      • saltIsBase64Encoded

        protected boolean saltIsBase64Encoded
    • Constructor Detail

      • JdbcRealm

        public JdbcRealm()
    • Method Detail

      • setDataSource

        public void setDataSource(DataSource dataSource)
        Sets the datasource that should be used to retrieve connections used by this realm.
        Parameters:
        dataSource - the SQL data source.
      • 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
      • 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.
      • setSaltStyle

        public void setSaltStyle(JdbcRealm.SaltStyle saltStyle)
        Sets the salt style. See saltStyle.
        Parameters:
        saltStyle - new SaltStyle to set.
      • setSaltIsBase64Encoded

        public void setSaltIsBase64Encoded(boolean saltIsBase64Encoded)
        Makes it possible to switch off base64 encoding of password salt. The default value is true, ie. expect the salt from a string value in a database to be base64 encoded.
        Parameters:
        saltIsBase64Encoded - the saltIsBase64Encoded to set
      • doGetAuthenticationInfo

        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
                                                      throws AuthenticationException
        Description copied from class: AuthenticatingRealm
        Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given authentication token.

        For most datasources, this means just 'pulling' authentication data for an associated subject/user and nothing more and letting Shiro do the rest. But in some systems, this method could actually perform EIS specific log-in logic in addition to just retrieving data - it is up to the Realm implementation.

        A null return value means that no account could be associated with the specified token.
        Specified by:
        doGetAuthenticationInfo in class AuthenticatingRealm
        Parameters:
        token - the authentication token containing the user's principal and credentials.
        Returns:
        an AuthenticationInfo object containing account data resulting from the authentication ONLY if the lookup is successful (i.e. account exists and is valid, etc.)
        Throws:
        AuthenticationException - if there is an error acquiring data or performing realm-specific authentication logic for the specified token
      • getSaltForUser

        protected String getSaltForUser(String username)