Class JpaGroupRoleProvider

java.lang.Object
org.opencastproject.userdirectory.JpaGroupRoleProvider
All Implemented Interfaces:
org.opencastproject.security.api.GroupProvider, org.opencastproject.security.api.RoleProvider, AAIRoleProvider, GroupRoleProvider

public class JpaGroupRoleProvider extends Object implements AAIRoleProvider, org.opencastproject.security.api.GroupProvider, GroupRoleProvider
Manages and locates users using JPA.
  • Field Details

    • PERSISTENCE_UNIT

      public static final String PERSISTENCE_UNIT
      The JPA persistence unit name
      See Also:
    • securityService

      protected org.opencastproject.security.api.SecurityService securityService
      The security service
    • emf

      protected javax.persistence.EntityManagerFactory emf
      The factory used to generate the entity manager
    • dbSessionFactory

      protected org.opencastproject.db.DBSessionFactory dbSessionFactory
    • db

      protected org.opencastproject.db.DBSession db
    • organizationDirectoryService

      protected org.opencastproject.security.api.OrganizationDirectoryService organizationDirectoryService
      The organization directory service
    • userDirectoryService

      protected org.opencastproject.security.api.UserDirectoryService userDirectoryService
      The user directory service
  • Constructor Details

    • JpaGroupRoleProvider

      public JpaGroupRoleProvider()
  • Method Details

    • setEntityManagerFactory

      public void setEntityManagerFactory(javax.persistence.EntityManagerFactory emf)
      OSGi DI
    • setDBSessionFactory

      public void setDBSessionFactory(org.opencastproject.db.DBSessionFactory dbSessionFactory)
    • setUserDirectoryService

      public void setUserDirectoryService(org.opencastproject.security.api.UserDirectoryService userDirectoryService)
      Sets the user directory service
      Parameters:
      userDirectoryService - the userDirectoryService to set
    • setSecurityService

      public void setSecurityService(org.opencastproject.security.api.SecurityService securityService)
      Parameters:
      securityService - the securityService to set
    • setOrganizationDirectoryService

      public void setOrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService organizationDirectoryService)
      Parameters:
      organizationDirectoryService - the organizationDirectoryService to set
    • activate

      public void activate(org.osgi.service.component.ComponentContext cc)
      Callback for activation of this component.
      Parameters:
      cc - the component context
    • getRoles

      public Iterator<org.opencastproject.security.api.Role> getRoles()
      Return the roles
      Specified by:
      getRoles in interface AAIRoleProvider
      Returns:
      the roles
      See Also:
    • getRolesForUser

      public List<org.opencastproject.security.api.Role> getRolesForUser(String userName)
      Specified by:
      getRolesForUser in interface GroupRoleProvider
      Specified by:
      getRolesForUser in interface org.opencastproject.security.api.RoleProvider
      See Also:
      • RoleProvider.getRolesForUser(String)
    • getRolesForGroup

      public List<org.opencastproject.security.api.Role> getRolesForGroup(String groupName)
      Specified by:
      getRolesForGroup in interface org.opencastproject.security.api.GroupProvider
      Specified by:
      getRolesForGroup in interface GroupRoleProvider
      See Also:
      • RoleProvider.getRolesForUser(String)
    • getOrganization

      public String getOrganization()
      Specified by:
      getOrganization in interface GroupRoleProvider
      Specified by:
      getOrganization in interface org.opencastproject.security.api.RoleProvider
      See Also:
      • RoleProvider.getOrganization()
    • findRoles

      public Iterator<org.opencastproject.security.api.Role> findRoles(String query, org.opencastproject.security.api.Role.Target target, int offset, int limit)
      Specified by:
      findRoles in interface org.opencastproject.security.api.RoleProvider
      See Also:
      • RoleProvider.findRoles(String, Role.Target, int, int)
    • updateGroupMembershipFromRoles

      public void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList)
      Updates a user's group membership
      Specified by:
      updateGroupMembershipFromRoles in interface GroupRoleProvider
      Parameters:
      userName - the username
      orgId - the user's organization
      roleList - the list of group role names
    • updateGroupMembershipFromRoles

      public void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList, String prefix)
      Updates a user's group membership
      Parameters:
      userName - the username
      orgId - the user's organization
      roleList - the list of group role names
      prefix - handle only roles with given prefix
    • removeMemberFromAllGroups

      public void removeMemberFromAllGroups(String userName, String orgId)
      Removes a user from all groups
      Parameters:
      userName - the username
      orgId - the user's organization
    • loadGroup

      public org.opencastproject.security.impl.jpa.JpaGroup loadGroup(String groupId, String orgId)
      Loads a group from persistence
      Parameters:
      groupId - the group id
      orgId - the organization id
      Returns:
      the loaded group or null if not found
    • getGroup

      public org.opencastproject.security.impl.jpa.JpaGroup getGroup(String groupId)
      Get group.
      Parameters:
      groupId -
      Returns:
      the group
    • addGroup

      public void addGroup(org.opencastproject.security.impl.jpa.JpaGroup group) throws org.opencastproject.security.api.UnauthorizedException
      Adds or updates a group to the persistence.
      Specified by:
      addGroup in interface GroupRoleProvider
      Parameters:
      group - the group to add
      Throws:
      org.opencastproject.security.api.UnauthorizedException
    • getGroups

      public Iterator<org.opencastproject.security.api.Group> getGroups()
      Description copied from interface: GroupRoleProvider
      Getting all groups
      Specified by:
      getGroups in interface GroupRoleProvider
      Returns:
      Iterator<Group> persisted groups
    • getGroups

      public org.opencastproject.security.api.JaxbGroupList getGroups(int limit, int offset) throws IOException
      Returns a XML representation of the list of groups available the current user's organization.
      Parameters:
      limit - the int amount to limit the results
      offset - the offset to start this result set at
      Returns:
      the JaxbGroupList of results
      Throws:
      IOException - if unexpected IO exception occurs
    • getGroups

      public List<org.opencastproject.security.impl.jpa.JpaGroup> getGroups(Optional<Integer> limit, Optional<Integer> offset, Optional<String> nameFilter, Optional<String> textFilter, ArrayList<org.opencastproject.util.requests.SortCriterion> sortCriteria)
      Get groups by the defined filter and sorting criteria.
      Parameters:
      limit - how many groups to get (optional)
      offset - where to start the list for pagination (optional)
      nameFilter - filter by group name (optional)
      textFilter - fulltext filter (optional)
      sortCriteria - the sorting criteria
      Returns:
      a list of groups
    • countTotalGroups

      public long countTotalGroups(Optional<String> nameFilter, Optional<String> textFilter)
      Count groups that fit the filter criteria in total.
      Parameters:
      nameFilter - filter by group name (optional)
      textFilter - fulltext filter (optional)
      Returns:
      a list of groups
    • removeGroup

      public void removeGroup(String groupId) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.UnauthorizedException, Exception
      Remove a group by id
      Parameters:
      groupId - the id of the group to remove
      Throws:
      Exception - unexpected error occurred
      org.opencastproject.security.api.UnauthorizedException - user is not authorized to remove this group
      org.opencastproject.util.NotFoundException - the group was not found
    • createGroup

      public void createGroup(String name, String description, String roles, String users) throws IllegalArgumentException, org.opencastproject.security.api.UnauthorizedException, ConflictException
      Create a new group
      Parameters:
      name - the name of the group
      description - a description of the group
      roles - the roles of the group
      users - the users in the group
      Throws:
      IllegalArgumentException - if missing or bad parameters
      org.opencastproject.security.api.UnauthorizedException - if user does not have rights to create group
      ConflictException - if group already exists
    • removeMemberFromGroup

      public boolean removeMemberFromGroup(String groupId, String member) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.UnauthorizedException
      Remove member from group.
      Parameters:
      groupId -
      member -
      Returns:
      true if we updated the group, false otherwise
      Throws:
      org.opencastproject.util.NotFoundException
      org.opencastproject.security.api.UnauthorizedException
    • addMemberToGroup

      public boolean addMemberToGroup(String groupId, String member) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.UnauthorizedException
      Add member to group.
      Parameters:
      groupId -
      member -
      Returns:
      true if we updated the group, false otherwise
      Throws:
      org.opencastproject.util.NotFoundException
      org.opencastproject.security.api.UnauthorizedException
    • updateGroup

      public void updateGroup(String groupId, String name, String description, String roles, String users) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.UnauthorizedException
      Update a group
      Specified by:
      updateGroup in interface GroupRoleProvider
      Parameters:
      groupId - the id of the group to update
      name - the name to update
      description - the description to update
      roles - the roles to update
      users - the users to update
      Throws:
      org.opencastproject.util.NotFoundException - if the group is not found
      org.opencastproject.security.api.UnauthorizedException - if the user does not have rights to update the group
      See Also: