Search in sources :

Example 36 with ChaiOperationException

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);
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LdapProfile(password.pwm.config.profile.LdapProfile) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 37 with ChaiOperationException

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;
}
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 38 with ChaiOperationException

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());
            }
        }
    }
}
Also used : ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) SchemaParser(com.novell.ldap.client.SchemaParser)

Example 39 with ChaiOperationException

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);
    }
}
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 40 with ChaiOperationException

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));
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LdapProfile(password.pwm.config.profile.LdapProfile) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)66 ErrorInformation (password.pwm.error.ErrorInformation)31 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)28 ChaiUser (com.novell.ldapchai.ChaiUser)24 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Map (java.util.Map)12 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)11 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 PwmApplication (password.pwm.PwmApplication)10 LdapProfile (password.pwm.config.profile.LdapProfile)10 FormConfiguration (password.pwm.config.value.data.FormConfiguration)9 List (java.util.List)8 PwmSession (password.pwm.http.PwmSession)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ChaiPasswordPolicyException (com.novell.ldapchai.exception.ChaiPasswordPolicyException)6 Instant (java.time.Instant)6