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;
}
Aggregations