use of com.novell.ldapchai.exception.ChaiOperationException in project pwm by pwm-project.
the class LdapOperationsHelper method readPhotoDataFromLdap.
public static PhotoDataBean readPhotoDataFromLdap(final Configuration configuration, final ChaiUser chaiUser, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
final LdapProfile ldapProfile = userIdentity.getLdapProfile(configuration);
final String attribute = ldapProfile.readSettingAsString(PwmSetting.PEOPLE_SEARCH_PHOTO_ATTRIBUTE);
if (attribute == null || attribute.isEmpty()) {
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "ldap photo attribute is not configured"));
}
final byte[] photoData;
final String mimeType;
try {
final byte[][] photoAttributeData = chaiUser.readMultiByteAttribute(attribute);
if (photoAttributeData == null || photoAttributeData.length == 0 || photoAttributeData[0].length == 0) {
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "user has no photo data stored in LDAP attribute"));
}
photoData = photoAttributeData[0];
mimeType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(photoData));
} catch (IOException | ChaiOperationException e) {
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, "error reading user photo ldap attribute: " + e.getMessage()));
}
return new PhotoDataBean(mimeType, photoData);
}
use of com.novell.ldapchai.exception.ChaiOperationException 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.ChaiOperationException in project pwm by pwm-project.
the class EdirSchemaExtender method checkAttribute.
private void checkAttribute(final boolean readOnly, final SchemaDefinition schemaDefinition, final Map<String, SchemaParser> existingAttrs) throws ChaiUnavailableException {
final String name = schemaDefinition.getName();
if (existingAttrs.containsKey(name)) {
final SchemaParser existingValue = existingAttrs.get(name);
logActivity("attribute '" + name + "' exists");
final boolean attributeIsCorrect = checkAttributeCorrectness(schemaDefinition, existingValue);
stateMap.put(name, attributeIsCorrect ? SchemaDefinition.State.correct : SchemaDefinition.State.incorrect);
if (!readOnly && !attributeIsCorrect) {
logActivity("beginning update for attribute '" + name + "'");
try {
schemaEntry.replaceAttribute(LDAP_SCHEMA_ATTR_ATTRS, existingValue.getRawString(), schemaDefinition.getDefinition());
logActivity("+ attribute '" + name + "' has been modified");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while updating attribute definition '" + name + "', error: " + e.getMessage());
}
}
} else {
logActivity("attribute '" + name + "' does not exist");
if (!readOnly) {
logActivity("beginning add for attribute '" + name + "'");
try {
schemaEntry.addAttribute(LDAP_SCHEMA_ATTR_ATTRS, schemaDefinition.getDefinition());
stateMap.put(name, SchemaDefinition.State.missing);
logActivity("+ attribute '" + name + "' has been added");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while adding attribute definition '" + name + "', error: " + e.getMessage());
}
}
}
}
use of com.novell.ldapchai.exception.ChaiOperationException 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.ChaiOperationException in project pwm by pwm-project.
the class UserSearchEngine method resolveUserDN.
private UserIdentity resolveUserDN(final String userDN) throws PwmUnrecoverableException, ChaiUnavailableException, PwmOperationalException {
final Collection<LdapProfile> ldapProfiles = pwmApplication.getConfig().getLdapProfiles().values();
for (final LdapProfile ldapProfile : ldapProfiles) {
final ChaiProvider provider = pwmApplication.getProxyChaiProvider(ldapProfile.getIdentifier());
final ChaiUser user = provider.getEntryFactory().newChaiUser(userDN);
if (user.exists()) {
try {
return new UserIdentity(user.readCanonicalDN(), ldapProfile.getIdentifier());
} catch (ChaiOperationException e) {
LOGGER.error("unexpected error reading canonical userDN for '" + userDN + "', error: " + e.getMessage());
}
}
}
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_CANT_MATCH_USER));
}
Aggregations