Class JpaGroupRoleProvider
java.lang.Object
org.opencastproject.userdirectory.JpaGroupRoleProvider
- All Implemented Interfaces:
GroupProvider,RoleProvider,AAIRoleProvider,GroupRoleProvider
public class JpaGroupRoleProvider
extends Object
implements AAIRoleProvider, GroupProvider, GroupRoleProvider
Manages and locates users using JPA.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DBSessionprotected DBSessionFactoryprotected javax.persistence.EntityManagerFactoryThe factory used to generate the entity managerprotected OrganizationDirectoryServiceThe organization directory servicestatic final StringThe JPA persistence unit nameprotected SecurityServiceThe security serviceprotected UserDirectoryServiceThe user directory service -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) Callback for activation of this component.voidAdds or updates a group to the persistence.booleanaddMemberToGroup(String groupId, String member) Add member to group.longcountTotalGroups(Optional<String> nameFilter, Optional<String> textFilter) Count groups that fit the filter criteria in total.voidcreateGroup(String name, String description, String roles, String users) Create a new groupfindRoles(String query, Role.Target target, int offset, int limit) Return the found roles as an iterator.Get group.Getting all groupsgetGroups(int limit, int offset) Returns a XML representation of the list of groups available the current user's organization.getGroups(Optional<Integer> limit, Optional<Integer> offset, Optional<String> nameFilter, Optional<String> textFilter, ArrayList<SortCriterion> sortCriteria) Get groups by the defined filter and sorting criteria.Returns the identifier for the organization that is defining this set of roles.getRoles()Return the rolesgetRolesForGroup(String groupName) Returns the roles for this group or an empty array if no roles are applicable.getRolesForUser(String userName) Returns the roles for this user or an empty array if no roles are applicable.Loads a group from persistencevoidremoveGroup(String groupId) Remove a group by idvoidremoveMemberFromAllGroups(String userName, String orgId) Removes a user from all groupsbooleanremoveMemberFromGroup(String groupId, String member) Remove member from group.voidsetDBSessionFactory(DBSessionFactory dbSessionFactory) voidsetEntityManagerFactory(javax.persistence.EntityManagerFactory emf) OSGi DIvoidsetOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService) voidsetSecurityService(SecurityService securityService) voidsetUserDirectoryService(UserDirectoryService userDirectoryService) Sets the user directory servicevoidUpdate a groupvoidupdateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList) Updates a user's group membershipvoidUpdates a user's group membership
-
Field Details
-
PERSISTENCE_UNIT
The JPA persistence unit name- See Also:
-
securityService
The security service -
emf
protected javax.persistence.EntityManagerFactory emfThe factory used to generate the entity manager -
dbSessionFactory
-
db
-
organizationDirectoryService
The organization directory service -
userDirectoryService
The user directory service
-
-
Constructor Details
-
JpaGroupRoleProvider
public JpaGroupRoleProvider()
-
-
Method Details
-
setEntityManagerFactory
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory emf) OSGi DI -
setDBSessionFactory
-
setUserDirectoryService
Sets the user directory service- Parameters:
userDirectoryService- the userDirectoryService to set
-
setSecurityService
- Parameters:
securityService- the securityService to set
-
setOrganizationDirectoryService
public void setOrganizationDirectoryService(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
Return the roles- Specified by:
getRolesin interfaceAAIRoleProvider- Returns:
- the roles
- See Also:
-
getRolesForUser
Returns the roles for this user or an empty array if no roles are applicable.- Specified by:
getRolesForUserin interfaceGroupRoleProvider- Specified by:
getRolesForUserin interfaceRoleProvider- Parameters:
userName- the user id- Returns:
- the set of roles
- See Also:
-
getRolesForGroup
Returns the roles for this group or an empty array if no roles are applicable.- Specified by:
getRolesForGroupin interfaceGroupProvider- Specified by:
getRolesForGroupin interfaceGroupRoleProvider- Parameters:
groupName- the group id- Returns:
- the set of roles
- See Also:
-
getOrganization
Returns the identifier for the organization that is defining this set of roles.- Specified by:
getOrganizationin interfaceGroupRoleProvider- Specified by:
getOrganizationin interfaceRoleProvider- Returns:
- the defining organization
- See Also:
-
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:
-
updateGroupMembershipFromRoles
Updates a user's group membership- Specified by:
updateGroupMembershipFromRolesin interfaceGroupRoleProvider- Parameters:
userName- the usernameorgId- the user's organizationroleList- 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 usernameorgId- the user's organizationroleList- the list of group role namesprefix- handle only roles with given prefix
-
removeMemberFromAllGroups
Removes a user from all groups- Parameters:
userName- the usernameorgId- the user's organization
-
loadGroup
Loads a group from persistence- Parameters:
groupId- the group idorgId- the organization id- Returns:
- the loaded group or
nullif not found
-
getGroup
Get group.- Parameters:
groupId-- Returns:
- the group
-
addGroup
Adds or updates a group to the persistence.- Specified by:
addGroupin interfaceGroupRoleProvider- Parameters:
group- the group to add- Throws:
UnauthorizedException
-
getGroups
Description copied from interface:GroupRoleProviderGetting all groups- Specified by:
getGroupsin interfaceGroupRoleProvider- Returns:
- Iterator<Group> persisted groups
-
getGroups
Returns a XML representation of the list of groups available the current user's organization.- Parameters:
limit- the int amount to limit the resultsoffset- the offset to start this result set at- Returns:
- the JaxbGroupList of results
- Throws:
IOException- if unexpected IO exception occurs
-
getGroups
public List<JpaGroup> getGroups(Optional<Integer> limit, Optional<Integer> offset, Optional<String> nameFilter, Optional<String> textFilter, ArrayList<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
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
Remove a group by id- Parameters:
groupId- the id of the group to remove- Throws:
Exception- unexpected error occurredUnauthorizedException- user is not authorized to remove this groupNotFoundException- the group was not found
-
createGroup
public void createGroup(String name, String description, String roles, String users) throws IllegalArgumentException, UnauthorizedException, ConflictException Create a new group- Parameters:
name- the name of the groupdescription- a description of the grouproles- the roles of the groupusers- the users in the group- Throws:
IllegalArgumentException- if missing or bad parametersUnauthorizedException- if user does not have rights to create groupConflictException- if group already exists
-
removeMemberFromGroup
public boolean removeMemberFromGroup(String groupId, String member) throws NotFoundException, UnauthorizedException Remove member from group.- Parameters:
groupId-member-- Returns:
- true if we updated the group, false otherwise
- Throws:
NotFoundExceptionUnauthorizedException
-
addMemberToGroup
public boolean addMemberToGroup(String groupId, String member) throws NotFoundException, UnauthorizedException Add member to group.- Parameters:
groupId-member-- Returns:
- true if we updated the group, false otherwise
- Throws:
NotFoundExceptionUnauthorizedException
-
updateGroup
public void updateGroup(String groupId, String name, String description, String roles, String users) throws NotFoundException, UnauthorizedException Update a group- Specified by:
updateGroupin interfaceGroupRoleProvider- Parameters:
groupId- the id of the group to updatename- the name to updatedescription- the description to updateroles- the roles to updateusers- the users to update- Throws:
NotFoundException- if the group is not foundUnauthorizedException- if the user does not have rights to update the group- See Also:
-