Search in sources :

Example 46 with ChaiUnavailableException

use of com.novell.ldapchai.exception.ChaiUnavailableException in project pwm by pwm-project.

the class EdirSchemaExtender method readSchemaObjectclasses.

private Map<String, SchemaParser> readSchemaObjectclasses() throws ChaiUnavailableException, ChaiOperationException {
    final Map<String, SchemaParser> returnObj = new LinkedHashMap<>();
    final Set<String> valuesFromLdap = schemaEntry.readMultiStringAttribute(LDAP_SCHEMA_ATTR_CLASSES);
    for (final String key : valuesFromLdap) {
        SchemaParser schemaParser = null;
        try {
            schemaParser = new SchemaParser(key);
        } catch (Exception e) {
            LOGGER.error("error parsing schema objectclasses definition: " + e.getMessage());
        }
        if (schemaParser != null) {
            for (final String attrName : schemaParser.getNames()) {
                returnObj.put(attrName, schemaParser);
            }
        }
    }
    return returnObj;
}
Also used : SchemaParser(com.novell.ldap.client.SchemaParser) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LinkedHashMap(java.util.LinkedHashMap)

Example 47 with ChaiUnavailableException

use of com.novell.ldapchai.exception.ChaiUnavailableException in project pwm by pwm-project.

the class UserSearchEngine method resolveUsername.

public UserIdentity resolveUsername(final String username, final String context, final String profile, final SessionLabel sessionLabel) throws PwmUnrecoverableException, PwmOperationalException {
    // check if username is a key
    {
        UserIdentity inputIdentity = null;
        try {
            inputIdentity = UserIdentity.fromKey(username, pwmApplication);
        } catch (PwmException e) {
        /* input is not a userIdentity */
        }
        if (inputIdentity != null) {
            try {
                final ChaiUser theUser = pwmApplication.getProxiedChaiUser(inputIdentity);
                if (theUser.exists()) {
                    final String canonicalDN;
                    canonicalDN = theUser.readCanonicalDN();
                    return new UserIdentity(canonicalDN, inputIdentity.getLdapProfileID());
                }
            } catch (ChaiOperationException e) {
                throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_CANT_MATCH_USER, e.getMessage()));
            } catch (ChaiUnavailableException e) {
                throw PwmUnrecoverableException.fromChaiException(e);
            }
        }
    }
    try {
        // see if we need to do a contextless search.
        if (checkIfStringIsDN(username, sessionLabel)) {
            return resolveUserDN(username);
        } else {
            final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
            builder.username(username);
            if (context != null) {
                builder.contexts(Collections.singletonList(context));
            }
            if (profile != null) {
                builder.ldapProfile(profile);
            }
            final SearchConfiguration searchConfiguration = builder.build();
            return performSingleUserSearch(searchConfiguration, sessionLabel);
        }
    } catch (PwmOperationalException e) {
        throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_CANT_MATCH_USER, e.getErrorInformation().getDetailedErrorMsg(), e.getErrorInformation().getFieldValues()));
    } catch (ChaiUnavailableException e) {
        throw PwmUnrecoverableException.fromChaiException(e);
    }
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 48 with ChaiUnavailableException

use of com.novell.ldapchai.exception.ChaiUnavailableException in project pwm by pwm-project.

the class UserSearchEngine method executeSearch.

private Map<UserIdentity, Map<String, String>> executeSearch(final UserSearchJob userSearchJob, final SessionLabel sessionLabel, final int searchID, final int jobID) throws PwmOperationalException, PwmUnrecoverableException {
    debugOutputTask.conditionallyExecuteTask();
    final SearchHelper searchHelper = new SearchHelper();
    searchHelper.setMaxResults(userSearchJob.getMaxResults());
    searchHelper.setFilter(userSearchJob.getSearchFilter());
    searchHelper.setAttributes(userSearchJob.getReturnAttributes());
    searchHelper.setTimeLimit((int) userSearchJob.getTimeoutMs());
    final String debugInfo;
    {
        final Map<String, String> props = new LinkedHashMap<>();
        props.put("profile", userSearchJob.getLdapProfile().getIdentifier());
        props.put("base", userSearchJob.getContext());
        props.put("maxCount", String.valueOf(searchHelper.getMaxResults()));
        debugInfo = "[" + StringUtil.mapToString(props) + "]";
    }
    log(PwmLogLevel.TRACE, sessionLabel, searchID, jobID, "performing ldap search for user; " + debugInfo);
    final Instant startTime = Instant.now();
    final Map<String, Map<String, String>> results;
    try {
        results = userSearchJob.getChaiProvider().search(userSearchJob.getContext(), searchHelper);
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, e.getMessage()));
    } catch (ChaiOperationException e) {
        throw new PwmOperationalException(PwmError.forChaiError(e.getErrorCode()), "ldap error during searchID=" + searchID + ", error=" + e.getMessage());
    }
    final TimeDuration searchDuration = TimeDuration.fromCurrent(startTime);
    if (pwmApplication.getStatisticsManager() != null && pwmApplication.getStatisticsManager().status() == PwmService.STATUS.OPEN) {
        pwmApplication.getStatisticsManager().updateAverageValue(Statistic.AVG_LDAP_SEARCH_TIME, searchDuration.getTotalMilliseconds());
    }
    if (results.isEmpty()) {
        log(PwmLogLevel.TRACE, sessionLabel, searchID, jobID, "no matches from search (" + searchDuration.asCompactString() + "); " + debugInfo);
        return Collections.emptyMap();
    }
    log(PwmLogLevel.TRACE, sessionLabel, searchID, jobID, "found " + results.size() + " results in " + searchDuration.asCompactString() + "; " + debugInfo);
    final Map<UserIdentity, Map<String, String>> returnMap = new LinkedHashMap<>();
    for (final Map.Entry<String, Map<String, String>> entry : results.entrySet()) {
        final String userDN = entry.getKey();
        final Map<String, String> attributeMap = entry.getValue();
        final UserIdentity userIdentity = new UserIdentity(userDN, userSearchJob.getLdapProfile().getIdentifier());
        returnMap.put(userIdentity, attributeMap);
    }
    return returnMap;
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Instant(java.time.Instant) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) SearchHelper(com.novell.ldapchai.util.SearchHelper) PwmOperationalException(password.pwm.error.PwmOperationalException) LinkedHashMap(java.util.LinkedHashMap) ErrorInformation(password.pwm.error.ErrorInformation) TimeDuration(password.pwm.util.java.TimeDuration) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 49 with ChaiUnavailableException

