Search in sources :

Example 1 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean in project pwm by pwm-project.

the class CrService method readUserResponseInfo.

public ResponseInfoBean readUserResponseInfo(final SessionLabel sessionLabel, final UserIdentity userIdentity, final ChaiUser theUser) throws ChaiUnavailableException, PwmUnrecoverableException {
    final Configuration config = pwmApplication.getConfig();
    LOGGER.trace(sessionLabel, "beginning read of user response sequence");
    final List<DataStorageMethod> readPreferences = config.helper().getCrReadPreference();
    final String debugMsg = "will attempt to read the following storage methods: " + JsonUtil.serializeCollection(readPreferences) + " for response info for user " + theUser.getEntryDN();
    LOGGER.debug(sessionLabel, debugMsg);
    final String userGUID;
    if (readPreferences.contains(DataStorageMethod.DB) || readPreferences.contains(DataStorageMethod.LOCALDB)) {
        userGUID = LdapOperationsHelper.readLdapGuidValue(pwmApplication, sessionLabel, userIdentity, false);
    } else {
        userGUID = null;
    }
    for (final DataStorageMethod storageMethod : readPreferences) {
        final ResponseInfoBean readResponses;
        LOGGER.trace(sessionLabel, "attempting read of response info via storage method: " + storageMethod);
        readResponses = operatorMap.get(storageMethod).readResponseInfo(theUser, userIdentity, userGUID);
        if (readResponses != null) {
            LOGGER.debug(sessionLabel, "returning response info read via method " + storageMethod + " for user " + theUser.getEntryDN());
            return readResponses;
        } else {
            LOGGER.trace(sessionLabel, "no responses info read using method " + storageMethod);
        }
    }
    LOGGER.debug(sessionLabel, "no response info found for user " + theUser.getEntryDN());
    return null;
}
Also used : Configuration(password.pwm.config.Configuration) DataStorageMethod(password.pwm.config.option.DataStorageMethod) ResponseInfoBean(password.pwm.bean.ResponseInfoBean)

Example 2 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean in project pwm by pwm-project.

the class ResponseStatsCommand method makeStatistics.

ResponseStats makeStatistics(final PwmApplication pwmApplication, final List<UserIdentity> userIdentities) throws PwmUnrecoverableException, ChaiUnavailableException {
    final ResponseStats responseStats = new ResponseStats();
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            out("processing...  " + userCounter + " users read");
        }
    }, 30 * 1000, 30 * 1000);
    final CrService crService = pwmApplication.getCrService();
    for (final UserIdentity userIdentity : userIdentities) {
        userCounter++;
        final ResponseInfoBean responseInfoBean = crService.readUserResponseInfo(null, userIdentity, pwmApplication.getProxiedChaiUser(userIdentity));
        makeStatistics(responseStats, responseInfoBean);
    }
    timer.cancel();
    return responseStats;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) UserIdentity(password.pwm.bean.UserIdentity) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) CrService(password.pwm.util.operations.CrService)

Example 3 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean in project pwm by pwm-project.

the class NMASCrOperator method readResponseInfo.

