@Test public void testSynchronizeExistingLdapUsers() throws Exception { User user1 = createNiceMock(User.class); User user2 = createNiceMock(User.class); User user3 = createNiceMock(User.class); User user4 = createNiceMock(User.class); expect(user1.getUserName()).andReturn("synced_user1").anyTimes(); expect(user2.getUserName()).andReturn("synced_user2").anyTimes(); expect(user3.getUserName()).andReturn("unsynced_user1").anyTimes(); expect(user4.getUserName()).andReturn("unsynced_user2").anyTimes(); expect(user1.isLdapUser()).andReturn(true).anyTimes(); expect(user2.isLdapUser()).andReturn(true).anyTimes(); expect(user3.isLdapUser()).andReturn(false).anyTimes(); expect(user4.isLdapUser()).andReturn(false).anyTimes(); List<User> userList = Arrays.asList(user1, user2, user3, user4); Configuration configuration = createNiceMock(Configuration.class); Users users = createNiceMock(Users.class); LdapTemplate ldapTemplate = createNiceMock(LdapTemplate.class); LdapServerProperties ldapServerProperties = createNiceMock(LdapServerProperties.class); expect(users.getAllUsers()).andReturn(userList); replay(ldapTemplate, ldapServerProperties, users, configuration); replay(user1, user2, user3, user4); AmbariLdapDataPopulatorTestInstance populator = createMockBuilder(AmbariLdapDataPopulatorTestInstance.class) .addMockedMethod("getLdapUsers") .withConstructor(configuration, users) .createNiceMock(); expect(populator.getLdapUsers("synced_user1")).andReturn(Collections.<LdapUserDto>emptySet()); expect(populator.getLdapUsers("synced_user2")).andReturn(Collections.singleton(createNiceMock(LdapUserDto.class))); replay(populator); populator.setLdapTemplate(ldapTemplate); populator.setLdapServerProperties(ldapServerProperties); LdapBatchDto result = populator.synchronizeExistingLdapUsers(new LdapBatchDto()); assertEquals(1, result.getUsersToBeRemoved().size()); assertTrue(result.getUsersToBeRemoved().contains("synced_user1")); assertTrue(result.getUsersToBeCreated().isEmpty()); assertTrue(result.getUsersToBecomeLdap().isEmpty()); assertTrue(result.getGroupsToBeRemoved().isEmpty()); assertTrue(result.getGroupsToBeCreated().isEmpty()); assertTrue(result.getGroupsToBecomeLdap().isEmpty()); assertTrue(result.getMembershipToAdd().isEmpty()); assertTrue(result.getMembershipToRemove().isEmpty()); verify(populator.loadLdapTemplate(), populator); }
public LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo) throws AmbariException { LOG.trace("Synchronize Existing LDAP users..."); final Map<String, User> internalUsersMap = getInternalUsers(); for (User user : internalUsersMap.values()) { if (user.isLdapUser()) { Set<LdapUserDto> userDtos = getLdapUsers(user.getUserName()); if (userDtos.isEmpty()) { batchInfo.getUsersToBeRemoved().add(user.getUserName()); } } } return batchInfo; }
AmbariLdapDataPopulator { public LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo) throws AmbariException { LOG.trace("Synchronize Existing LDAP users..."); final Map<String, User> internalUsersMap = getInternalUsers(); for (User user : internalUsersMap.values()) { if (user.isLdapUser()) { Set<LdapUserDto> userDtos = getLdapUsers(user.getUserName()); if (userDtos.isEmpty()) { batchInfo.getUsersToBeRemoved().add(user.getUserName()); } } } return batchInfo; } }
AmbariLdapDataPopulator { public LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo) throws AmbariException { LOG.trace("Synchronize Existing LDAP users..."); final Map<String, User> internalUsersMap = getInternalUsers(); for (User user : internalUsersMap.values()) { if (user.isLdapUser()) { Set<LdapUserDto> userDtos = getLdapUsers(user.getUserName()); if (userDtos.isEmpty()) { batchInfo.getUsersToBeRemoved().add(user.getUserName()); } } } return batchInfo; } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); }
AmbariLdapDataPopulator { public LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo) throws AmbariException { LOG.trace("Synchronize Existing LDAP users..."); final Map<String, User> internalUsersMap = getInternalUsers(); for (User user : internalUsersMap.values()) { if (user.isLdapUser()) { Set<LdapUserDto> userDtos = getLdapUsers(user.getUserName()); if (userDtos.isEmpty()) { batchInfo.getUsersToBeRemoved().add(user.getUserName()); } } } return batchInfo; } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo); }
AmbariLdapDataPopulator { public LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo) throws AmbariException { LOG.trace("Synchronize Existing LDAP users..."); final Map<String, User> internalUsersMap = getInternalUsers(); for (User user : internalUsersMap.values()) { if (user.isLdapUser()) { Set<LdapUserDto> userDtos = getLdapUsers(user.getUserName()); if (userDtos.isEmpty()) { batchInfo.getUsersToBeRemoved().add(user.getUserName()); } } } return batchInfo; } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo);  }