Search in sources :

Example 1 with CrService

use of password.pwm.util.operations.CrService 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 2 with CrService

use of password.pwm.util.operations.CrService in project pwm by pwm-project.

the class HelpdeskServlet method restClearResponsesHandler.

@ActionHandler(action = "clearResponses")
private ProcessStatus restClearResponsesHandler(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException, ChaiUnavailableException, PwmOperationalException {
    final UserIdentity userIdentity;
    try {
        userIdentity = readUserKeyRequestParameter(pwmRequest);
    } catch (PwmUnrecoverableException e) {
        pwmRequest.outputJsonResult(RestResultBean.fromError(e.getErrorInformation()));
        return ProcessStatus.Halt;
    }
    final HelpdeskProfile helpdeskProfile = pwmRequest.getPwmSession().getSessionManager().getHelpdeskProfile(pwmRequest.getPwmApplication());
    HelpdeskServletUtil.checkIfUserIdentityViewable(pwmRequest, helpdeskProfile, userIdentity);
    {
        final boolean buttonEnabled = helpdeskProfile.readSettingAsBoolean(PwmSetting.HELPDESK_CLEAR_RESPONSES_BUTTON);
        final HelpdeskClearResponseMode mode = helpdeskProfile.readSettingAsEnum(PwmSetting.HELPDESK_CLEAR_RESPONSES, HelpdeskClearResponseMode.class);
        if (!buttonEnabled && (mode == HelpdeskClearResponseMode.no)) {
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_SECURITY_VIOLATION, "setting " + PwmSetting.HELPDESK_CLEAR_RESPONSES_BUTTON.toMenuLocationDebug(helpdeskProfile.getIdentifier(), pwmRequest.getLocale()) + " must be enabled or setting " + PwmSetting.HELPDESK_CLEAR_RESPONSES.toMenuLocationDebug(helpdeskProfile.getIdentifier(), pwmRequest.getLocale()) + "must be set to yes or ask"));
        }
    }
    final ChaiUser chaiUser = getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
    final String userGUID = LdapOperationsHelper.readLdapGuidValue(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession().getLabel(), userIdentity, true);
    final CrService crService = pwmRequest.getPwmApplication().getCrService();
    crService.clearResponses(pwmRequest.getPwmSession().getLabel(), userIdentity, chaiUser, userGUID);
    // mark the event log
    {
        final HelpdeskAuditRecord auditRecord = new AuditRecordFactory(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession()).createHelpdeskAuditRecord(AuditEvent.HELPDESK_CLEAR_RESPONSES, pwmRequest.getPwmSession().getUserInfo().getUserIdentity(), null, userIdentity, pwmRequest.getPwmSession().getSessionStateBean().getSrcAddress(), pwmRequest.getPwmSession().getSessionStateBean().getSrcHostname());
        pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
    }
    final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) ChaiUser(com.novell.ldapchai.ChaiUser) HelpdeskClearResponseMode(password.pwm.config.option.HelpdeskClearResponseMode) UserIdentity(password.pwm.bean.UserIdentity) HelpdeskProfile(password.pwm.config.profile.HelpdeskProfile) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) CrService(password.pwm.util.operations.CrService) HelpdeskAuditRecord(password.pwm.svc.event.HelpdeskAuditRecord) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 3 with CrService

use of password.pwm.util.operations.CrService in project pwm by pwm-project.

the class RestChallengesServer method doSetChallengeDataJson.

