JpaGroupRoleProvider extends AbstractIndexProducer implements AAIRoleProvider, GroupProvider, GroupRoleProvider { public void createGroup(String name, String description, String roles, String users) throws IllegalArgumentException, UnauthorizedException, ConflictException { JpaOrganization organization = (JpaOrganization) securityService.getOrganization(); HashSet<JpaRole> roleSet = new HashSet<JpaRole>(); if (roles != null) { for (String role : StringUtils.split(roles, ",")) { roleSet.add(new JpaRole(StringUtils.trim(role), organization)); } } HashSet<String> members = new HashSet<String>(); if (users != null) { for (String member : StringUtils.split(users, ",")) { members.add(StringUtils.trim(member)); } } final String groupId = name.toLowerCase().replaceAll("\\W", "_"); JpaGroup existingGroup = UserDirectoryPersistenceUtil.findGroup(groupId, organization.getId(), emf); if (existingGroup != null) throw new ConflictException("group already exists"); addGroup(new JpaGroup(groupId, organization, name, description, roleSet, members)); }  @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; }
@Test public void testDuplicateGroupCreation() throws IllegalArgumentException, UnauthorizedException, ConflictException { provider.createGroup("Test 1", "Test group", "ROLE_ASTRO_101_SPRING_2011_STUDENT", "admin"); thrown.expect(ConflictException.class); provider.createGroup("Test 1", "Test group 2", "ROLE_ASTRO_101_SPRING_2011_STUDENT", "admin"); }