Search in sources :

Example 1 with LdapTemplate

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

the class LdapHealthIndicatorTests method ldapIsUp.

@Test
@SuppressWarnings("unchecked")
public void ldapIsUp() {
    LdapTemplate ldapTemplate = mock(LdapTemplate.class);
    given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any())).willReturn("3");
    LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isEqualTo("3");
    verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
}
Also used : LdapTemplate(org.springframework.ldap.core.LdapTemplate) Test(org.junit.Test)

Example 2 with LdapTemplate

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

the class LdapHealthIndicatorTests method ldapIsDown.

@Test
@SuppressWarnings("unchecked")
public void ldapIsDown() {
    LdapTemplate ldapTemplate = mock(LdapTemplate.class);
    given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any())).willThrow(new CommunicationException(new javax.naming.CommunicationException("Connection failed")));
    LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
    verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
}
Also used : CommunicationException(org.springframework.ldap.CommunicationException) LdapTemplate(org.springframework.ldap.core.LdapTemplate) Test(org.junit.Test)

Example 3 with LdapTemplate

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

the class SpringLdapComponent method createEndpoint.

/**
     * creates a Spring LDAP endpoint
     * @param remaining name of the Spring LDAP template bean to be used for the LDAP operation
     * @param parameters key-value pairs to be set on @see org.apache.camel.component.springldap.SpringLdapEndpoint.
     * Currently supported keys are operation and scope.
     * 'operation' is defined in org.apache.camel.component.springldap.LdapOperation.
     * 'scope' must be one of "object", "onelevel", or "subtree".
     */
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    CamelContext camelContext = getCamelContext();
    Registry registry = camelContext.getRegistry();
    LdapTemplate ldapTemplate = registry.lookupByNameAndType(remaining, LdapTemplate.class);
    Endpoint endpoint = new SpringLdapEndpoint(remaining, ldapTemplate);
    setProperties(endpoint, parameters);
    return endpoint;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) Registry(org.apache.camel.spi.Registry) LdapTemplate(org.springframework.ldap.core.LdapTemplate)

Example 4 with LdapTemplate

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

the class LdapServerBeanDefinitionParserTests method useOfUrlAttributeCreatesCorrectContextSource.

@Test
public void useOfUrlAttributeCreatesCorrectContextSource() throws Exception {
    int port = getDefaultPort();
    // Create second "server" with a url pointing at embedded one
    appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='" + port + "'/>" + "<ldap-server ldif='classpath:test-server.ldif' id='blah' url='ldap://127.0.0.1:" + port + "/dc=springframework,dc=org' />");
    // Check the default context source is still there.
    appCtx.getBean(BeanIds.CONTEXT_SOURCE);
    DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx.getBean("blah");
    // Check data is loaded as before
    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 5 with LdapTemplate

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

the class LdapServerBeanDefinitionParserTests method loadingSpecificLdifFileIsSuccessful.

@Test
public void loadingSpecificLdifFileIsSuccessful() {
    appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath*:test-server2.xldif' root='dc=monkeymachine,dc=co,dc=uk' />");
    DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx.getBean(BeanIds.CONTEXT_SOURCE);
    LdapTemplate template = new LdapTemplate(contextSource);
    template.lookup("uid=pg,ou=gorillas");
}
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)

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