Class MysqlDbAclProvider

java.lang.Object
com.illumon.iris.db.v2.permissions.MysqlDbAclProvider
All Implemented Interfaces:
com.fishlib.auth.AuthModule, DbAclWriter, Closeable, AutoCloseable
Direct Known Subclasses:
MysqlDbAclGuiHelper, UnauthenticatedPermissionFilterProviderMysqlImpl

public class MysqlDbAclProvider
extends Object
implements DbAclWriter, com.fishlib.auth.AuthModule, Closeable
Access to the MySQL ACL database. This class implements an AuthModule and DbAclWriter and serves as the basis for the Mysql permission filter provider, as well as the GUI helper. Anything that talks to the ACL database should use or extend it. The class is configured with properties: MysqlDbAclProvider.host - the mysql host to connect to MysqlDbAclProvider.db - the database containing our ACL tables MysqlDbAclProvider.user - username for MySQL connection MysqlDbAclProvider.ssl - SSL connectivity to MySQL (not yet tested in a production environmen5t) The MySQL password is stored as a base64 encoded string, either in a file (which takes precedence) referenced by: MysqlDbAclProvider.passwordFile or within a property itself MysqlDbAclProvider.pass
  • Field Details

  • Constructor Details

    • MysqlDbAclProvider

      public MysqlDbAclProvider​(com.fishlib.io.logger.Logger log)
    • MysqlDbAclProvider

      public MysqlDbAclProvider​(com.fishlib.io.logger.Logger log, boolean readOnly)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getFilterDetailsForUser

      public List<PermissionFilterProvider.FilterDetails> getFilterDetailsForUser​(com.fishlib.auth.UserContext userContext)
    • retrieveRowAcls

      public Collection<String> retrieveRowAcls​(String effectiveUser, String namespace, String tableName)
    • retrieveColumnAcls

      public Map<String,​List<com.fishlib.base.Pair<String,​String>>> retrieveColumnAcls​(String effectiveUser, String namespace, String tableName)
    • retrieveSystemAcls

      public Collection<String> retrieveSystemAcls​(String effectiveUser, String key)
      Retrieve the set of system ACLs that modify system behavior rather than table access.
      Parameters:
      effectiveUser - The user to get ACLs for
      key - The lookup value that applies
      Returns:
      A collection of strings representing the applicable ACLs.
    • canEditInputTable

      public boolean canEditInputTable​(String effectiveUser, String namespace, String tableName)
    • canAnyoneEditInputTable

      public boolean canAnyoneEditInputTable​(String namespace, String tableName)
    • getAccountsForUser

      public String[] getAccountsForUser​(String effectiveUser)
    • getAllUsers

      public String[] getAllUsers()
    • getAllGroups

      public String[] getAllGroups()
    • getAllStrategies

      public String[] getAllStrategies() throws SQLException
      Throws:
      SQLException
    • getAllAccounts

      public String[] getAllAccounts() throws SQLException
      Throws:
      SQLException
    • getAccountsForStrategy

      public String[] getAccountsForStrategy​(String strategy)
    • getStrategyForAccount

      public String[] getStrategyForAccount​(String account)
    • getAccountsForGroup

      public String[] getAccountsForGroup​(String group)
    • getStrategiesForGroup

      public String[] getStrategiesForGroup​(String group)
    • groupStrategyExists

      public boolean groupStrategyExists​(String groupName, String strategy)
    • userExists

      public boolean userExists​(String username)
      Specified by:
      userExists in interface com.fishlib.auth.AuthModule
    • isUserPassValid

      public boolean isUserPassValid​(String username, String password)
      Specified by:
      isUserPassValid in interface com.fishlib.auth.AuthModule
    • runFunctionWithSqlRetry

      protected <R> R runFunctionWithSqlRetry​(MysqlDbAclProvider.SQLFunction<R> function) throws SQLException
      Throws:
      SQLException
    • runProcedureWithSqlRetry

      protected void runProcedureWithSqlRetry​(MysqlDbAclProvider.SQLProcedure procedure) throws SQLException
      Throws:
      SQLException
    • getGroupsForUser

      public String[] getGroupsForUser​(String effectiveUser)
    • getStrategiesForUser

      public String[] getStrategiesForUser​(String effectiveUser)
    • getUsersForGroup

      public String[] getUsersForGroup​(String group)
    • addMembership

      public void addMembership​(String user, List<String> groups) throws SQLException
      Description copied from interface: DbAclWriter
      Adds a user to a list of groups If the user could not be added to all of the groups, a RuntimeException is thrown.
      Specified by:
      addMembership in interface DbAclWriter
      Parameters:
      user - the user to add to the groups
      groups - a list of groups to add the user to
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addUser

      public void addUser​(String user, String passwordHash) throws SQLException
      Description copied from interface: DbAclWriter
      Adds a user to the Iris system.
      Specified by:
      addUser in interface DbAclWriter
      Parameters:
      user - the user to add.
      passwordHash - the APR1 hash of the user's password. Ignored if the system is not configured to manage user authentication.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • changePassword

      public void changePassword​(String user, String passwordHash) throws SQLException
      Description copied from interface: DbAclWriter
      Changes the password for a user.
      Specified by:
      changePassword in interface DbAclWriter
      Parameters:
      user - the user to change a password for.
      passwordHash - the APR1 hash of the user's password.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • removeMembership

      public void removeMembership​(String user, List<String> groups) throws SQLException
      Description copied from interface: DbAclWriter
      Removes a user from a list of groups. It is possible that the user may be removed from some groups and not others. If the user could not be removed from all of the specified groups (e.g., because they are not a member of those groups), a runtime exception is thrown.
      Specified by:
      removeMembership in interface DbAclWriter
      Parameters:
      user - the user to remove from groups
      groups - a list of groups to remove the user from
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteGroup

      public void deleteGroup​(String group) throws SQLException
      Description copied from interface: DbAclWriter
      Deletes a group. The group is removed from all user to group mappings, all group to strategy mappings. All table ACLs and input table editors that reference the group are deleted.
      Specified by:
      deleteGroup in interface DbAclWriter
      Parameters:
      group - the group to delete.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteUser

      public void deleteUser​(String user) throws SQLException
      Description copied from interface: DbAclWriter
      The user is deleted. Deletes the user's group, followed by deleting any other user to group associations for the user. If managed authentication is enabled, also deletes the user's password.
      Specified by:
      deleteUser in interface DbAclWriter
      Parameters:
      user - the user to delete
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addGroupStrategy

      public void addGroupStrategy​(String group, String strategy) throws SQLException
      Description copied from interface: DbAclWriter
      For AccountFilterGenerator() there are two levels of mappings. Group to strategy and strategy to account. This will add a group to the intermediate "strategy".
      Specified by:
      addGroupStrategy in interface DbAclWriter
      Parameters:
      group - the group to map to a strategy
      strategy - the strategy that the group is added to
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteGroupStrategy

      public void deleteGroupStrategy​(String group, String strategy) throws SQLException
      Description copied from interface: DbAclWriter
      For AccountFilterGenerator() there are two levels of mappings. Group to strategy and strategy to account. This will remove a group from the intermediate "strategy".
      Specified by:
      deleteGroupStrategy in interface DbAclWriter
      Parameters:
      group - the group to remove a mapping to a strategy
      strategy - the strategy that the group is removed from
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addStrategyAccount

      public void addStrategyAccount​(String strategy, String account) throws SQLException
      Description copied from interface: DbAclWriter
      For AccountFilterGenerator() there are two levels of mappings. Group to strategy and strategy to account. This will add an account to the intermediate "strategy".
      Specified by:
      addStrategyAccount in interface DbAclWriter
      Parameters:
      strategy - the strategy that the account is added to
      account - the account to add to a strategy
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteStrategyAccount

      public void deleteStrategyAccount​(String strategy, String account) throws SQLException
      Description copied from interface: DbAclWriter
      For AccountFilterGenerator() there are two levels of mappings. Group to strategy and strategy to account. This will remove an account from the intermediate "strategy".
      Specified by:
      deleteStrategyAccount in interface DbAclWriter
      Parameters:
      strategy - the strategy that the account is added to
      account - the account to add to a strategy
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addAcl

      public int addAcl​(String group, String ns, String table, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Adds an ACL entry. No ACL entry may currently exist for the group and table in question.
      Specified by:
      addAcl in interface DbAclWriter
      Parameters:
      group - the group to add the entry for
      ns - the namespace to add the entry for ("*" for all namespaces)
      table - the namespace to add the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      acl - the ACL to add, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • updateAcl

      public int updateAcl​(String group, String ns, String table, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Changes an already existent ACL entry. An ACL entry must currently exist for the group and table in question.
      Specified by:
      updateAcl in interface DbAclWriter
      Parameters:
      group - the group to update the entry for
      ns - the namespace to update the entry for ("*" for all namespaces)
      table - the namespace to update the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      acl - the new ACL, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteAcls

      public void deleteAcls​(String group, String ns, String table) throws SQLException
      Description copied from interface: DbAclWriter
      Deletes an ACL entry for a group and table.
      Specified by:
      deleteAcls in interface DbAclWriter
      Parameters:
      group - the group to remove the entry for
      ns - the namespace to add the entry for ("*" for all namespaces)
      table - the namespace to add the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addColumnAcl

      public int addColumnAcl​(String group, String ns, String table, String columns, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Adds a Column ACL entry. No ACL entry may currently exist for the group and table in question.
      Specified by:
      addColumnAcl in interface DbAclWriter
      Parameters:
      group - the group to add the entry for
      ns - the namespace to add the entry for ("*" for all namespaces)
      table - the namespace to add the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      columns - the columns the ACL applies to
      acl - the ACL to add, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • updateColumnAcl

      public int updateColumnAcl​(String group, String ns, String table, String columns, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Changes an already existent Column ACL entry. An ACL entry must currently exist for the group, table, and column set in question.
      Specified by:
      updateColumnAcl in interface DbAclWriter
      Parameters:
      group - the group to update the entry for
      ns - the namespace to update the entry for ("*" for all namespaces)
      table - the namespace to update the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      columns - the columns the ACL applies to
      acl - the new ACL, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteColumnAcls

      public void deleteColumnAcls​(String group, String ns, String table, String columns) throws SQLException
      Description copied from interface: DbAclWriter
      Deletes a Column ACL entry for a group, table, and column set.
      Specified by:
      deleteColumnAcls in interface DbAclWriter
      Parameters:
      group - the group to remove the entry for
      ns - the namespace to add the entry for ("*" for all namespaces)
      table - the namespace to add the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      columns - the applicable columne set
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addSystemAcl

      public int addSystemAcl​(String group, String key, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Adds a system ACL entry. No ACL entry may currently exist for the group and key in question.
      Specified by:
      addSystemAcl in interface DbAclWriter
      Parameters:
      group - the group to add the entry for
      key - the key to add the entry for (wildcard not allowed)
      acl - the ACL to add, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • updateSystemAcl

      public int updateSystemAcl​(String group, String key, String acl) throws SQLException
      Description copied from interface: DbAclWriter
      Changes an already existent system ACL entry. An ACL entry must currently exist for the group and key in question.
      Specified by:
      updateSystemAcl in interface DbAclWriter
      Parameters:
      group - the group to update the entry for
      key - the key to update the entry for (no wildcard)
      acl - the new ACL, see http://wiki.illumon.com/Iris/Permissions#Table_Access_Control_Lists_.28ACLs.29
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteSystemAcls

      public void deleteSystemAcls​(String group, String key) throws SQLException
      Description copied from interface: DbAclWriter
      Deletes a system ACL entry for a group and key.
      Specified by:
      deleteSystemAcls in interface DbAclWriter
      Parameters:
      group - the group to remove the entry for
      key - the namespace to add the entry for (wildcard not allowed)
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • addInputTableEditor

      public int addInputTableEditor​(String group, String ns, String table, boolean canEdit) throws SQLException
      Description copied from interface: DbAclWriter
      Adds an entry to the ACL database for editing an input table.
      Specified by:
      addInputTableEditor in interface DbAclWriter
      Parameters:
      group - the group to add the entry for
      ns - the namespace to add the entry for ("*" for all namespaces)
      table - the namespace to add the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      canEdit - whether the table is editable for this group
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • updateInputTableEditor

      public int updateInputTableEditor​(String group, String ns, String table, boolean canEdit) throws SQLException
      Description copied from interface: DbAclWriter
      Updates an entry to the ACL database for editing an input table.
      Specified by:
      updateInputTableEditor in interface DbAclWriter
      Parameters:
      group - the group to update the entry for
      ns - the namespace to update the entry for ("*" for all namespaces)
      table - the namespace to update the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      canEdit - whether the table is editable for this group
      Returns:
      the number of rows within the ACL database that were modified.
      Throws:
      SQLException - if the underlying SQL operation could not be completed
    • deleteInputTableEditor

      public void deleteInputTableEditor​(String group, String ns, String table) throws SQLException
      Description copied from interface: DbAclWriter
      Deletes an entry to the ACL database for editing an input table.
      Specified by:
      deleteInputTableEditor in interface DbAclWriter
      Parameters:
      group - the group to delete the entry for
      ns - the namespace to delete the entry for ("*" for all namespaces)
      table - the namespace to delete the entry for ("*" for tables within a namespace, if ns is "*" table must also be "*")
      Throws:
      SQLException - if the underlying SQL operation could not be completed