Search in sources :

Example 6 with ResponseInfoBean

use of password.pwm.bean.ResponseInfoBean 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 7 with ResponseInfoBean

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

the class ImportResponsesCommand method doCommand.

@Override
void doCommand() throws Exception {
    final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
    final File inputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_EXISTING_INPUT_FILE.getName());
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), PwmConstants.DEFAULT_CHARSET.toString()))) {
        out("importing stored responses from " + inputFile.getAbsolutePath() + "....");
        int counter = 0;
        String line;
        final long startTime = System.currentTimeMillis();
        while ((line = reader.readLine()) != null) {
            counter++;
            final RestChallengesServer.JsonChallengesData inputData;
            inputData = JsonUtil.deserialize(line, RestChallengesServer.JsonChallengesData.class);
            final UserIdentity userIdentity = UserIdentity.fromDelimitedKey(inputData.username);
            final ChaiUser user = pwmApplication.getProxiedChaiUser(userIdentity);
            if (user.exists()) {
                out("writing responses to user '" + user.getEntryDN() + "'");
                try {
                    final ChallengeProfile challengeProfile = pwmApplication.getCrService().readUserChallengeProfile(null, userIdentity, user, PwmPasswordPolicy.defaultPolicy(), PwmConstants.DEFAULT_LOCALE);
                    final ChallengeSet challengeSet = challengeProfile.getChallengeSet();
                    final String userGuid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, null, userIdentity, false);
                    final ResponseInfoBean responseInfoBean = inputData.toResponseInfoBean(PwmConstants.DEFAULT_LOCALE, challengeSet.getIdentifier());
                    pwmApplication.getCrService().writeResponses(userIdentity, user, userGuid, responseInfoBean);
                } catch (Exception e) {
                    out("error writing responses to user '" + user.getEntryDN() + "', error: " + e.getMessage());
                    return;
                }
            } else {
                out("user '" + user.getEntryDN() + "' is not a valid userDN");
                return;
            }
        }
        out("output complete, " + counter + " responses imported in " + TimeDuration.fromCurrent(startTime).asCompactString());
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) ChallengeSet(com.novell.ldapchai.cr.ChallengeSet) InputStreamReader(java.io.InputStreamReader) UserIdentity(password.pwm.bean.UserIdentity) ChallengeProfile(password.pwm.config.profile.ChallengeProfile) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) FileInputStream(java.io.FileInputStream) ChaiUser(com.novell.ldapchai.ChaiUser) BufferedReader(java.io.BufferedReader) RestChallengesServer(password.pwm.ws.server.rest.RestChallengesServer) File(java.io.File)

Example 8 with ResponseInfoBean

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

the class SetupResponsesServlet method generateResponseInfoBean.

private static ResponseInfoBean generateResponseInfoBean(final PwmRequest pwmRequest, final ChallengeSet challengeSet, final Map<Challenge, String> readResponses, final Map<Challenge, String> helpdeskResponses) throws ChaiUnavailableException, PwmDataValidationException, PwmUnrecoverableException {
    final ChaiProvider provider = pwmRequest.getPwmSession().getSessionManager().getChaiProvider();
    try {
        final ResponseInfoBean responseInfoBean = new ResponseInfoBean(readResponses, helpdeskResponses, challengeSet.getLocale(), challengeSet.getMinRandomRequired(), challengeSet.getIdentifier(), null, null);
        final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(readResponses, challengeSet.getLocale(), challengeSet.getMinRandomRequired(), provider.getChaiConfiguration(), challengeSet.getIdentifier());
        responseSet.meetsChallengeSetRequirements(challengeSet);
        final SetupResponsesBean setupResponsesBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, SetupResponsesBean.class);
        final int minRandomRequiredSetup = setupResponsesBean.getResponseData().getMinRandomSetup();
        if (minRandomRequiredSetup == 0) {
            // if using recover style, then all readResponseSet must be supplied at this point.
            if (responseSet.getChallengeSet().getRandomChallenges().size() < challengeSet.getRandomChallenges().size()) {
                throw new ChaiValidationException("too few random responses", ChaiError.CR_TOO_FEW_RANDOM_RESPONSES);
            }
        }
        return responseInfoBean;
    } catch (ChaiValidationException e) {
        final ErrorInformation errorInfo = convertChaiValidationException(e);
        throw new PwmDataValidationException(errorInfo);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmDataValidationException(password.pwm.error.PwmDataValidationException) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) SetupResponsesBean(password.pwm.http.bean.SetupResponsesBean) ResponseInfoBean(password.pwm.bean.ResponseInfoBean)

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