Search in sources :

Example 6 with LdapTemplate

use of org.springframework.ldap.core.LdapTemplate in project gocd by gocd.

the class LdapUserSearchTest method setUp.

@Before
public void setUp() {
    goConfigService = mock(GoConfigService.class);
    contextFactory = mock(SpringSecurityContextSource.class);
    securityConfig = mock(SecurityConfig.class);
    ldapTemplate = mock(LdapTemplate.class);
    logger = mock(Logger.class);
    ldapUserSearch = new LdapUserSearch(goConfigService, contextFactory, ldapTemplate, logger);
    when(goConfigService.security()).thenReturn(securityConfig);
    spy = spy(ldapUserSearch);
}
Also used : SpringSecurityContextSource(org.springframework.security.ldap.SpringSecurityContextSource) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) Logger(org.apache.log4j.Logger) LdapTemplate(org.springframework.ldap.core.LdapTemplate) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 7 with LdapTemplate

use of org.springframework.ldap.core.LdapTemplate in project camel by apache.

the class SpringLdapProducerTest method testFunctionDriven.

@Test
public void testFunctionDriven() throws Exception {
    String dn = "cn=dn";
    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();
    Map<String, Object> body = new HashMap<String, Object>();
    body.put(SpringLdapProducer.DN, dn);
    body.put(SpringLdapProducer.REQUEST, dn);
    body.put(SpringLdapProducer.FUNCTION, (BiFunction<LdapOperations, String, Void>) (l, q) -> {
        l.lookup(q);
        return null;
    });
    when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
    processBody(exchange, in, body);
    verify(ldapTemplate).lookup(eq(dn));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) ModificationItem(javax.naming.directory.ModificationItem) Message(org.apache.camel.Message) Matchers(org.mockito.Matchers) BiFunction(java.util.function.BiFunction) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) LdapTemplate(org.springframework.ldap.core.LdapTemplate) SearchControls(javax.naming.directory.SearchControls) BasicAttribute(javax.naming.directory.BasicAttribute) LdapOperations(org.springframework.ldap.core.LdapOperations) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Before(org.junit.Before) LdapQuery(org.springframework.ldap.query.LdapQuery) DefaultExchange(org.apache.camel.impl.DefaultExchange) Matchers.isNull(org.mockito.Matchers.isNull) DirContext(javax.naming.directory.DirContext) BasicAttributes(javax.naming.directory.BasicAttributes) DefaultMessage(org.apache.camel.impl.DefaultMessage) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) AttributesMapper(org.springframework.ldap.core.AttributesMapper) CamelTestSupport(org.apache.camel.test.junit4.CamelTestSupport) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) LdapOperations(org.springframework.ldap.core.LdapOperations) Test(org.junit.Test)

Example 8 with LdapTemplate

use of org.springframework.ldap.core.LdapTemplate in project jBPM5-Developer-Guide by Salaboy.

the class ProcessAndHumanTasksTest method setUp.

@Before
public void setUp() throws Exception {
    container = new ApacheDSContainer("o=mojo", "classpath:identity-repository.ldif");
    container.setPort(9898);
    container.afterPropertiesSet();
    LdapContextSource cs = new LdapContextSource();
    cs.setUrl("ldap://localhost:9898/");
    cs.setBase("o=mojo");
    cs.setUserDn("uid=admin,ou=system");
    cs.setPassword("secret");
    cs.afterPropertiesSet();
    LdapTemplate ldapTemplate = new LdapTemplate(cs);
    ldapTemplate.afterPropertiesSet();
    ldapQuery = new LdapQueryHelper(ldapTemplate);
    // By Setting the jbpm.usergroup.callback property with the call
    // back class full name, task service will use this to validate the
    // user/group exists and its permissions are ok.
    System.setProperty("jbpm.usergroup.callback", "org.jbpm.task.identity.LDAPUserGroupCallbackImpl");
//        LdapUserGroupCallback callback = (LdapUserGroupCallback) UserGroupCallbackManager.getInstance().getCallback();
//        callback.setQuery(ldapQuery);
}
Also used : LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) ApacheDSContainer(org.springframework.security.ldap.server.ApacheDSContainer) LdapTemplate(org.springframework.ldap.core.LdapTemplate) Before(org.junit.Before)

Example 9 with LdapTemplate

use of org.springframework.ldap.core.LdapTemplate in project spring-security by spring-projects.

the class LdapServerBeanDefinitionParserTests method embeddedServerCreationContainsExpectedContextSourceAndData.

@Test
public void embeddedServerCreationContainsExpectedContextSourceAndData() {
    appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif'/>");
    DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx.getBean(BeanIds.CONTEXT_SOURCE);
    // Check data is loaded
    LdapTemplate template = new LdapTemplate(contextSource);
    template.lookup("uid=ben,ou=people");
}
Also used : DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) LdapTemplate(org.springframework.ldap.core.LdapTemplate) InMemoryXmlApplicationContext(org.springframework.security.config.util.InMemoryXmlApplicationContext) Test(org.junit.Test)

Example 10 with LdapTemplate

use of org.springframework.ldap.core.LdapTemplate in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfigurationTests method testQueryEmbeddedLdap.

@Test
public void testQueryEmbeddedLdap() throws LDAPException {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.ldap.embedded.base-dn:dc=spring,dc=org");
    this.context.register(EmbeddedLdapAutoConfiguration.class, LdapAutoConfiguration.class, LdapDataAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(LdapTemplate.class).length).isEqualTo(1);
    LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class);
    assertThat(ldapTemplate.list("ou=company1,c=Sweden,dc=spring,dc=org")).hasSize(4);
}
Also used : LdapTemplate(org.springframework.ldap.core.LdapTemplate) Test(org.junit.Test)

Aggregations

LdapTemplate (org.springframework.ldap.core.LdapTemplate)11 Test (org.junit.Test)8 Before (org.junit.Before)3 InMemoryXmlApplicationContext (org.springframework.security.config.util.InMemoryXmlApplicationContext)3 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)3 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 BasicAttribute (javax.naming.directory.BasicAttribute)1 BasicAttributes (javax.naming.directory.BasicAttributes)1 DirContext (javax.naming.directory.DirContext)1 ModificationItem (javax.naming.directory.ModificationItem)1 SearchControls (javax.naming.directory.SearchControls)1 CamelContext (org.apache.camel.CamelContext)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1