Search in sources :

Example 36 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project pwm by pwm-project.

the class UpdateProfileServlet method nextStep.

protected void nextStep(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
    final UpdateProfileProfile updateProfileProfile = getProfile(pwmRequest);
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    {
        final String updateProfileAgreementText = updateProfileProfile.readSettingAsLocalizedString(PwmSetting.UPDATE_PROFILE_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
        if (!StringUtil.isEmpty(updateProfileAgreementText)) {
            if (!updateProfileBean.isAgreementPassed()) {
                final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
                final String expandedText = macroMachine.expandMacros(updateProfileAgreementText);
                pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
                pwmRequest.forwardToJsp(JspUrl.UPDATE_ATTRIBUTES_AGREEMENT);
                return;
            }
        }
    }
    // make sure there is form data in the bean.
    if (!updateProfileBean.isFormLdapLoaded()) {
        updateProfileBean.getFormData().clear();
        updateProfileBean.getFormData().putAll((UpdateProfileUtil.formDataFromLdap(pwmRequest, updateProfileProfile)));
        updateProfileBean.setFormLdapLoaded(true);
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    if (!updateProfileBean.isFormSubmitted()) {
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    // validate the form data.
    try {
        // verify form meets the form requirements
        final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
        final Map<FormConfiguration, String> formValues = FormUtility.readFormValuesFromMap(updateProfileBean.getFormData(), formFields, pwmRequest.getLocale());
        UpdateProfileUtil.verifyFormAttributes(pwmRequest.getPwmApplication(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getLocale(), formValues, true);
    } catch (PwmException e) {
        LOGGER.error(pwmSession, e.getMessage());
        setLastError(pwmRequest, e.getErrorInformation());
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    {
        final boolean requireConfirmation = updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_SHOW_CONFIRMATION);
        if (requireConfirmation && !updateProfileBean.isConfirmationPassed()) {
            UpdateProfileUtil.forwardToConfirmForm(pwmRequest, updateProfileProfile, updateProfileBean);
            return;
        }
    }
    if (UpdateProfileUtil.checkForTokenVerificationProgress(pwmRequest, updateProfileBean, updateProfileProfile) == ProcessStatus.Halt) {
        return;
    }
    try {
        // write the form values
        final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
        UpdateProfileUtil.doProfileUpdate(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getLocale(), pwmSession.getUserInfo(), pwmSession.getSessionManager().getMacroMachine(pwmApplication), updateProfileProfile, updateProfileBean.getFormData(), theUser);
        // re-populate the uiBean because we have changed some values.
        pwmSession.reloadUserInfoBean(pwmApplication);
        // clear cached read attributes.
        pwmRequest.getPwmSession().reloadUserInfoBean(pwmApplication);
        // mark the event log
        pwmApplication.getAuditManager().submit(AuditEvent.UPDATE_PROFILE, pwmSession.getUserInfo(), pwmSession);
        // clear the bean
        pwmApplication.getSessionStateService().clearBean(pwmRequest, UpdateProfileBean.class);
        pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_UpdateProfile);
        return;
    } catch (PwmException e) {
        LOGGER.error(pwmSession, e.getMessage());
        setLastError(pwmRequest, e.getErrorInformation());
    } catch (ChaiException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UPDATE_ATTRS_FAILURE, e.toString());
        LOGGER.error(pwmSession, errorInformation.toDebugStr());
        setLastError(pwmRequest, errorInformation);
    }
    UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
}
Also used : PwmApplication(password.pwm.PwmApplication) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration) PwmSession(password.pwm.http.PwmSession) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 37 with ChaiUser

use of com.novell.ldapchai.ChaiUser 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)

Example 38 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project pwm by pwm-project.

the class LdapTokenMachine method storeToken.

