public Collection<String> getUserGroups() { final com.atlassian.crowd.search.query.membership.MembershipQuery<String> membershipQuery = QueryBuilder.queryFor(String.class, EntityDescriptor.group()) .parentsOf(EntityDescriptor.user()) .withName(name) .returningAtMost(EntityQuery.ALL_RESULTS); return Lists.newArrayList(crowdService.search(membershipQuery)); }
private void migrateUser( final long fromDirectoryId, final long toDirectoryId, final String remoteUser, final User user, final AtomicLong migratedCount) throws Exception { if (!user.getName().equalsIgnoreCase(remoteUser)) { UserWithAttributes userWithAttributes = directoryManager.findUserWithAttributesByName(fromDirectoryId, user.getName()); try { final UserTemplate newUser = new UserTemplate(user); newUser.setDirectoryId(toDirectoryId); directoryManager.addUser( toDirectoryId, newUser, new PasswordCredential(generatePassword())); } catch (InvalidUserException e) { // That's fine just go on to the next user. Don't copy the groups. return; } // Migrate attributes Set<String> keys = userWithAttributes.getKeys(); Map<String, Set<String>> attributes = new HashMap<String, Set<String>>(); for (String key : keys) { Set<String> values = userWithAttributes.getValues(key); attributes.put(key, values); } directoryManager.storeUserAttributes(toDirectoryId, user.getName(), attributes); MembershipQuery<Group> groupQuery = QueryBuilder.queryFor(Group.class, EntityDescriptor.group()) .parentsOf(EntityDescriptor.user()) .withName(user.getName()) .returningAtMost(EntityQuery.ALL_RESULTS); List<Group> groups = directoryManager.searchDirectGroupRelationships(fromDirectoryId, groupQuery); for (Group group : groups) { // We may need to add the group first try { directoryManager.findGroupByName(toDirectoryId, group.getName()); } catch (GroupNotFoundException ex) { final GroupTemplate newGroup = new GroupTemplate(group); newGroup.setDirectoryId(toDirectoryId); directoryManager.addGroup(toDirectoryId, newGroup); } directoryManager.addUserToGroup(toDirectoryId, user.getName(), group.getName()); directoryManager.removeUserFromGroup(fromDirectoryId, user.getName(), group.getName()); } directoryManager.removeUser(fromDirectoryId, user.getName()); migratedCount.addAndGet(1); } }
@Test public void testTurkish() throws Exception { // EMBCWD-735 // Add a dotted i turkish user User user = TestData.User.getUser( "turkish", TestData.DIRECTORY_ID, TestData.User.ACTIVE, TestData.User.FIRST_NAME, TestData.User.LAST_NAME, TestData.User.DISPLAY_NAME, TestData.User.EMAIL); User createdUser = userDao.add(user, TestData.User.CREDENTIAL); // Now add a dotless turk?sh user user = TestData.User.getUser( "turk\u0131sh", TestData.DIRECTORY_ID, TestData.User.ACTIVE, TestData.User.FIRST_NAME, TestData.User.LAST_NAME, TestData.User.DISPLAY_NAME, TestData.User.EMAIL); createdUser = userDao.add(user, TestData.User.CREDENTIAL); List<User> allUsers = userDao.search( TestData.DIRECTORY_ID, QueryBuilder.queryFor(User.class, EntityDescriptor.user()) .returningAtMost(EntityQuery.ALL_RESULTS)); assertEquals(2, allUsers.size()); }
public ApplicationQuery(SearchRestriction searchRestriction, int startIndex, int maxResults) { super( Application.class, EntityDescriptor.application(), searchRestriction, startIndex, maxResults); }