Search in sources :

Example 36 with ChaiUnavailableException

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

the class AdminServlet method downloadUserReportCsv.

@ActionHandler(action = "downloadUserReportCsv")
private ProcessStatus downloadUserReportCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmApplication.getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_USER_REPORT_RECORDS_CSV));
    final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
    try {
        final String selectedColumns = pwmRequest.readParameterAsString("selectedColumns", "");
        final ReportColumnFilter columnFilter = ReportUtils.toReportColumnFilter(selectedColumns);
        final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
        reportCsvUtility.outputToCsv(outputStream, true, pwmRequest.getLocale(), columnFilter);
    } catch (Exception e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        pwmRequest.respondWithError(errorInformation);
    } finally {
        outputStream.close();
    }
    return ProcessStatus.Halt;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) OutputStream(java.io.OutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) ReportColumnFilter(password.pwm.svc.report.ReportColumnFilter) LocalDBException(password.pwm.util.localdb.LocalDBException) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) DatabaseException(password.pwm.util.db.DatabaseException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 37 with ChaiUnavailableException

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

the class ActivateUserUtils method sendPostActivationSms.

static boolean sendPostActivationSms(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final Configuration config = pwmApplication.getConfig();
    final UserInfo userInfo = pwmSession.getUserInfo();
    final Locale locale = pwmSession.getSessionStateBean().getLocale();
    final LdapProfile ldapProfile = userInfo.getUserIdentity().getLdapProfile(config);
    final String message = config.readSettingAsLocalizedString(PwmSetting.SMS_ACTIVATION_TEXT, locale);
    final String toSmsNumber;
    try {
        toSmsNumber = userInfo.readStringAttribute(ldapProfile.readSettingAsString(PwmSetting.SMS_USER_PHONE_ATTRIBUTE));
    } catch (Exception e) {
        LOGGER.debug(pwmSession.getLabel(), "error reading SMS attribute from user '" + pwmSession.getUserInfo().getUserIdentity() + "': " + e.getMessage());
        return false;
    }
    if (toSmsNumber == null || toSmsNumber.length() < 1) {
        LOGGER.debug(pwmSession.getLabel(), "skipping send activation SMS for '" + pwmSession.getUserInfo().getUserIdentity() + "' no SMS number configured");
        return false;
    }
    pwmApplication.sendSmsUsingQueue(toSmsNumber, message, pwmRequest.getSessionLabel(), pwmSession.getSessionManager().getMacroMachine(pwmApplication));
    return true;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) UserInfo(password.pwm.ldap.UserInfo) PwmSession(password.pwm.http.PwmSession) LdapProfile(password.pwm.config.profile.LdapProfile) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ImpossiblePasswordPolicyException(com.novell.ldapchai.exception.ImpossiblePasswordPolicyException) PwmDataValidationException(password.pwm.error.PwmDataValidationException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Example 38 with ChaiUnavailableException

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

the class NewUserProfile method getNewUserPasswordPolicy.

public PwmPasswordPolicy getNewUserPasswordPolicy(final PwmApplication pwmApplication, final Locale userLocale) throws PwmUnrecoverableException {
    final Configuration config = pwmApplication.getConfig();
    final long maxNewUserCacheMS = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_NEWUSER_PASSWORD_POLICY_CACHE_MS));
    if (newUserPasswordPolicyCacheTime != null && TimeDuration.fromCurrent(newUserPasswordPolicyCacheTime).isLongerThan(maxNewUserCacheMS)) {
        newUserPasswordPolicyCacheTime = Instant.now();
        newUserPasswordPolicyCache.clear();
    }
    final PwmPasswordPolicy cachedPolicy = newUserPasswordPolicyCache.get(userLocale);
    if (cachedPolicy != null) {
        return cachedPolicy;
    }
    final PwmPasswordPolicy thePolicy;
    final LdapProfile defaultLdapProfile = config.getDefaultLdapProfile();
    final String configuredNewUserPasswordDN = readSettingAsString(PwmSetting.NEWUSER_PASSWORD_POLICY_USER);
    if (configuredNewUserPasswordDN == null || configuredNewUserPasswordDN.length() < 1) {
        final String errorMsg = "the setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(this.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " must have a value";
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorMsg));
    } else {
        final String lookupDN;
        if ("TESTUSER".equalsIgnoreCase(configuredNewUserPasswordDN)) {
            lookupDN = defaultLdapProfile.readSettingAsString(PwmSetting.LDAP_TEST_USER_DN);
            if (lookupDN == null || lookupDN.isEmpty()) {
                final String errorMsg = "setting " + PwmSetting.LDAP_TEST_USER_DN.toMenuLocationDebug(defaultLdapProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " must be configured since setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(this.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " is set to TESTUSER";
                throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorMsg));
            }
        } else {
            lookupDN = configuredNewUserPasswordDN;
        }
        if (lookupDN.isEmpty()) {
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "user ldap dn in setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE) + " can not be resolved"));
        } else {
            try {
                final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider(defaultLdapProfile.getIdentifier());
                final ChaiUser chaiUser = chaiProvider.getEntryFactory().newChaiUser(lookupDN);
                final UserIdentity userIdentity = new UserIdentity(lookupDN, defaultLdapProfile.getIdentifier());
                thePolicy = PasswordUtility.readPasswordPolicyForUser(pwmApplication, null, userIdentity, chaiUser, userLocale);
            } catch (ChaiUnavailableException e) {
                throw new PwmUnrecoverableException(PwmError.forChaiError(e.getErrorCode()));
            }
        }
    }
    newUserPasswordPolicyCache.put(userLocale, thePolicy);
    return thePolicy;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Configuration(password.pwm.config.Configuration) StoredConfiguration(password.pwm.config.stored.StoredConfiguration) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 39 with ChaiUnavailableException

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

