use of org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl in project alfresco-repository by Alfresco.
the class ChainingUserRegistrySynchronizerTest method getMockedLDAPSearchResult.
private LDAPInitialDirContextFactoryImpl getMockedLDAPSearchResult(boolean withEmail) throws NamingException {
@SuppressWarnings("unchecked") NamingEnumeration<SearchResult> mockedNamingEnumeration = mock(NamingEnumeration.class);
when(mockedNamingEnumeration.hasMore()).thenReturn(true).thenReturn(false);
BasicAttributes attributes = new BasicAttributes();
attributes.put(new BasicAttribute("sAMAccountName", "U1"));
attributes.put(new BasicAttribute("givenName", "U1"));
if (withEmail) {
attributes.put(new BasicAttribute("mail", "U1@alfresco.com"));
}
SearchResult mockedSearchResult = new SearchResult("CN:U1", null, attributes);
mockedSearchResult.setNameInNamespace("CN:U1");
when(mockedNamingEnumeration.next()).thenReturn(mockedSearchResult);
InitialDirContext mockedInitialDirContext = mock(InitialDirContext.class);
when(mockedInitialDirContext.search((String) any(), anyString(), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);
LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
return mockedLdapInitialDirContextFactory;
}
use of org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl in project alfresco-repository by Alfresco.
the class ChainingUserRegistrySynchronizerTest method executeMockedLDAPSync.
private void executeMockedLDAPSync(boolean withEmail) throws NamingException, Exception {
MockUserRegistry mockUserRegistry = new MockUserRegistry("Z0", new NodeDescription[] {}, new NodeDescription[] {});
MockLDAPUserRegistry mockLDAPUserRegistry = new MockLDAPUserRegistry(mockUserRegistry);
LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = getMockedLDAPSearchResult(withEmail);
mockLDAPUserRegistry.setLDAPInitialDirContextFactory(mockedLdapInitialDirContextFactory);
mockLDAPUserRegistry.setEnableProgressEstimation(false);
mockLDAPUserRegistry.setUserIdAttributeName("sAMAccountName");
Map<String, String> personAttributeMapping = getMockedLdapAttributeMapping();
mockLDAPUserRegistry.setPersonAttributeMapping(personAttributeMapping);
mockLDAPUserRegistry.setNamespaceService(this.namespaceService);
mockLDAPUserRegistry.afterPropertiesSet();
this.applicationContextManager.setUserRegistries(mockLDAPUserRegistry);
ChainingUserRegistrySynchronizer chainingSynchronizer = (ChainingUserRegistrySynchronizer) this.synchronizer;
chainingSynchronizer.synchronize(false, false);
}
Aggregations