Class GroupInfo

java.lang.Object
com.iizix.server.db.GroupInfo

public class GroupInfo extends Object
Class holding information about user groups for the server.

The database table is created with:

 CREATE TABLE IZS.GROUPS (
  gid       BIGINT       NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
  name      VARCHAR(80)  NOT NULL,
  descr     VARCHAR(160) NOT NULL,
  disabled  BOOLEAN      NOT NULL DEFAULT FALSE,
  all_apps  BOOLEAN      NOT NULL DEFAULT FALSE,
  UNIQUE (name)
 );
 

Author:
Christopher Mindus
  • Field Details

    • DEFAULT_GROUP_NAME

      public static final String DEFAULT_GROUP_NAME
      The group name of the Default normal user group: "Default".
      See Also:
    • ADMIN_GROUP_NAME

      public static final String ADMIN_GROUP_NAME
      The group name of the Administrators group: "Administrators".
      See Also:
    • gid

      public final long gid
      The unique group ID.
  • Method Details

    • loadGroups

      public static GroupInfo[] loadGroups(Connection conn, boolean returnGroupInfoArray) throws SQLException
      Loads all the groups. Previous groups are cleared.
      Parameters:
      conn - The database connection.
      returnGroupInfoArray - Flag to return the array of all groups.
      Returns:
      The array of all groups if returnGroupInfoArray is true, null otherwise.
      Throws:
      SQLException - For SQL errors.
    • getGroup

      public static GroupInfo getGroup(Connection conn, String name) throws SQLException
      Gets the group from the database and caches the entry.
      Parameters:
      conn - The database connection.
      name - The group name, wildcard "*" means all groups and will fail this call.
      Throws:
      SQLException - For SQL errors.
      NotFoundException - If the name is "*" or not found.
    • getGroup

      public static GroupInfo getGroup(String name, boolean reload) throws SQLException
      Gets the group with the specified name.
      Parameters:
      name - The group name, wildcard "*" means all groups and will fail this call.
      reload - Flag to reload the group informations from the database.
      Returns:
      The group found, or null if not found.
      Throws:
      SQLException - For SQL errors.
      NotFoundException - If the name is "*".
    • getAllGroups

      public static GroupInfo[] getAllGroups(boolean reload) throws SQLException
      Gets all the groups from the database.
      Parameters:
      reload - Flag to reload the group informations from the database.
      Returns:
      The array of group informations.
      Throws:
      SQLException - For SQL errors.
    • getAllGroups

      public static GroupInfo[] getAllGroups(Connection conn) throws SQLException
      Gets all the groups from the database.
      Parameters:
      conn - The JDBC connection.
      Returns:
      The array of group informations.
      Throws:
      SQLException - For SQL errors.
    • getGroups

      public static GroupInfo[] getGroups(String[] names, boolean reload) throws NotFoundException, SQLException
      Gets the groups for the names.
      Parameters:
      names - The group names to find. The wildcard "*" group name means all groups.
      reload - Flag to reload the group informations from the database.
      Returns:
      The array of group informations.
      Throws:
      NotFoundException - If a group is not found.
      SQLException - For SQL errors.
    • getGroups

      public static GroupInfo[] getGroups(Connection conn, String[] names) throws NotFoundException, SQLException
      Gets the groups for the names from the database.
      Parameters:
      names - The group names to find. The wildcard "*" group name means all groups.
      Returns:
      The array of group informations.
      Throws:
      NotFoundException - If a group is not found.
      SQLException - For SQL errors.
    • getGroups

      public static GroupInfo[] getGroups(long[] groupIDs, boolean reload) throws NotFoundException, SQLException
      Gets the groups for the group IDs.
      Parameters:
      groupIDs - The groupIDs to find.
      reload - Flag to reload the group informations from the database.
      Returns:
      The array of group informations.
      Throws:
      NotFoundException - If a group is not found.
      SQLException - For SQL errors.
    • createGroup

      public static GroupInfo createGroup(String name, String descr, boolean isDisabled, boolean areAllAppsAllowed) throws SQLException
      Creates a new group with the specified information.

      Note that the name AND the lower case name of the group should not exist, otherwise you will get an SQLException of a duplicate entry.

      Parameters:
      name - The group name (min 3 characters, max 80 characters).
      descr - The group description (max 160 characters, cannot be null).
      isDisabled - The group is initially disabled if true, enabled if false.
      areAllAppsAllowed - Enable group to access all apps (be careful with this one, it is primarily used for Administrator groups).
      Returns:
      The GroupInfo of the new group created.
      Throws:
      IllegalArgumentException - If name or descr lengths are invalid.
      SQLException - For SQL errors.
      NullPointerException - If name or descr parameters are null.
    • createGroup

      public static GroupInfo createGroup(Connection conn, String name, String descr, boolean isDisabled, boolean areAllAppsAllowed) throws SQLException
      Creates a new group with the specified information.

      Note that the name AND the lower case name of the group should not exist, otherwise you will get an SQLException of a duplicate entry.

      Parameters:
      conn - The JDBC connection.
      name - The group name (min 3 characters, max 80 characters).
      descr - The group description (max 160 characters, cannot be null).
      isDisabled - The group is initially disabled if true, enabled if false.
      areAllAppsAllowed - Enable group to access all apps (be careful with this one, it is primarily used for Administrator groups).
      Returns:
      The GroupInfo of the new group created.
      Throws:
      IllegalArgumentException - If name or descr lengths are invalid.
      SQLException - For SQL errors.
      NullPointerException - If conn, name or descr parameters are null.
    • getName

      public String getName()
      Gets the name of the group.
      Returns:
      The user name.
    • getDescription

      public String getDescription()
      Gets the description of the group.
      Returns:
      A descriptive text.
    • isDisabled

      public boolean isDisabled()
      Returns if the group is enabled or disabled.
      Returns:
      true if disabled, false for enabled (default).
    • areAllAppsAllowed

      public boolean areAllAppsAllowed()
      Returns if the group allows users to run all apps without further app checking.
      Returns:
      true to allow all apps (typically for administrators), false to perform default checking with the defined apps.
    • toString

      public String toString()
      Outputs a debug string.
      Overrides:
      toString in class Object
      Returns:
      String for debugging.
    • refreshFromDB

      public void refreshFromDB() throws SQLException
      Refreshes the DB information for the group.
      Throws:
      SQLException - For SQL errors.
    • setInformation

      public boolean setInformation(String name, String descr, Boolean isDisabled, Boolean areAllAppsAllowed) throws NotFoundException, SQLException
      Updates the information of the group.
      Parameters:
      name - The new name (min 3 characters, max 80 characters), null for same name.
      descr - The new description (max 160 characters), null for same description.
      isDisabled - Flag for group disabled, null for no change.
      areAllAppsAllowed - Flag for all apps are allowed, null for no change.
      Throws:
      IllegalArgumentException - If name or descr lengths are invalid.
      NotFoundException - If the group is not found (has been removed).
      SQLException - For SQL errors.
    • deleteGroup

      public boolean deleteGroup(Connection conn) throws SQLException
      Deletes the group from the database. No commit operation is done on the connection if you wish to perform multiple operations as a unit of operation.
      Parameters:
      conn - The SQL connection.
      Returns:
      true if successfully deleted, false if already deleted.
      Throws:
      SQLException - For SQL errors.
    • deleteGroup

      public boolean deleteGroup() throws SQLException
      Deletes the group from the database. If you wish to delete multiple groups, use the deleteGroup(Connection) call instead and grab a connection from the pool.
      Returns:
      true if successfully deleted, false if already deleted.
      Throws:
      SQLException - For SQL errors.