Class UserControl


@Service
public class UserControl
extends DatabaseAwareBean
User and group administration DAO.
Author:
Donal Fellows
  • Constructor Details

  • Method Details

    • listUsers

      public List<UserRecord> listUsers()
      List the users in the database.
      Returns:
      List of users. Only UserRecord.userId and UserRecord.userName fields are inflated.
    • listUsers

      public List<UserRecord> listUsers​(boolean internal)
      List the users of a type in the database.
      Parameters:
      internal - Whether to get the internal users. If not, get the OpenID users.
      Returns:
      List of users. Only UserRecord.userId and UserRecord.userName fields are inflated.
    • listUsers

      public Map<String,​URI> listUsers​(Function<UserRecord,​URI> uriMapper)
      List the users in the database.
      Parameters:
      uriMapper - How to construct a URL for the user.
      Returns:
      Map of users to URLs.
    • listUsers

      public Map<String,​URI> listUsers​(boolean internal, Function<UserRecord,​URI> uriMapper)
      List the users of a type in the database.
      Parameters:
      internal - Whether to get the internal users. If not, get the OpenID users.
      uriMapper - How to construct a URL for the user.
      Returns:
      Map of users to URLs.
    • createUser

      public Optional<UserRecord> createUser​(UserRecord user, Function<MemberRecord,​URI> urlGen)
      Create a user.
      Parameters:
      user - The description of the user to create.
      urlGen - How to construct the URL for a group membership in the response. If null, the memberships will be omitted.
      Returns:
      A description of the created user, or Optional.empty() if the user exists already.
    • getUser

      public Optional<UserRecord> getUser​(int id, Function<MemberRecord,​URI> urlGen)
      Get a description of a user.
      Parameters:
      id - The ID of the user.
      urlGen - How to construct the URL for a group membership in the response. If null, the memberships will be omitted.
      Returns:
      A description of the user, or Optional.empty() if the user doesn't exist.
    • getUser

      public Optional<UserRecord> getUser​(String user, Function<MemberRecord,​URI> urlGen)
      Get a description of a user.
      Parameters:
      user - The name of the user.
      urlGen - How to construct the URL for a group membership in the response. If null, the memberships will be omitted.
      Returns:
      A description of the user, or Optional.empty() if the user doesn't exist.
    • updateUser

      public Optional<UserRecord> updateUser​(int id, UserRecord user, String adminUser, Function<MemberRecord,​URI> urlGen)
      Updates a user.
      Parameters:
      id - The ID of the user
      user - The description of what to update.
      adminUser - The name of the current user doing this call. Used to prohibit any admin from doing major damage to themselves.
      urlGen - How to construct the URL for a group membership in the response. If null, the memberships will be omitted.
      Returns:
      The updated user
    • deleteUser

      public Optional<String> deleteUser​(int id, String adminUser)
      Deletes a user.
      Parameters:
      id - The ID of the user to delete.
      adminUser - The name of the current user doing this call. Used to prohibit anyone from deleting themselves.
      Returns:
      The name of the deleted user if things succeeded, or Optional.empty() on failure.
    • getUser

      public PasswordChangeRecord getUser​(Principal principal) throws AuthenticationException
      Get a model for updating the local password of the current user.
      Parameters:
      principal - The current user
      Returns:
      User model object. Password fields are unfilled.
      Throws:
      AuthenticationException - If the user cannot change their password here for some reason.
    • updateUser

      public PasswordChangeRecord updateUser​(Principal principal, PasswordChangeRecord user) throws AuthenticationException
      Update the local password of the current user based on a filled out model previously provided.
      Parameters:
      principal - The current user
      user - Valid user model object with password fields filled.
      Returns:
      Replacement user model object. Password fields are unfilled.
      Throws:
      AuthenticationException - If the user cannot change their password here for some reason.
    • listGroups

      public List<GroupRecord> listGroups()
      List the groups in the database. Does not include membership data.
      Returns:
      List of groups.
    • listGroups

      public List<GroupRecord> listGroups​(GroupRecord.GroupType type)
      List the groups of a type in the database. Does not include membership data.
      Parameters:
      type - The type of groups to get.
      Returns:
      List of groups.
    • listGroups

      public Map<String,​URI> listGroups​(Function<GroupRecord,​URI> uriMapper)
      List the groups in the database.
      Parameters:
      uriMapper - How to construct a URL for the group.
      Returns:
      Map of group names to URLs.
    • listGroups

      public Map<String,​URI> listGroups​(GroupRecord.GroupType type, Function<GroupRecord,​URI> uriMapper)
      List the groups of a type in the database.
      Parameters:
      type - The type of groups to get.
      uriMapper - How to construct a URL for the group.
      Returns:
      Map of group names to URLs.
    • getGroup

      public Optional<GroupRecord> getGroup​(int id, Function<MemberRecord,​URI> urlGen)
      Get a description of a group. Includes group membership data.
      Parameters:
      id - The ID of the group.
      urlGen - How to construct the URL for a group membership. If null, the memberships will be omitted.
      Returns:
      A description of the group, or Optional.empty() if the group doesn't exist.
    • getGroup

      public Optional<GroupRecord> getGroup​(String name, Function<MemberRecord,​URI> urlGen)
      Get a description of a group. Includes group membership data.
      Parameters:
      name - The name of the group.
      urlGen - How to construct the URL for a group membership. If null, the memberships will be omitted.
      Returns:
      A description of the group, or Optional.empty() if the group doesn't exist.
    • createGroup

      public Optional<GroupRecord> createGroup​(GroupRecord groupTemplate, GroupRecord.GroupType type)
      Create a group from a supplied group.
      Parameters:
      groupTemplate - Description of what the group should look like. Only the groupName and the quota properties are used.
      type - What type of group is this; internal groups hold internal users, external groups hold external users and come in two kinds.
      Returns:
      The full group description, assuming all went well.
    • updateGroup

      public Optional<GroupRecord> updateGroup​(int id, GroupRecord group, Function<MemberRecord,​URI> urlGen)
      Update a group from a supplied description.
      Parameters:
      id - The ID of the group to update
      group - The template of what the group is to be updated to.
      urlGen - How to construct the URL for a group membership in the response. If null, the memberships will be omitted.
      Returns:
      A description of the updated group, or Optional.empty() if the group doesn't exist.
    • deleteGroup

      public Optional<String> deleteGroup​(int groupId)
      Delete a group. This removes all users from that group automatically.
      Parameters:
      groupId - The ID of the group to delete.
      Returns:
      The deleted group name on success; Optional.empty() on failure.
    • addUserToGroup

      public Optional<MemberRecord> addUserToGroup​(UserRecord user, GroupRecord group)
      Adds a user to a group.
      Parameters:
      user - What user to add.
      group - What group to add to.
      Returns:
      Description of the created membership, or empty if adding failed. Note that this doesn't set the URLs.
    • removeUserFromGroup

      public boolean removeUserFromGroup​(UserRecord user, GroupRecord group)
      Removes a user from a group.
      Parameters:
      user - What user to remove.
      group - What group to remove from.
      Returns:
      Whether the removing succeeded.
    • removeMembershipOfGroup

      public boolean removeMembershipOfGroup​(MemberRecord member, GroupRecord group)
      Removes a user from a group.
      Parameters:
      member - What membership to remove.
      group - What group to remove from.
      Returns:
      Whether the removing succeeded.
    • describeMembership

      public Optional<MemberRecord> describeMembership​(int memberId, Function<MemberRecord,​URI> groupUriGen, Function<MemberRecord,​URI> userUriGen)
      Describe the details of a particular group membership.
      Parameters:
      memberId - The ID of the membership record.
      groupUriGen - How to generate the URL for the group. Ignored if null.
      userUriGen - How to generate the URL for the user. Ignored if null.
      Returns:
      The membership description