@Override
public ResponseInfoBean readResponseInfo(final ChaiUser theUser, final UserIdentity userIdentity, final String userGUID) throws PwmUnrecoverableException {
    try {
        if (theUser.getChaiProvider().getDirectoryVendor() != DirectoryVendor.EDIRECTORY) {
            LOGGER.debug("skipping request to read NMAS responses for " + userIdentity + ", directory type is not eDirectory");
            return null;
        }
        final ResponseSet responseSet = NmasCrFactory.readNmasResponseSet(theUser);
        if (responseSet == null) {
            return null;
        }
        final ResponseInfoBean responseInfoBean = CrOperators.convertToNoAnswerInfoBean(responseSet, DataStorageMethod.NMAS);
        responseInfoBean.setTimestamp(null);
        return responseInfoBean;
    } catch (ChaiException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_RESPONSES_NORESPONSES, "unexpected error reading response info " + e.getMessage()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ResponseSet(com.novell.ldapchai.cr.ResponseSet) NmasResponseSet(com.novell.ldapchai.impl.edir.NmasResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 4 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean in project pwm by pwm-project.

the class HelpdeskDetailInfoBean method makeHelpdeskDetailInfo.

static HelpdeskDetailInfoBean makeHelpdeskDetailInfo(final PwmRequest pwmRequest, final HelpdeskProfile helpdeskProfile, final UserIdentity userIdentity) throws PwmUnrecoverableException, ChaiUnavailableException {
    final HelpdeskDetailInfoBeanBuilder builder = HelpdeskDetailInfoBean.builder();
    final Instant startTime = Instant.now();
    LOGGER.trace(pwmRequest, "beginning to assemble detail data report for user " + userIdentity);
    final Locale actorLocale = pwmRequest.getLocale();
    final ChaiUser theUser = HelpdeskServlet.getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
    if (!theUser.exists()) {
        return null;
    }
    final UserInfo userInfo = UserInfoFactory.newUserInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), actorLocale, userIdentity, theUser.getChaiProvider());
    final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, null);
    try {
        final List<AccountInformationBean.ActivityRecord> userHistory = AccountInformationBean.makeAuditInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, pwmRequest.getLocale());
        builder.userHistory(userHistory);
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "unexpected error reading userHistory for user '" + userIdentity + "', " + e.getMessage());
    }
    builder.userKey(userIdentity.toObfuscatedKey(pwmRequest.getPwmApplication()));
    builder.profileData(getProfileData(helpdeskProfile, userInfo, pwmRequest.getSessionLabel(), pwmRequest.getLocale()));
    builder.passwordPolicyRules(makePasswordPolicyRules(userInfo, pwmRequest.getLocale(), pwmRequest.getConfig()));
    {
        final List<String> requirementLines = PasswordRequirementsTag.getPasswordRequirementsStrings(userInfo.getPasswordPolicy(), pwmRequest.getConfig(), pwmRequest.getLocale(), macroMachine);
        builder.passwordRequirements(Collections.unmodifiableList(requirementLines));
    }
    if ((userInfo.getPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN() != null)) {
        builder.passwordPolicyDN(userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN());
    } else {
        builder.passwordPolicyDN(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    if ((userInfo.getPasswordPolicy() != null) && userInfo.getPasswordPolicy().getIdentifier() != null) {
        builder.passwordPolicyID(userInfo.getPasswordPolicy().getIdentifier());
    } else {
        builder.passwordPolicyID(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    {
        final ResponseInfoBean responseInfoBean = userInfo.getResponseInfoBean();
        if (responseInfoBean != null && responseInfoBean.getHelpdeskCrMap() != null) {
            final List<DisplayElement> responseDisplay = new ArrayList<>();
            int counter = 0;
            for (final Map.Entry<Challenge, String> entry : responseInfoBean.getHelpdeskCrMap().entrySet()) {
                counter++;
                responseDisplay.add(new DisplayElement("item_" + counter, DisplayElement.Type.string, entry.getKey().getChallengeText(), entry.getValue()));
            }
            builder.helpdeskResponses = responseDisplay;
        }
    }
    builder.userDisplayName(HelpdeskCardInfoBean.figureDisplayName(helpdeskProfile, macroMachine));
    final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
    {
        final Set<ViewStatusFields> viewStatusFields = helpdeskProfile.readSettingAsOptionList(PwmSetting.HELPDESK_VIEW_STATUS_VALUES, ViewStatusFields.class);
        builder.statusData(ViewableUserInfoDisplayReader.makeDisplayData(viewStatusFields, pwmRequest.getConfig(), userInfo, null, pwmRequest.getLocale()));
    }
    {
        final Set<HelpdeskDetailInfoBean.StandardButton> visibleButtons = determineVisibleButtons(helpdeskProfile);
        builder.visibleButtons(visibleButtons);
        builder.enabledButtons(determineEnabledButtons(visibleButtons, userInfo));
        builder.customButtons(determineCustomButtons(helpdeskProfile));
    }
    final HelpdeskDetailInfoBean helpdeskDetailInfoBean = builder.build();
    if (pwmRequest.getConfig().isDevDebugMode()) {
        LOGGER.trace(pwmRequest, "completed assembly of detail data report for user " + userIdentity + " in " + timeDuration.asCompactString() + ", contents: " + JsonUtil.serialize(helpdeskDetailInfoBean));
    }
    return builder.build();
}
Also used : Locale(java.util.Locale) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Instant(java.time.Instant) ViewStatusFields(password.pwm.config.option.ViewStatusFields) UserInfo(password.pwm.ldap.UserInfo) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) DisplayElement(password.pwm.http.bean.DisplayElement) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) ArrayList(java.util.ArrayList) List(java.util.List) TimeDuration(password.pwm.util.java.TimeDuration)

Example 5 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean in project pwm by pwm-project.

the class SetupResponsesServlet method nextStep.

@Override
protected void nextStep(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
    final SetupResponsesBean setupResponsesBean = getSetupResponseBean(pwmRequest);
    initializeBean(pwmRequest, setupResponsesBean);
    pwmRequest.setAttribute(PwmRequestAttribute.ModuleBean, setupResponsesBean);
    pwmRequest.setAttribute(PwmRequestAttribute.ModuleBean_String, pwmRequest.getPwmApplication().getSecureService().encryptObjectToString(setupResponsesBean));
    pwmRequest.setAttribute(PwmRequestAttribute.SetupResponses_ResponseInfo, pwmRequest.getPwmSession().getUserInfo().getResponseInfoBean());
    if (setupResponsesBean.isHasExistingResponses() && !pwmRequest.getPwmSession().getUserInfo().isRequiresResponseConfig()) {
        pwmRequest.forwardToJsp(JspUrl.SETUP_RESPONSES_EXISTING);
        return;
    }
    if (!setupResponsesBean.isResponsesSatisfied()) {
        pwmRequest.forwardToJsp(JspUrl.SETUP_RESPONSES);
        return;
    }
    if (!setupResponsesBean.isHelpdeskResponsesSatisfied()) {
        if (setupResponsesBean.getHelpdeskResponseData().getChallengeSet() == null || setupResponsesBean.getHelpdeskResponseData().getChallengeSet().getChallenges().isEmpty()) {
            setupResponsesBean.setHelpdeskResponsesSatisfied(true);
        } else {
            pwmRequest.forwardToJsp(JspUrl.SETUP_RESPONSES_HELPDESK);
            return;
        }
    }
    if (pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.CHALLENGE_SHOW_CONFIRMATION)) {
        if (!setupResponsesBean.isConfirmed()) {
            pwmRequest.forwardToJsp(JspUrl.SETUP_RESPONSES_CONFIRM);
            return;
        }
    }
    try {
        // everything good, so lets save responses.
        final ResponseInfoBean responses = generateResponseInfoBean(pwmRequest, setupResponsesBean.getResponseData().getChallengeSet(), setupResponsesBean.getResponseData().getResponseMap(), setupResponsesBean.getHelpdeskResponseData().getResponseMap());
        saveResponses(pwmRequest, responses);
        pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, SetupResponsesBean.class);
        pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_SetupResponse);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest.getSessionLabel(), e.getErrorInformation());
        pwmRequest.respondWithError(e.getErrorInformation());
    } catch (ChaiValidationException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_RANDOM_RESPONSE, e.getMessage());
        LOGGER.error(pwmRequest.getSessionLabel(), errorInformation);
        pwmRequest.respondWithError(errorInformation);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) SetupResponsesBean(password.pwm.http.bean.SetupResponsesBean) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

ResponseInfoBean (password.pwm.bean.ResponseInfoBean)8 ErrorInformation (password.pwm.error.ErrorInformation)4 ChaiUser (com.novell.ldapchai.ChaiUser)3 UserIdentity (password.pwm.bean.UserIdentity)3 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 ChaiException (com.novell.ldapchai.exception.ChaiException)2 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 ChallengeProfile (password.pwm.config.profile.ChallengeProfile)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 SetupResponsesBean (password.pwm.http.bean.SetupResponsesBean)2 CrService (password.pwm.util.operations.CrService)2 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)1 ChallengeSet (com.novell.ldapchai.cr.ChallengeSet)1 ResponseSet (com.novell.ldapchai.cr.ResponseSet)1 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)1 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1