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