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());
}
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());
}
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;
}
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");
}
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");
}
Aggregations