the class PeopleSearchDataReader method readUserMultiAttributeValues.

private List<String> readUserMultiAttributeValues(final PwmRequest pwmRequest, final UserIdentity userIdentity, final String attributeName) throws PwmUnrecoverableException {
    final List<String> returnObj = new ArrayList<>();
    final int maxValues = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.PEOPLESEARCH_VALUE_MAXCOUNT));
    final ChaiUser chaiUser = getChaiUser(userIdentity);
    try {
        final Set<String> ldapValues = chaiUser.readMultiStringAttribute(attributeName);
        if (ldapValues != null) {
            returnObj.addAll(ldapValues);
        }
        while (returnObj.size() > maxValues) {
            returnObj.remove(returnObj.size() - 1);
        }
        return Collections.unmodifiableList(returnObj);
    } catch (ChaiOperationException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, "error reading attribute value '" + attributeName + "', error:" + e.getMessage()));
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, e.getMessage()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 40 with ChaiUnavailableException

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

the class PeopleSearchDataReader method readUserDNAttributeValues.

private List<UserIdentity> readUserDNAttributeValues(final UserIdentity userIdentity, final String attributeName) throws PwmUnrecoverableException {
    final List<UserIdentity> returnObj = new ArrayList<>();
    final int maxValues = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.PEOPLESEARCH_VALUE_MAXCOUNT));
    final ChaiUser chaiUser = getChaiUser(userIdentity);
    final Set<String> ldapValues;
    try {
        ldapValues = chaiUser.readMultiStringAttribute(attributeName);
    } catch (ChaiOperationException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, "error reading attribute value '" + attributeName + "', error:" + e.getMessage()));
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, e.getMessage()));
    }
    final boolean checkUserDNValues = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.PEOPLESEARCH_MAX_VALUE_VERIFYUSERDN));
    for (final String userDN : ldapValues) {
        final UserIdentity loopIdentity = new UserIdentity(userDN, userIdentity.getLdapProfileID());
        if (returnObj.size() < maxValues) {
            try {
                if (checkUserDNValues) {
                    checkIfUserIdentityViewable(loopIdentity);
                }
                returnObj.add(loopIdentity);
            } catch (PwmOperationalException e) {
                LOGGER.debug(pwmRequest, "discarding userDN " + userDN + " from attribute " + attributeName + " because it does not match search filter");
            }
        } else {
            LOGGER.trace(pwmRequest, "discarding userDN " + userDN + " from attribute " + attributeName + " because maximum value count has been reached");
        }
    }
    return returnObj;
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) UserIdentity(password.pwm.bean.UserIdentity) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

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