Class JpaUserAndRoleProvider

java.lang.Object
org.opencastproject.userdirectory.JpaUserAndRoleProvider
All Implemented Interfaces:
RoleProvider, UserProvider

public class JpaUserAndRoleProvider extends Object implements UserProvider, RoleProvider
Manages and locates users using JPA.
  • Field Details

  • Constructor Details

    • JpaUserAndRoleProvider

      public JpaUserAndRoleProvider()
  • Method Details

    • setDBSessionFactory

      public void setDBSessionFactory(DBSessionFactory dbSessionFactory)
    • setSecurityService

      public void setSecurityService(SecurityService securityService)
      Parameters:
      securityService - the securityService to set
    • activate

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

      public List<Role> getRolesForUser(String userName)
      Returns the roles for this user or an empty array if no roles are applicable.
      Specified by:
      getRolesForUser in interface RoleProvider
      Parameters:
      userName - the user id
      Returns:
      the set of roles
      See Also:
    • findUsers

      public Iterator<User> findUsers(String query, int offset, int limit)
      Return the found user's as an iterator.
      Specified by:
      findUsers in interface UserProvider
      Parameters:
      query - the query. Use the wildcards "_" to match any single character and "%" to match an arbitrary number of characters (including zero characters).
      offset - the offset
      limit - the limit. 0 means no limit
      Returns:
      an iterator of user's
      See Also:
    • findUsers

      public Iterator<User> findUsers(Collection<String> userNames)
      Description copied from interface: UserProvider
      Find a list of users by their user names Note that the default implementation of this might be slow, as it calls loadUser on every single user.
      Specified by:
      findUsers in interface UserProvider
      Parameters:
      userNames - A list of user names
      Returns:
      A list of resolved user objects
    • findInsecurePasswordHashes

      public List<User> findInsecurePasswordHashes()
      List all users with insecure password hashes
    • findRoles

      public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit)
      Return the found roles as an iterator.
      Specified by:
      findRoles in interface RoleProvider
      Parameters:
      query - the query. Use the wildcards "_" to match any single character and "%" to match an arbitrary number of characters (including zero characters).
      offset - the offset
      limit - the limit. 0 means no limit
      Returns:
      an iterator of role's
      See Also:
    • loadUser

      public User loadUser(String userName)
      Loads a user by username, or returns null if this user is not known to this provider.
      Specified by:
      loadUser in interface UserProvider
      Parameters:
      userName - the username
      Returns:
      the user
      See Also:
    • getUsers

      public Iterator<User> getUsers()
      Description copied from interface: UserProvider
      Gets all known users.
      Specified by:
      getUsers in interface UserProvider
      Returns:
      the users
    • getOrganization

      public String getOrganization()
      Returns the identifier for the organization that is associated with this user provider. If equal to UserProvider.ALL_ORGANIZATIONS, this provider will always be consulted, regardless of the organization.
      Specified by:
      getOrganization in interface RoleProvider
      Specified by:
      getOrganization in interface UserProvider
      Returns:
      the defining organization
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • loadUser

      public User loadUser(String userName, String organization)
      Loads a user from persistence
      Parameters:
      userName - the user name
      organization - the organization id
      Returns:
      the loaded user or null if not found
    • loadUser

      public User loadUser(long userId, String organization)
      Loads a user from persistence
      Parameters:
      userId - the user's id
      organization - the organization id
      Returns:
      the loaded user or null if not found
    • addUser

      public void addUser(JpaUser user) throws UnauthorizedException
      Adds a user to the persistence
      Parameters:
      user - the user to add
      Throws:
      UnauthorizedException - if the user is not allowed to create other user with the given roles
    • addUser

      public void addUser(JpaUser user, boolean passwordEncoded) throws UnauthorizedException
      Adds a user to the persistence
      Parameters:
      user - the user to add
      passwordEncoded - if the password is already encoded or should be encoded
      Throws:
      UnauthorizedException - if the user is not allowed to create other user with the given roles
    • updateUser

      public User updateUser(JpaUser user) throws NotFoundException, UnauthorizedException
      Updates a user to the persistence
      Parameters:
      user - the user to save
      Throws:
      NotFoundException
      UnauthorizedException - if the current user is not allowed to update user with the given roles
    • updateUser

      public User updateUser(JpaUser user, boolean passwordEncoded) throws NotFoundException, UnauthorizedException
      Updates a user to the persistence
      Parameters:
      user - the user to save
      passwordEncoded - if the password is already encoded or should be encoded
      Throws:
      NotFoundException
      UnauthorizedException - if the current user is not allowed to update user with the given roles
    • deleteUser

      public void deleteUser(String username, String orgId) throws NotFoundException, UnauthorizedException, Exception
      Delete the given user
      Parameters:
      username - the name of the user to delete
      orgId - the organization id
      Throws:
      NotFoundException - if the requested user is not exist
      UnauthorizedException - if you havn't permissions to delete an admin user (only admins may do that)
      Exception
    • addRole

      public void addRole(JpaRole jpaRole)
      Adds a role to the persistence
      Parameters:
      jpaRole - the role
    • getName

      public String getName()
      Description copied from interface: UserProvider
      Gets the provider name
      Specified by:
      getName in interface UserProvider
      Returns:
      the provider name
    • countUsers

      public long countUsers()
      Description copied from interface: UserProvider
      Returns the number of users in the provider
      Specified by:
      countUsers in interface UserProvider
      Returns:
      the count of users in the provider
    • countAllUsers

      public long countAllUsers()
      Returns the number of all users in the database
      Returns:
      the count of all users in the database
    • invalidate

      public void invalidate(String userName)
      Description copied from interface: UserProvider
      Discards any cached value for given user name.
      Specified by:
      invalidate in interface UserProvider
      Parameters:
      userName - the user name