Search in sources :

Example 1 with LDAPInitialDirContextFactoryImpl

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;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) SearchResult(javax.naming.directory.SearchResult) SearchControls(javax.naming.directory.SearchControls) InitialDirContext(javax.naming.directory.InitialDirContext) LDAPInitialDirContextFactoryImpl(org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl)

Example 2 with LDAPInitialDirContextFactoryImpl

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);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LDAPInitialDirContextFactoryImpl(org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl)

Aggregations

LDAPInitialDirContextFactoryImpl (org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl)2 BasicAttribute (javax.naming.directory.BasicAttribute)1 BasicAttributes (javax.naming.directory.BasicAttributes)1 InitialDirContext (javax.naming.directory.InitialDirContext)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1