Class JpaUserAndRoleProvider

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

public class JpaUserAndRoleProvider extends Object implements org.opencastproject.security.api.UserProvider, org.opencastproject.security.api.RoleProvider
Manages and locates users using JPA.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.opencastproject.db.DBSession
     
    protected org.opencastproject.db.DBSessionFactory
     
    protected javax.persistence.EntityManagerFactory
    The factory used to generate the entity manager
    static final String
    Encoding expected from all inputs
    Group provider
    protected Object
    A token to store in the miss cache
    static final String
     
    static final String
    The user provider name
    static final String
    Role constant used in JSON formatted users
    protected org.opencastproject.security.api.SecurityService
    The security service
    static final String
    Username constant used in JSON formatted users

    Fields inherited from interface org.opencastproject.security.api.UserProvider

    ALL_ORGANIZATIONS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    activate(org.osgi.service.component.ComponentContext cc)
    Callback for activation of this component.
    void
    addRole(org.opencastproject.security.impl.jpa.JpaRole jpaRole)
    Adds a role to the persistence
    void
    addUser(org.opencastproject.security.impl.jpa.JpaUser user)
    Adds a user to the persistence
    void
    addUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded)
    Adds a user to the persistence
    long
    Returns the number of all users in the database
    long
     
    void
    deleteUser(String username, String orgId)
    Delete the given user
    List<org.opencastproject.security.api.User>
    List all users with insecure password hashes
    Iterator<org.opencastproject.security.api.Role>
    findRoles(String query, org.opencastproject.security.api.Role.Target target, int offset, int limit)
    Iterator<org.opencastproject.security.api.User>
    findUsers(String query, int offset, int limit)
    Iterator<org.opencastproject.security.api.User>
     
     
    List<org.opencastproject.security.api.Role>
    Iterator<org.opencastproject.security.api.User>
     
    void
    invalidate(String userName)
     
    org.opencastproject.security.api.User
    loadUser(long userId, String organization)
    Loads a user from persistence
    org.opencastproject.security.api.User
    loadUser(String userName)
    org.opencastproject.security.api.User
    loadUser(String userName, String organization)
    Loads a user from persistence
    void
    setDBSessionFactory(org.opencastproject.db.DBSessionFactory dbSessionFactory)
     
    void
    setSecurityService(org.opencastproject.security.api.SecurityService securityService)
     
    org.opencastproject.security.api.User
    updateUser(org.opencastproject.security.impl.jpa.JpaUser user)
    Updates a user to the persistence
    org.opencastproject.security.api.User
    updateUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded)
    Updates a user to the persistence

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • PERSISTENCE_UNIT

      public static final String PERSISTENCE_UNIT
      See Also:
    • PROVIDER_NAME

      public static final String PROVIDER_NAME
      The user provider name
      See Also:
    • USERNAME

      public static final String USERNAME
      Username constant used in JSON formatted users
      See Also:
    • ROLES

      public static final String ROLES
      Role constant used in JSON formatted users
      See Also:
    • ENCODING

      public static final String ENCODING
      Encoding expected from all inputs
      See Also:
    • securityService

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

      protected JpaGroupRoleProvider groupRoleProvider
      Group provider
    • nullToken

      protected Object nullToken
      A token to store in the miss cache
    • 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
  • Constructor Details

    • JpaUserAndRoleProvider

      public JpaUserAndRoleProvider()
  • Method Details

    • setDBSessionFactory

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

      public void setSecurityService(org.opencastproject.security.api.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<org.opencastproject.security.api.Role> getRolesForUser(String userName)
      Specified by:
      getRolesForUser in interface org.opencastproject.security.api.RoleProvider
      See Also:
      • RoleProvider.getRolesForUser(String)
    • findUsers

      public Iterator<org.opencastproject.security.api.User> findUsers(String query, int offset, int limit)
      Specified by:
      findUsers in interface org.opencastproject.security.api.UserProvider
      See Also:
      • UserProvider.findUsers(String, int, int)
    • findUsers

      public Iterator<org.opencastproject.security.api.User> findUsers(Collection<String> userNames)
      Specified by:
      findUsers in interface org.opencastproject.security.api.UserProvider
    • findInsecurePasswordHashes

      public List<org.opencastproject.security.api.User> findInsecurePasswordHashes()
      List all users with insecure password hashes
    • 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)
    • loadUser

      public org.opencastproject.security.api.User loadUser(String userName)
      Specified by:
      loadUser in interface org.opencastproject.security.api.UserProvider
      See Also:
      • UserProvider.loadUser(java.lang.String)
    • getUsers

      public Iterator<org.opencastproject.security.api.User> getUsers()
      Specified by:
      getUsers in interface org.opencastproject.security.api.UserProvider
    • getOrganization

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

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

      public org.opencastproject.security.api.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 org.opencastproject.security.api.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(org.opencastproject.security.impl.jpa.JpaUser user) throws org.opencastproject.security.api.UnauthorizedException
      Adds a user to the persistence
      Parameters:
      user - the user to add
      Throws:
      org.opencastproject.security.api.UnauthorizedException - if the user is not allowed to create other user with the given roles
    • addUser

      public void addUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded) throws org.opencastproject.security.api.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:
      org.opencastproject.security.api.UnauthorizedException - if the user is not allowed to create other user with the given roles
    • updateUser

      public org.opencastproject.security.api.User updateUser(org.opencastproject.security.impl.jpa.JpaUser user) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.UnauthorizedException
      Updates a user to the persistence
      Parameters:
      user - the user to save
      Throws:
      org.opencastproject.util.NotFoundException
      org.opencastproject.security.api.UnauthorizedException - if the current user is not allowed to update user with the given roles
    • updateUser

      public org.opencastproject.security.api.User updateUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded) throws org.opencastproject.util.NotFoundException, org.opencastproject.security.api.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:
      org.opencastproject.util.NotFoundException
      org.opencastproject.security.api.UnauthorizedException - if the current user is not allowed to update user with the given roles
    • deleteUser

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

      public void addRole(org.opencastproject.security.impl.jpa.JpaRole jpaRole)
      Adds a role to the persistence
      Parameters:
      jpaRole - the role
    • getName

      public String getName()
      Specified by:
      getName in interface org.opencastproject.security.api.UserProvider
    • countUsers

      public long countUsers()
      Specified by:
      countUsers in interface org.opencastproject.security.api.UserProvider
    • 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)
      Specified by:
      invalidate in interface org.opencastproject.security.api.UserProvider