use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LdapProfile method readCanonicalDN.
public String readCanonicalDN(final PwmApplication pwmApplication, final String dnValue) throws PwmUnrecoverableException {
{
final boolean doCanonicalDnResolve = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_RESOLVE_CANONICAL_DN));
if (!doCanonicalDnResolve) {
return dnValue;
}
}
final boolean enableCanonicalCache = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_CACHE_CANONICAL_ENABLE));
String canonicalValue = null;
final CacheKey cacheKey = CacheKey.makeCacheKey(LdapPermissionTester.class, null, "canonicalDN-" + this.getIdentifier() + "-" + dnValue);
if (enableCanonicalCache) {
final String cachedDN = pwmApplication.getCacheService().get(cacheKey);
if (cachedDN != null) {
canonicalValue = cachedDN;
}
}
if (canonicalValue == null) {
try {
final ChaiProvider chaiProvider = this.getProxyChaiProvider(pwmApplication);
final ChaiEntry chaiEntry = chaiProvider.getEntryFactory().newChaiEntry(dnValue);
canonicalValue = chaiEntry.readCanonicalDN();
if (enableCanonicalCache) {
final long cacheSeconds = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_CACHE_CANONICAL_SECONDS));
final CachePolicy cachePolicy = CachePolicy.makePolicyWithExpiration(new TimeDuration(cacheSeconds, TimeUnit.SECONDS));
pwmApplication.getCacheService().put(cacheKey, cachePolicy, canonicalValue);
}
LOGGER.trace("read and cached canonical ldap DN value for input '" + dnValue + "' as '" + canonicalValue + "'");
} catch (ChaiUnavailableException | ChaiOperationException e) {
LOGGER.error("error while reading canonicalDN for dn value '" + dnValue + "', error: " + e.getMessage());
return dnValue;
}
}
return canonicalValue;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LdapBrowser method doBrowseImpl.
private LdapBrowseResult doBrowseImpl(final String profileID, final String dn) throws PwmUnrecoverableException, ChaiUnavailableException, ChaiOperationException {
final LdapBrowseResult result = new LdapBrowseResult();
{
final Map<String, Boolean> childDNs = new TreeMap<>();
childDNs.putAll(getChildEntries(profileID, dn));
for (final Map.Entry<String, Boolean> entry : childDNs.entrySet()) {
final String childDN = entry.getKey();
final DNInformation dnInformation = new DNInformation();
dnInformation.setDn(childDN);
dnInformation.setEntryName(entryNameFromDN(childDN));
if (entry.getValue()) {
result.getNavigableDNlist().add(dnInformation);
} else {
result.getSelectableDNlist().add(dnInformation);
}
}
result.setMaxResults(childDNs.size() >= getMaxSizeLimit());
}
result.setDn(dn);
result.setProfileID(profileID);
final Configuration configuration = new Configuration(storedConfiguration);
if (configuration.getLdapProfiles().size() > 1) {
result.getProfileList().addAll(configuration.getLdapProfiles().keySet());
}
if (adRootDNList(profileID).contains(dn)) {
result.setParentDN("");
} else if (dn != null && !dn.isEmpty()) {
final ChaiEntry dnEntry = getChaiProvider(profileID).getEntryFactory().newChaiEntry(dn);
final ChaiEntry parentEntry = dnEntry.getParentEntry();
if (parentEntry == null) {
result.setParentDN("");
} else {
result.setParentDN(parentEntry.getEntryDN());
}
}
return result;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LdapBrowser method adRootDNList.
private Set<String> adRootDNList(final String profile) throws ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException {
final ChaiProvider chaiProvider = getChaiProvider(profile);
final Set<String> adRootValues = new HashSet<>();
if (chaiProvider.getDirectoryVendor() == DirectoryVendor.ACTIVE_DIRECTORY) {
final ChaiEntry chaiEntry = ChaiUtility.getRootDSE(chaiProvider);
adRootValues.addAll(chaiEntry.readMultiStringAttribute("namingContexts"));
}
return adRootValues;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LdapDebugDataGenerator method makeLdapDebugInfos.
public static List<LdapDebugInfo> makeLdapDebugInfos(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final Configuration configuration, final Locale locale) {
final List<LdapDebugInfo> returnList = new ArrayList<>();
for (final LdapProfile ldapProfile : configuration.getLdapProfiles().values()) {
final LdapDebugInfo ldapDebugInfo = new LdapDebugInfo();
ldapDebugInfo.setProfileName(ldapProfile.getIdentifier());
ldapDebugInfo.setDisplayName(ldapProfile.getDisplayName(locale));
try {
final ChaiProvider chaiProvider = LdapOperationsHelper.createChaiProvider(pwmApplication, null, ldapProfile, configuration, ldapProfile.readSettingAsString(PwmSetting.LDAP_PROXY_USER_DN), ldapProfile.readSettingAsPassword(PwmSetting.LDAP_PROXY_USER_PASSWORD));
final Collection<ChaiConfiguration> chaiConfigurations = ChaiUtility.splitConfigurationPerReplica(chaiProvider.getChaiConfiguration(), null);
final List<LdapDebugServerInfo> ldapDebugServerInfos = new ArrayList<>();
for (final ChaiConfiguration chaiConfiguration : chaiConfigurations) {
final LdapDebugServerInfo ldapDebugServerInfo = new LdapDebugServerInfo();
ldapDebugServerInfo.setLdapServerlUrl(chaiConfiguration.getSetting(ChaiSetting.BIND_URLS));
final ChaiProvider loopProvider = chaiProvider.getProviderFactory().newProvider(chaiConfiguration);
{
final ChaiEntry rootDSEentry = ChaiUtility.getRootDSE(loopProvider);
final Map<String, List<String>> rootDSEdata = LdapOperationsHelper.readAllEntryAttributeValues(rootDSEentry);
ldapDebugServerInfo.setRootDseAttributes(rootDSEdata);
}
{
final String proxyUserDN = ldapProfile.readSettingAsString(PwmSetting.LDAP_PROXY_USER_DN);
if (proxyUserDN != null) {
ldapDebugServerInfo.setProxyDN(proxyUserDN);
final ChaiEntry proxyUserEntry = chaiProvider.getEntryFactory().newChaiEntry(proxyUserDN);
if (proxyUserEntry.exists()) {
final Map<String, List<String>> proxyUserData = LdapOperationsHelper.readAllEntryAttributeValues(proxyUserEntry);
ldapDebugServerInfo.setProxyUserAttributes(proxyUserData);
}
}
}
{
final String testUserDN = ldapProfile.readSettingAsString(PwmSetting.LDAP_TEST_USER_DN);
if (testUserDN != null) {
ldapDebugServerInfo.setTestUserDN(testUserDN);
final ChaiEntry testUserEntry = chaiProvider.getEntryFactory().newChaiEntry(testUserDN);
if (testUserEntry.exists()) {
final Map<String, List<String>> testUserdata = LdapOperationsHelper.readAllEntryAttributeValues(testUserEntry);
ldapDebugServerInfo.setTestUserAttributes(testUserdata);
}
}
}
ldapDebugServerInfos.add(ldapDebugServerInfo);
}
ldapDebugInfo.setServerInfo(ldapDebugServerInfos);
returnList.add(ldapDebugInfo);
} catch (Exception e) {
LOGGER.error("error during output of ldap profile debug data profile: " + ldapProfile + ", error: " + e.getMessage());
}
}
return returnList;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LdapDebugDataGenerator method readUserAttributeData.
private Map<String, List<String>> readUserAttributeData(final ChaiProvider chaiProvider, final String userDN) throws ChaiUnavailableException, ChaiOperationException {
final ChaiEntry testUserEntry = chaiProvider.getEntryFactory().newChaiEntry(userDN);
if (testUserEntry.exists()) {
final Map<String, List<String>> returnData = new LinkedHashMap<>();
final Map<String, List<String>> testUserdata = LdapOperationsHelper.readAllEntryAttributeValues(testUserEntry);
testUserdata.put("dn", Collections.singletonList(userDN));
return returnData;
}
return null;
}
Aggregations