@Test public void testFindRoles() throws UnauthorizedException { Set<JpaRole> authorities = new HashSet<JpaRole>(); authorities.add(new JpaRole("ROLE_ASTRO_101_SPRING_2011_STUDENT", org1)); authorities.add(new JpaRole("ROLE_ASTRO_109_SPRING_2012_STUDENT", org1)); Set<String> members = new HashSet<String>(); members.add("admin"); JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", authorities, members); provider.addGroup(group); Role role = provider.findRoles("%test%", Role.Target.ALL, 0, 0).next(); Assert.assertEquals("ROLE_GROUP_TEST", role.getName()); authorities.clear(); authorities.add(new JpaRole("ROLE_ASTRO_122_SPRING_2011_STUDENT", org1)); authorities.add(new JpaRole("ROLE_ASTRO_124_SPRING_2012_STUDENT", org1)); JpaGroup group2 = new JpaGroup("test2", org1, "Test2", "Test 2 group", authorities, members); provider.addGroup(group2); authorities = new HashSet<JpaRole>(); authorities.add(new JpaRole("ROLE_ASTRO_134_SPRING_2011_STUDENT", org2)); authorities.add(new JpaRole("ROLE_ASTRO_144_SPRING_2012_STUDENT", org2)); JpaGroup group3 = new JpaGroup("test2", org2, "Test2", "Test 2 group", authorities, members); provider.addGroup(group3); Assert.assertEquals(0, IteratorUtils.toList(provider.findRoles("%PrIn%", Role.Target.ALL, 0, 0)).size()); Assert.assertEquals(0, IteratorUtils.toList(provider.findRoles("%PrIn%", Role.Target.ALL, 0, 1)).size()); Assert.assertEquals(2, IteratorUtils.toList(provider.findRoles("%test%", Role.Target.ALL, 0, 2)).size()); }
@Override public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); String orgId = securityService.getOrganization().getId(); List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf); List<Role> roles = new ArrayList<Role>(); for (JpaGroup group : groups) { if (like(group.getRole(), query)) roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP)); } Set<Role> result = new HashSet<Role>(); int i = 0; for (Role entry : roles) { if (limit != 0 && result.size() >= limit) break; if (i >= offset) result.add(entry); i++; } return result.iterator(); }
JpaGroupRoleProvider extends AbstractIndexProducer implements AAIRoleProvider, GroupProvider, GroupRoleProvider { @Override public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); String orgId = securityService.getOrganization().getId(); List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf); List<Role> roles = new ArrayList<Role>(); for (JpaGroup group : groups) { if (like(group.getRole(), query)) roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP)); } Set<Role> result = new HashSet<Role>(); int i = 0; for (Role entry : roles) { if (limit != 0 && result.size() >= limit) break; if (i >= offset) result.add(entry); i++; } return result.iterator(); } }
JpaGroupRoleProvider extends AbstractIndexProducer implements AAIRoleProvider, GroupProvider, GroupRoleProvider { @Override public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); String orgId = securityService.getOrganization().getId(); List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf); List<Role> roles = new ArrayList<Role>(); for (JpaGroup group : groups) { if (like(group.getRole(), query)) roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP)); } Set<Role> result = new HashSet<Role>(); int i = 0; for (Role entry : roles) { if (limit != 0 && result.size() >= limit) break; if (i >= offset) result.add(entry); i++; } return result.iterator(); }  }
JpaGroupRoleProvider extends AbstractIndexProducer implements AAIRoleProvider, GroupProvider, GroupRoleProvider { @Override public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); String orgId = securityService.getOrganization().getId(); List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf); List<Role> roles = new ArrayList<Role>(); for (JpaGroup group : groups) { if (like(group.getRole(), query)) roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP)); } Set<Role> result = new HashSet<Role>(); int i = 0; for (Role entry : roles) { if (limit != 0 && result.size() >= limit) break; if (i >= offset) result.add(entry); i++; } return result.iterator(); }  @Reference(name = "entityManagerFactory", target = "(osgi.unit.name=org.opencastproject.common)") void setEntityManagerFactory(EntityManagerFactory emf); @Reference(name = "userDirectoryService") void setUserDirectoryService(UserDirectoryService userDirectoryService); @Reference(name = "message-broker-sender") void setMessageSender(MessageSender messageSender); @Reference(name = "message-broker-receiver") void setMessageReceiver(MessageReceiver messageReceiver); @Reference(name = "security-service") void setSecurityService(SecurityService securityService); @Reference(name = "organization-directory-service") void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService); @Activate void activate(ComponentContext cc); @Override Iterator<Role> getRoles(); @Override List<Role> getRolesForUser(String userName); @Override List<Role> getRolesForGroup(String groupName); @Override String getOrganization(); @Override Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit); void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList); void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList, String prefix); Group loadGroup(String groupId, String orgId); @Override void addGroup(final JpaGroup group); Iterator<Group> getGroups(); JaxbGroupList getGroupsAsJson(int limit, int offset); JaxbGroupList getGroupsAsXml(int limit, int offset); void removeGroup(String groupId); void createGroup(String name, String description, String roles, String users); @Override void updateGroup(String groupId, String name, String description, String roles, String users); @Override void repopulate(final String indexName); @Override MessageReceiver getMessageReceiver(); @Override Service getService(); @Override String getClassName(); @Override MessageSender getMessageSender(); @Override SecurityService getSecurityService(); @Override String getSystemUserName(); }
JpaGroupRoleProvider extends AbstractIndexProducer implements AAIRoleProvider, GroupProvider, GroupRoleProvider { @Override public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); String orgId = securityService.getOrganization().getId(); List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf); List<Role> roles = new ArrayList<Role>(); for (JpaGroup group : groups) { if (like(group.getRole(), query)) roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP)); } Set<Role> result = new HashSet<Role>(); int i = 0; for (Role entry : roles) { if (limit != 0 && result.size() >= limit) break; if (i >= offset) result.add(entry); i++; } return result.iterator(); }  @Reference(name = "entityManagerFactory", target = "(osgi.unit.name=org.opencastproject.common)") void setEntityManagerFactory(EntityManagerFactory emf); @Reference(name = "userDirectoryService") void setUserDirectoryService(UserDirectoryService userDirectoryService); @Reference(name = "message-broker-sender") void setMessageSender(MessageSender messageSender); @Reference(name = "message-broker-receiver") void setMessageReceiver(MessageReceiver messageReceiver); @Reference(name = "security-service") void setSecurityService(SecurityService securityService); @Reference(name = "organization-directory-service") void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService); @Activate void activate(ComponentContext cc); @Override Iterator<Role> getRoles(); @Override List<Role> getRolesForUser(String userName); @Override List<Role> getRolesForGroup(String groupName); @Override String getOrganization(); @Override Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit); void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList); void updateGroupMembershipFromRoles(String userName, String orgId, List<String> roleList, String prefix); Group loadGroup(String groupId, String orgId); @Override void addGroup(final JpaGroup group); Iterator<Group> getGroups(); JaxbGroupList getGroupsAsJson(int limit, int offset); JaxbGroupList getGroupsAsXml(int limit, int offset); void removeGroup(String groupId); void createGroup(String name, String description, String roles, String users); @Override void updateGroup(String groupId, String name, String description, String roles, String users); @Override void repopulate(final String indexName); @Override MessageReceiver getMessageReceiver(); @Override Service getService(); @Override String getClassName(); @Override MessageSender getMessageSender(); @Override SecurityService getSecurityService(); @Override String getSystemUserName(); static final String PERSISTENCE_UNIT; }