use of com.novell.ldapchai.exception.ChaiUnavailableException in project pwm by pwm-project.

the class LdapBrowser method getChildEntries.

private Map<String, Boolean> getChildEntries(final String profile, final String dn) throws ChaiUnavailableException, PwmUnrecoverableException, ChaiOperationException {
    final HashMap<String, Boolean> returnMap = new HashMap<>();
    final ChaiProvider chaiProvider = getChaiProvider(profile);
    if ((dn == null || dn.isEmpty()) && chaiProvider.getDirectoryVendor() == DirectoryVendor.ACTIVE_DIRECTORY) {
        final Set<String> adRootDNList = adRootDNList(profile);
        for (final String rootDN : adRootDNList) {
            returnMap.put(rootDN, true);
        }
    } else {
        final Map<String, Map<String, List<String>>> results;
        {
            final SearchHelper searchHelper = new SearchHelper();
            searchHelper.setFilter("(objectclass=*)");
            searchHelper.setMaxResults(getMaxSizeLimit());
            searchHelper.setAttributes("subordinateCount");
            searchHelper.setSearchScope(SearchScope.ONE);
            results = chaiProvider.searchMultiValues(dn, searchHelper);
        }
        for (final Map.Entry<String, Map<String, List<String>>> entry : results.entrySet()) {
            final String resultDN = entry.getKey();
            final Map<String, List<String>> attributeResults = entry.getValue();
            boolean hasSubs = false;
            if (attributeResults.containsKey("subordinateCount")) {
                // only eDir actually returns this operational attribute
                final Integer subordinateCount = Integer.parseInt(attributeResults.get("subordinateCount").iterator().next());
                hasSubs = subordinateCount > 0;
            } else {
                final SearchHelper searchHelper = new SearchHelper();
                searchHelper.setFilter("(objectclass=*)");
                searchHelper.setMaxResults(1);
                searchHelper.setAttributes(Collections.emptyList());
                searchHelper.setSearchScope(SearchScope.ONE);
                try {
                    final Map<String, Map<String, String>> subSearchResults = chaiProvider.search(resultDN, searchHelper);
                    hasSubs = !subSearchResults.isEmpty();
                } catch (Exception e) {
                    LOGGER.debug("error during subordinate entry count of " + dn + ", error: " + e.getMessage());
                }
            }
            returnMap.put(resultDN, hasSubs);
        }
    }
    return returnMap;
}
Also used : HashMap(java.util.HashMap) SearchHelper(com.novell.ldapchai.util.SearchHelper) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 50 with ChaiUnavailableException

use of com.novell.ldapchai.exception.ChaiUnavailableException in project pwm by pwm-project.

the class PwNotifyDbStorageService method writeStoredState.

public void writeStoredState(final UserIdentity userIdentity, final SessionLabel sessionLabel, final StoredNotificationState storedNotificationState) throws PwmUnrecoverableException {
    final String guid;
    try {
        guid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, sessionLabel, userIdentity, true);
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(PwmUnrecoverableException.fromChaiException(e).getErrorInformation());
    }
    if (StringUtil.isEmpty(guid)) {
        throw new PwmUnrecoverableException(PwmError.ERROR_MISSING_GUID);
    }
    final String rawDbValue = JsonUtil.serialize(storedNotificationState);
    try {
        pwmApplication.getDatabaseAccessor().put(TABLE, guid, rawDbValue);
    } catch (DatabaseException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, e.getMessage()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseException(password.pwm.util.db.DatabaseException)

Aggregations

ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)76 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)51 ErrorInformation (password.pwm.error.ErrorInformation)37 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)32 PwmOperationalException (password.pwm.error.PwmOperationalException)25 IOException (java.io.IOException)22 ChaiUser (com.novell.ldapchai.ChaiUser)20 PwmException (password.pwm.error.PwmException)16 UserIdentity (password.pwm.bean.UserIdentity)15 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)13 PwmApplication (password.pwm.PwmApplication)12 LinkedHashMap (java.util.LinkedHashMap)11 ServletException (javax.servlet.ServletException)10 Configuration (password.pwm.config.Configuration)10 Instant (java.time.Instant)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FormConfiguration (password.pwm.config.value.data.FormConfiguration)7 ChaiException (com.novell.ldapchai.exception.ChaiException)6