public void storeToken(final TokenKey tokenKey, final TokenPayload tokenPayload) throws PwmOperationalException, PwmUnrecoverableException {
    try {
        final String md5sumToken = tokenKey.getStoredHash();
        final String encodedTokenPayload = tokenService.toEncryptedString(tokenPayload);
        final UserIdentity userIdentity = tokenPayload.getUserIdentity();
        final ChaiUser chaiUser = pwmApplication.getProxiedChaiUser(userIdentity);
        chaiUser.writeStringAttribute(tokenAttribute, md5sumToken + KEY_VALUE_DELIMITER + encodedTokenPayload);
    } catch (ChaiException e) {
        final String errorMsg = "unexpected ldap error saving token: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmOperationalException(errorInformation);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 39 with ChaiUser

use of com.novell.ldapchai.ChaiUser in project pwm by pwm-project.

the class ExportResponsesCommand method doCommand.

@Override
void doCommand() throws Exception {
    final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    JavaHelper.pause(2000);
    final long startTime = System.currentTimeMillis();
    final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
    final SearchConfiguration searchConfiguration = SearchConfiguration.builder().enableValueEscaping(false).username("*").build();
    final String systemRecordDelimiter = System.getProperty("line.separator");
    final Writer writer = new BufferedWriter(new PrintWriter(outputFile, PwmConstants.DEFAULT_CHARSET.toString()));
    final Map<UserIdentity, Map<String, String>> results = userSearchEngine.performMultiUserSearch(searchConfiguration, Integer.MAX_VALUE, Collections.emptyList(), SessionLabel.SYSTEM_LABEL);
    out("searching " + results.size() + " users for stored responses to write to " + outputFile.getAbsolutePath() + "....");
    int counter = 0;
    for (final UserIdentity identity : results.keySet()) {
        final ChaiUser user = pwmApplication.getProxiedChaiUser(identity);
        final ResponseSet responseSet = pwmApplication.getCrService().readUserResponseSet(null, identity, user);
        if (responseSet != null) {
            counter++;
            out("found responses for '" + user + "', writing to output.");
            final RestChallengesServer.JsonChallengesData outputData = new RestChallengesServer.JsonChallengesData();
            outputData.challenges = responseSet.asChallengeBeans(true);
            outputData.helpdeskChallenges = responseSet.asHelpdeskChallengeBeans(true);
            outputData.minimumRandoms = responseSet.getChallengeSet().minimumResponses();
            outputData.username = identity.toDelimitedKey();
            writer.write(JsonUtil.serialize(outputData));
            writer.write(systemRecordDelimiter);
        } else {
            out("skipping '" + user.toString() + "', no stored responses.");
        }
    }
    writer.close();
    out("output complete, " + counter + " responses exported in " + TimeDuration.fromCurrent(startTime).asCompactString());
}
Also used : PwmApplication(password.pwm.PwmApplication) UserSearchEngine(password.pwm.ldap.search.UserSearchEngine) UserIdentity(password.pwm.bean.UserIdentity) ResponseSet(com.novell.ldapchai.cr.ResponseSet) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) BufferedWriter(java.io.BufferedWriter) ChaiUser(com.novell.ldapchai.ChaiUser) RestChallengesServer(password.pwm.ws.server.rest.RestChallengesServer) File(java.io.File) Map(java.util.Map) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 40 with ChaiUser

use of com.novell.ldapchai.ChaiUser 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)

Aggregations

ChaiUser (com.novell.ldapchai.ChaiUser)69 ErrorInformation (password.pwm.error.ErrorInformation)38 UserIdentity (password.pwm.bean.UserIdentity)30 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)27 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 PwmOperationalException (password.pwm.error.PwmOperationalException)23 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)21 ChaiException (com.novell.ldapchai.exception.ChaiException)18 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)18 PwmApplication (password.pwm.PwmApplication)16 PwmSession (password.pwm.http.PwmSession)12 UserInfo (password.pwm.ldap.UserInfo)12 Instant (java.time.Instant)10 FormConfiguration (password.pwm.config.value.data.FormConfiguration)10 PasswordData (password.pwm.util.PasswordData)10 MacroMachine (password.pwm.util.macro.MacroMachine)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 LdapProfile (password.pwm.config.profile.LdapProfile)9 Locale (java.util.Locale)8