Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration testing with ActiveDirectoryLdapAuthenticationProvider

Last time I've added to our project one more authentication provider in order to authenticate user through windows active directory server:

<security:authentication-manager id="authenticationManager" erase-credentials="true">
        <security:authentication-provider ref="ldapActiveDirectoryAuthProvider" />
        <security:authentication-provider ref="authenticationProvider1"/>
        <security:authentication-provider ref="authenticationProvider2"/>
    </security:authentication-manager>

     <bean id="customLdapUserDetailsMapper" class="security.authentication.customLdapUserDetailsMapper">
     </bean>

     <bean id="ldapActiveDirectoryAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
       <constructor-arg value="my.domain"/>
       <constructor-arg value="ldap://my.custom.host:389" />
       <property name="useAuthenticationRequestCredentials" value="true" />
       <property name="convertSubErrorCodesToExceptions" value="true" />
       <property name="userDetailsContextMapper" ref="customLdapUserDetailsMapper" />
     </bean>

Alsmost work fine except existing integration tests that work with authentication flow. Namely each test tried to connect to server when ActiveDirectoryLdapAuthenticationProvider.bindAsUser then failed because my.custom.host is unavaible for this type of test.

I've started googling in order to find some mock for this type of test, but unfortunatly I found only this post Integration tests with spring-security and ldap where Luke Taylor recommended use existing integration tests as a guide. I've took a look into it but it doesn't contain any tests for this type of provider.

I'm new in such stuff and would be good to know the following things:

  1. Will be it correct to reuse in any manner this approach with new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); that was mentioned in LDAP integration test(I am not sure wheter it suites to me because I didn't create ldap ebbedded ldap server in my application context and didn't specify any .ldif files in mentioned configuration as well).
  2. In which way the following provider can be mocked in proper way?
like image 466
fashuser Avatar asked Nov 10 '22 19:11

fashuser


1 Answers

Actually you just have to provide another configuration which will be loaded for Testing purposes. There you can define a different Authentication Provider, which for example just can authenticate everyone.... Or just simply deactivate Authentication at all.

Since you don't want to test the functionallity provided by spring.

like image 146
questionaire Avatar answered Nov 14 '22 23:11

questionaire