Search in sources :

Example 16 with ChaiEntry

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;
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) CachePolicy(password.pwm.svc.cache.CachePolicy) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) TimeDuration(password.pwm.util.java.TimeDuration) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) CacheKey(password.pwm.svc.cache.CacheKey)

Example 17 with ChaiEntry

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;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) Configuration(password.pwm.config.Configuration) ChaiEntry(com.novell.ldapchai.ChaiEntry) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 18 with ChaiEntry

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;
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) HashSet(java.util.HashSet)

Example 19 with ChaiEntry

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;
}
Also used : ArrayList(java.util.ArrayList) ChaiEntry(com.novell.ldapchai.ChaiEntry) LdapProfile(password.pwm.config.profile.LdapProfile) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 20 with ChaiEntry

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;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ChaiEntry (com.novell.ldapchai.ChaiEntry)31 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)12 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 ChaiUser (com.novell.ldapchai.ChaiUser)6 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 ChaiException (com.novell.ldapchai.exception.ChaiException)2 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2 TcpProxy (com.novell.ldapchai.tests.util.TcpProxy)2 InetSocketAddress (java.net.InetSocketAddress)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2