문제

I'm using spring-security to authenticate simply , and apacheDS via a simple ldif file:

<!-- BEGIN LDIF CONFIGURATION -->

<security:ldap-server ldif="classpath:spring-security-on-LDIF.ldif" root="dc=foo,dc=com" />

<bean id="userDetailsContextMapper" class="com.foo.myapp.login.springsecurity.MyLdapUserDetailsMapper">
    <constructor-arg ref="MyUserDetailsService" /> 
</bean>

<security:authentication-manager alias="authenticationManager" >
    <security:ldap-authentication-provider user-search-base="ou=users" user-search-filter="uid={0}" user-context-mapper-ref="userDetailsContextMapper"/>
</security:authentication-manager>
<!--  END LDIF CONFIGURATION -->

That works fine. Now I want to add a NEW user to my .ldif file. Unfortunately, I need to restart tomcat to get it to reread the .ldif file. Is there a way to force apacheDS to reread/recache the ldif file at a certain point?

도움이 되었습니까?

해결책

Well, I think I figured it out. You get the ApacheDSContainer from the context, and call its destroy() (which calls stop and destroys the workingDir). Then you call afterPropertiesSet() (which creates the workingDir and then also calls start()). It appears to work quite well. I do this whenever I see the file changes. I used an org.apache.commons.io.monitor.FileAlterationListener to watch the .ldif file, which fires the onFileChange() at the appropriate time.

import org.springframework.security.config.BeanIds;
import org.springframework.security.ldap.server.ApacheDSContainer;
...
public void onFileChange(File file) {
    ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();  
    if (ctx == null)
        return; 
    ApacheDSContainer container = (ApacheDSContainer)ctx.getBean(BeanIds.EMBEDDED_APACHE_DS); 

    if (container != null) {
        try {
            container.destroy();
            container.afterPropertiesSet();
        }
        catch(Exception exec) {
            // handle error
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top