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);
}
}
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());
}
}
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);
}
}
Aggregations