Class JpaUserAndRoleProvider
java.lang.Object
org.opencastproject.userdirectory.JpaUserAndRoleProvider
- All Implemented Interfaces:
RoleProvider,UserProvider
Manages and locates users using JPA.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DBSessionprotected 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 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.voidAdds a role to the persistencevoidAdds a user to the persistencevoidAdds a user to the persistencelongReturns the number of all users in the databaselongReturns the number of users in the providervoiddeleteUser(String username, String orgId) Delete the given userList all users with insecure password hashesfindRoles(String query, Role.Target target, int offset, int limit) Return the found roles as an iterator.Return the found user's as an iterator.findUsers(Collection<String> userNames) Find a list of users by their user names Note that the default implementation of this might be slow, as it callsloadUseron every single user.getName()Gets the provider nameReturns the identifier for the organization that is associated with this user provider.getRolesForUser(String userName) Returns the roles for this user or an empty array if no roles are applicable.getUsers()Gets all known users.voidinvalidate(String userName) Discards any cached value for given user name.Loads a user from persistenceLoads a user by username, or returns null if this user is not known to this provider.Loads a user from persistencevoidsetDBSessionFactory(DBSessionFactory dbSessionFactory) voidsetSecurityService(SecurityService securityService) toString()updateUser(JpaUser user) Updates a user to the persistenceupdateUser(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
The 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
-
db
-
-
Constructor Details
-
JpaUserAndRoleProvider
public JpaUserAndRoleProvider()
-
-
Method Details
-
setDBSessionFactory
-
setSecurityService
- 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
Returns the roles for this user or an empty array if no roles are applicable.- Specified by:
getRolesForUserin interfaceRoleProvider- Parameters:
userName- the user id- Returns:
- the set of roles
- See Also:
-
findUsers
Return the found user's as an iterator.- Specified by:
findUsersin interfaceUserProvider- 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 offsetlimit- the limit. 0 means no limit- Returns:
- an iterator of user's
- See Also:
-
findUsers
Description copied from interface:UserProviderFind a list of users by their user names Note that the default implementation of this might be slow, as it callsloadUseron every single user.- Specified by:
findUsersin interfaceUserProvider- Parameters:
userNames- A list of user names- Returns:
- A list of resolved user objects
-
findInsecurePasswordHashes
List all users with insecure password hashes -
findRoles
Return the found roles as an iterator.- Specified by:
findRolesin interfaceRoleProvider- 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 offsetlimit- the limit. 0 means no limit- Returns:
- an iterator of role's
- See Also:
-
loadUser
Loads a user by username, or returns null if this user is not known to this provider.- Specified by:
loadUserin interfaceUserProvider- Parameters:
userName- the username- Returns:
- the user
- See Also:
-
getUsers
Description copied from interface:UserProviderGets all known users.- Specified by:
getUsersin interfaceUserProvider- Returns:
- the users
-
getOrganization
Returns the identifier for the organization that is associated with this user provider. If equal toUserProvider.ALL_ORGANIZATIONS, this provider will always be consulted, regardless of the organization.- Specified by:
getOrganizationin interfaceRoleProvider- Specified by:
getOrganizationin interfaceUserProvider- Returns:
- the defining organization
- 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
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
Adds a user to the persistence- Parameters:
user- the user to addpasswordEncoded- 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
Updates a user to the persistence- Parameters:
user- the user to save- Throws:
NotFoundExceptionUnauthorizedException- 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 savepasswordEncoded- if the password is already encoded or should be encoded- Throws:
NotFoundExceptionUnauthorizedException- 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 deleteorgId- the organization id- Throws:
NotFoundException- if the requested user is not existUnauthorizedException- if you havn't permissions to delete an admin user (only admins may do that)Exception
-
addRole
Adds a role to the persistence- Parameters:
jpaRole- the role
-
getName
Description copied from interface:UserProviderGets the provider name- Specified by:
getNamein interfaceUserProvider- Returns:
- the provider name
-
countUsers
public long countUsers()Description copied from interface:UserProviderReturns the number of users in the provider- Specified by:
countUsersin interfaceUserProvider- 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
Description copied from interface:UserProviderDiscards any cached value for given user name.- Specified by:
invalidatein interfaceUserProvider- Parameters:
userName- the user name
-