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
FieldsModifier and TypeFieldDescriptionprotected org.opencastproject.db.DBSessionprotected org.opencastproject.db.DBSessionFactoryprotected javax.persistence.EntityManagerFactoryThe factory used to generate the entity managerstatic final StringEncoding expected from all inputsprotected JpaGroupRoleProviderGroup providerprotected ObjectA token to store in the miss cachestatic final Stringstatic final StringThe user provider namestatic final StringRole constant used in JSON formatted usersprotected org.opencastproject.security.api.SecurityServiceThe security servicestatic final StringUsername constant used in JSON formatted usersFields inherited from interface org.opencastproject.security.api.UserProvider
ALL_ORGANIZATIONS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) Callback for activation of this component.voidaddRole(org.opencastproject.security.impl.jpa.JpaRole jpaRole) Adds a role to the persistencevoidaddUser(org.opencastproject.security.impl.jpa.JpaUser user) Adds a user to the persistencevoidaddUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded) Adds a user to the persistencelongReturns the number of all users in the databaselongvoiddeleteUser(String username, String orgId) Delete the given userList<org.opencastproject.security.api.User> List all users with insecure password hashesIterator<org.opencastproject.security.api.Role> Iterator<org.opencastproject.security.api.User> Iterator<org.opencastproject.security.api.User> findUsers(Collection<String> userNames) getName()List<org.opencastproject.security.api.Role> getRolesForUser(String userName) Iterator<org.opencastproject.security.api.User> getUsers()voidinvalidate(String userName) org.opencastproject.security.api.UserLoads a user from persistenceorg.opencastproject.security.api.Userorg.opencastproject.security.api.UserLoads a user from persistencevoidsetDBSessionFactory(org.opencastproject.db.DBSessionFactory dbSessionFactory) voidsetSecurityService(org.opencastproject.security.api.SecurityService securityService) toString()org.opencastproject.security.api.UserupdateUser(org.opencastproject.security.impl.jpa.JpaUser user) Updates a user to the persistenceorg.opencastproject.security.api.UserupdateUser(org.opencastproject.security.impl.jpa.JpaUser user, boolean passwordEncoded) Updates a user to the persistence
-
Field Details
-
PERSISTENCE_UNIT
- See Also:
-
PROVIDER_NAME
The user provider name- See Also:
-
USERNAME
Username constant used in JSON formatted users- See Also:
-
ROLES
Role constant used in JSON formatted users- See Also:
-
ENCODING
Encoding expected from all inputs- See Also:
-
securityService
protected org.opencastproject.security.api.SecurityService securityServiceThe security service -
groupRoleProvider
Group provider -
nullToken
A token to store in the miss cache -
emf
protected javax.persistence.EntityManagerFactory emfThe 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
- Specified by:
getRolesForUserin interfaceorg.opencastproject.security.api.RoleProvider- See Also:
-
findUsers
public Iterator<org.opencastproject.security.api.User> findUsers(String query, int offset, int limit) - Specified by:
findUsersin interfaceorg.opencastproject.security.api.UserProvider- See Also:
-
findUsers
- Specified by:
findUsersin interfaceorg.opencastproject.security.api.UserProvider
-
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:
findRolesin interfaceorg.opencastproject.security.api.RoleProvider- See Also:
-
loadUser
- Specified by:
loadUserin interfaceorg.opencastproject.security.api.UserProvider- See Also:
-
getUsers
- Specified by:
getUsersin interfaceorg.opencastproject.security.api.UserProvider
-
getOrganization
- Specified by:
getOrganizationin interfaceorg.opencastproject.security.api.RoleProvider- Specified by:
getOrganizationin interfaceorg.opencastproject.security.api.UserProvider- See Also:
-
toString
-
loadUser
Loads a user from persistence- Parameters:
userName- the user nameorganization- the organization id- Returns:
- the loaded user or
nullif not found
-
loadUser
Loads a user from persistence- Parameters:
userId- the user's idorganization- the organization id- Returns:
- the loaded user or
nullif 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 addpasswordEncoded- 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.NotFoundExceptionorg.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 savepasswordEncoded- if the password is already encoded or should be encoded- Throws:
org.opencastproject.util.NotFoundExceptionorg.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 deleteorgId- the organization id- Throws:
org.opencastproject.util.NotFoundException- if the requested user is not existorg.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
- Specified by:
getNamein interfaceorg.opencastproject.security.api.UserProvider
-
countUsers
public long countUsers()- Specified by:
countUsersin interfaceorg.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
- Specified by:
invalidatein interfaceorg.opencastproject.security.api.UserProvider
-