Search in sources :

Example 1 with EventDirContext

use of javax.naming.event.EventDirContext in project karaf by apache.

the class LDAPCache method open.

public synchronized DirContext open() throws NamingException {
    if (isContextAlive()) {
        return context;
    }
    clearCache();
    context = new InitialDirContext(options.getEnv());
    EventDirContext eventContext = ((EventDirContext) context.lookup(""));
    final SearchControls constraints = new SearchControls();
    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
    if (!options.getDisableCache()) {
        String filter = options.getUserFilter();
        filter = filter.replaceAll(Pattern.quote("%u"), Matcher.quoteReplacement("*"));
        filter = filter.replace("\\", "\\\\");
        eventContext.addNamingListener(options.getUserBaseDn(), filter, constraints, this);
        filter = options.getRoleFilter();
        if (filter != null) {
            filter = filter.replaceAll(Pattern.quote("%u"), Matcher.quoteReplacement("*"));
            filter = filter.replaceAll(Pattern.quote("%dn"), Matcher.quoteReplacement("*"));
            filter = filter.replaceAll(Pattern.quote("%fqdn"), Matcher.quoteReplacement("*"));
            filter = filter.replace("\\", "\\\\");
            eventContext.addNamingListener(options.getRoleBaseDn(), filter, constraints, this);
        }
    }
    return context;
}
Also used : EventDirContext(javax.naming.event.EventDirContext) SearchControls(javax.naming.directory.SearchControls) InitialDirContext(javax.naming.directory.InitialDirContext)

Aggregations

InitialDirContext (javax.naming.directory.InitialDirContext)1 SearchControls (javax.naming.directory.SearchControls)1 EventDirContext (javax.naming.event.EventDirContext)1