@RestMethodHandler(method = HttpMethod.POST, consumes = HttpContentType.json, produces = HttpContentType.json)
public RestResultBean doSetChallengeDataJson(final RestRequest restRequest) throws IOException, PwmUnrecoverableException {
    final JsonChallengesData jsonInput = RestUtility.deserializeJsonBody(restRequest, JsonChallengesData.class);
    final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInput.getUsername());
    try {
        final ChaiUser chaiUser;
        final String userGUID;
        final String csIdentifer;
        final UserIdentity userIdentity;
        final CrService crService = restRequest.getPwmApplication().getCrService();
        userIdentity = targetUserIdentity.getUserIdentity();
        chaiUser = targetUserIdentity.getChaiUser();
        userGUID = LdapOperationsHelper.readLdapGuidValue(restRequest.getPwmApplication(), restRequest.getSessionLabel(), userIdentity, false);
        final ChallengeProfile challengeProfile = crService.readUserChallengeProfile(restRequest.getSessionLabel(), userIdentity, chaiUser, PwmPasswordPolicy.defaultPolicy(), restRequest.getLocale());
        csIdentifer = challengeProfile.getChallengeSet().getIdentifier();
        final ResponseInfoBean responseInfoBean = jsonInput.toResponseInfoBean(restRequest.getLocale(), csIdentifer);
        crService.writeResponses(userIdentity, chaiUser, userGUID, responseInfoBean);
        // update statistics
        StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_CHALLENGES);
        return RestResultBean.forSuccessMessage(restRequest, Message.Success_SetupResponse);
    } catch (Exception e) {
        final String errorMsg = "unexpected error reading json input: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) ChallengeProfile(password.pwm.config.profile.ChallengeProfile) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) CrService(password.pwm.util.operations.CrService) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 4 with CrService

use of password.pwm.util.operations.CrService in project pwm by pwm-project.

the class RestChallengesServer method doFormGetChallengeData.

@RestMethodHandler(method = HttpMethod.GET, produces = HttpContentType.json)
public RestResultBean doFormGetChallengeData(final RestRequest restRequest) throws PwmUnrecoverableException {
    final boolean answers = restRequest.readParameterAsBoolean("answers");
    final boolean helpdesk = restRequest.readParameterAsBoolean("helpdesk");
    final String username = restRequest.readParameterAsString(FIELD_USERNAME, PwmHttpRequestWrapper.Flag.BypassValidation);
    try {
        if (answers && !restRequest.getPwmApplication().getConfig().readSettingAsBoolean(PwmSetting.ENABLE_WEBSERVICES_READANSWERS)) {
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "retrieval of answers is not permitted"));
        }
        final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
        // gather data
        final ResponseSet responseSet;
        final ChallengeSet challengeSet;
        final ChallengeSet helpdeskChallengeSet;
        final String outputUsername;
        final ChaiUser chaiUser = targetUserIdentity.getChaiUser();
        final Locale userLocale = restRequest.getLocale();
        final CrService crService = restRequest.getPwmApplication().getCrService();
        responseSet = crService.readUserResponseSet(restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), chaiUser);
        final PwmPasswordPolicy passwordPolicy = PasswordUtility.readPasswordPolicyForUser(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), chaiUser, userLocale);
        final ChallengeProfile challengeProfile = crService.readUserChallengeProfile(restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), chaiUser, passwordPolicy, userLocale);
        challengeSet = challengeProfile.getChallengeSet();
        helpdeskChallengeSet = challengeProfile.getHelpdeskChallengeSet();
        outputUsername = targetUserIdentity.getUserIdentity().toDelimitedKey();
        // build output
        final JsonChallengesData jsonData = new JsonChallengesData();
        {
            jsonData.username = outputUsername;
            if (responseSet != null) {
                jsonData.challenges = responseSet.asChallengeBeans(answers);
                if (helpdesk) {
                    jsonData.helpdeskChallenges = responseSet.asHelpdeskChallengeBeans(answers);
                }
                jsonData.minimumRandoms = responseSet.getChallengeSet().getMinRandomRequired();
            }
            final Policy policy = new Policy();
            if (challengeSet != null) {
                policy.challenges = challengesToBeans(challengeSet.getChallenges());
                policy.minimumRandoms = challengeSet.getMinRandomRequired();
            }
            if (helpdeskChallengeSet != null && helpdesk) {
                policy.helpdeskChallenges = challengesToBeans(helpdeskChallengeSet.getChallenges());
            }
            if (policy.challenges != null || policy.helpdeskChallenges != null) {
                jsonData.policy = policy;
            }
        }
        // update statistics
        StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_CHALLENGES);
        return RestResultBean.withData(jsonData);
    } catch (ChaiException e) {
        final String errorMsg = "unexpected error building json response: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : Locale(java.util.Locale) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) ChallengeSet(com.novell.ldapchai.cr.ChallengeSet) ChallengeProfile(password.pwm.config.profile.ChallengeProfile) ResponseSet(com.novell.ldapchai.cr.ResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) CrService(password.pwm.util.operations.CrService) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) ChaiException(com.novell.ldapchai.exception.ChaiException) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 5 with CrService

use of password.pwm.util.operations.CrService in project pwm by pwm-project.

the class UserInfoReader method getChallengeProfile.

@Override
public ChallengeProfile getChallengeProfile() throws PwmUnrecoverableException {
    final PwmPasswordPolicy pwmPasswordPolicy = selfCachedReference.getPasswordPolicy();
    final CrService crService = pwmApplication.getCrService();
    return crService.readUserChallengeProfile(sessionLabel, getUserIdentity(), chaiUser, pwmPasswordPolicy, locale);
}
Also used : PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) CrService(password.pwm.util.operations.CrService)

Aggregations

CrService (password.pwm.util.operations.CrService)6 ChaiUser (com.novell.ldapchai.ChaiUser)4 ErrorInformation (password.pwm.error.ErrorInformation)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 ChaiException (com.novell.ldapchai.exception.ChaiException)3 UserIdentity (password.pwm.bean.UserIdentity)3 IOException (java.io.IOException)2 ResponseInfoBean (password.pwm.bean.ResponseInfoBean)2 ChallengeProfile (password.pwm.config.profile.ChallengeProfile)2 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 RestMethodHandler (password.pwm.ws.server.RestMethodHandler)2 ChallengeSet (com.novell.ldapchai.cr.ChallengeSet)1 ResponseSet (com.novell.ldapchai.cr.ResponseSet)1 Locale (java.util.Locale)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 HelpdeskClearResponseMode (password.pwm.config.option.HelpdeskClearResponseMode)1 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)1 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)1