-
Oct 26th, 2010, 11:01 AM
#1
Connection refused from embedded LDAP
Hi
I'm trying to use the embedded LDAP server for testing as suggested; this is in a console app, not web, to make things simpler for the moment. I am getting java.net.ConnectException: Connection refused: connect.
My applicationContext-security.xml is
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<s:ldap-server ldif="classpath:users.ldif" port="33389"/>
<s:authentication-manager>
<s:authentication-provider ref='secondLdapProvider' />
</s:authentication-manager>
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSp ringSecurityContextSource">
<constructor-arg value="ldap://localhost:33389/dc=springframework,dc=org"/>
</bean>
<bean id="secondLdapProvider" class="org.springframework.security.ldap.authentic ation.LdapAuthenticationProvider">
<constructor-arg>
<bean class="org.springframework.security.ldap.authentic ation.BindAuthenticator">
<constructor-arg ref="contextSource" />
<property name="userSearch">
<bean id="userSearch" class="org.springframework.security.ldap.search.Fi lterBasedLdapUserSearch">
<constructor-arg index="0" value="ou=people"/>
<constructor-arg index="1" value="(uid={0})"/>
<constructor-arg index="2" ref="contextSource" />
</bean>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.ldap.userdetai ls.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource" />
<constructor-arg value="ou=groups" />
<property name="groupSearchFilter" value="(member={0})"/>
<property name="rolePrefix" value="ROLE_"/>
<property name="searchSubtree" value="true"/>
<property name="convertToUpperCase" value="true"/>
</bean>
</constructor-arg>
</bean>
</beans>
My java method is
public static void main(String[] args) {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource(
"applicationContext-security.xml"));
LdapAuthenticationProvider ldapAuthenticationProvider = (LdapAuthenticationProvider) bf.getBean("secondLdapProvider");
try {
Authentication request = new UsernamePasswordAuthenticationToken("rod", "koala");
Authentication result = ldapAuthenticationProvider.authenticate(request);
System.out.println("Successfully authenticated. Security context contains: "+result.toString() );
} catch(AuthenticationException e) {
System.out.println("Authentication failed: " + e.getMessage());
}
}
Logs are
[INFO,XmlBeanDefinitionReader,main] Loading XML bean definitions from class path resource [applicationContext-security.xml]
[INFO,DefaultSpringSecurityContextSource,main] URL 'ldap://localhost:33389/dc=springframework,dc=org', root DN is 'dc=springframework,dc=org'
[INFO,AbstractContextSource,main] Property 'userDn' not set - anonymous context will be used for read-write operations
[DEBUG,LdapAuthenticationProvider,main] Processing authentication request for user: rod
[DEBUG,FilterBasedLdapUserSearch,main] Searching for user 'rod', with user search [ searchFilter: '(uid={0})', searchBase: 'ou=people', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ]
Exception in thread "main" org.springframework.security.authentication.Authen ticationServiceException: localhost:33389; nested exception is javax.naming.CommunicationException: localhost:33389 [Root exception is java.net.ConnectException: Connection refused: connect]
at org.springframework.security.ldap.authentication.L dapAuthenticationProvider.authenticate(LdapAuthent icationProvider.java:271)
-
Oct 26th, 2010, 04:01 PM
#2
Try using a ClassPathXmlApplicationContext instead. You may want to read the differences between using ApplicationContext and a BeanFactory as well.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules