use of com.novell.ldapchai.cr.Challenge in project pwm by pwm-project.
the class ForgottenPasswordUtil method readResponsesFromHttpRequest.
static Map<Challenge, String> readResponsesFromHttpRequest(final PwmRequest req, final ChallengeSet challengeSet) throws PwmUnrecoverableException {
final Map<Challenge, String> responses = new LinkedHashMap<>();
int counter = 0;
for (final Challenge loopChallenge : challengeSet.getChallenges()) {
counter++;
final String answer = req.readParameterAsString(PwmConstants.PARAM_RESPONSE_PREFIX + counter);
responses.put(loopChallenge, answer.length() > 0 ? answer : "");
}
return responses;
}
use of com.novell.ldapchai.cr.Challenge in project pwm by pwm-project.
the class ForgottenPasswordUtil method initBogusForgottenPasswordBean.
static void initBogusForgottenPasswordBean(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
final ForgottenPasswordBean forgottenPasswordBean = ForgottenPasswordServlet.forgottenPasswordBean(pwmRequest);
forgottenPasswordBean.setUserIdentity(null);
forgottenPasswordBean.setPresentableChallengeSet(null);
final List<Challenge> challengeList = new ArrayList<>();
{
final String firstProfile = pwmRequest.getConfig().getChallengeProfileIDs().iterator().next();
final ChallengeSet challengeSet = pwmRequest.getConfig().getChallengeProfile(firstProfile, PwmConstants.DEFAULT_LOCALE).getChallengeSet();
challengeList.addAll(challengeSet.getRequiredChallenges());
for (int i = 0; i < challengeSet.getMinRandomRequired(); i++) {
challengeList.add(challengeSet.getRandomChallenges().get(i));
}
}
final List<FormConfiguration> formData = new ArrayList<>();
{
int counter = 0;
for (Challenge challenge : challengeList) {
final FormConfiguration formConfiguration = FormConfiguration.builder().name("challenge" + counter++).type(FormConfiguration.Type.text).labels(Collections.singletonMap("", challenge.getChallengeText())).minimumLength(challenge.getMinLength()).maximumLength(challenge.getMaxLength()).source(FormConfiguration.Source.bogus).build();
formData.add(formConfiguration);
}
}
forgottenPasswordBean.setAttributeForm(formData);
forgottenPasswordBean.setBogusUser(true);
{
final String profileID = pwmRequest.getConfig().getForgottenPasswordProfiles().keySet().iterator().next();
forgottenPasswordBean.setForgottenPasswordProfileID(profileID);
}
final ForgottenPasswordBean.RecoveryFlags recoveryFlags = new ForgottenPasswordBean.RecoveryFlags(false, Collections.singleton(IdentityVerificationMethod.ATTRIBUTES), Collections.emptySet(), 0);
forgottenPasswordBean.setRecoveryFlags(recoveryFlags);
}
use of com.novell.ldapchai.cr.Challenge in project pwm by pwm-project.
the class ForgottenPasswordServlet method processCheckResponses.
@ActionHandler(action = "checkResponses")
private ProcessStatus processCheckResponses(final PwmRequest pwmRequest) throws ChaiUnavailableException, IOException, ServletException, PwmUnrecoverableException {
final ForgottenPasswordBean forgottenPasswordBean = forgottenPasswordBean(pwmRequest);
if (forgottenPasswordBean.getUserIdentity() == null) {
return ProcessStatus.Continue;
}
final UserIdentity userIdentity = forgottenPasswordBean.getUserIdentity();
final ResponseSet responseSet = ForgottenPasswordUtil.readResponseSet(pwmRequest, forgottenPasswordBean);
if (responseSet == null) {
final String errorMsg = "attempt to check responses, but responses are not loaded into session bean";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
try {
// read the supplied responses from the user
final Map<Challenge, String> crMap = ForgottenPasswordUtil.readResponsesFromHttpRequest(pwmRequest, forgottenPasswordBean.getPresentableChallengeSet());
final boolean responsesPassed;
try {
responsesPassed = responseSet.test(crMap);
} catch (ChaiUnavailableException e) {
if (e.getCause() instanceof PwmUnrecoverableException) {
throw (PwmUnrecoverableException) e.getCause();
}
throw e;
}
// special case for nmas, clear out existing challenges and input fields.
if (!responsesPassed && responseSet instanceof NMASCrOperator.NMASCRResponseSet) {
forgottenPasswordBean.setPresentableChallengeSet(responseSet.getPresentableChallengeSet());
}
if (responsesPassed) {
LOGGER.debug(pwmRequest, "user '" + userIdentity + "' has supplied correct responses");
} else {
final String errorMsg = "incorrect response to one or more challenges";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_INCORRECT_RESPONSE, errorMsg);
handleUserVerificationBadAttempt(pwmRequest, forgottenPasswordBean, errorInformation);
return ProcessStatus.Continue;
}
} catch (ChaiValidationException e) {
LOGGER.debug(pwmRequest, "chai validation error checking user responses: " + e.getMessage());
final ErrorInformation errorInformation = new ErrorInformation(PwmError.forChaiError(e.getErrorCode()));
handleUserVerificationBadAttempt(pwmRequest, forgottenPasswordBean, errorInformation);
return ProcessStatus.Continue;
}
forgottenPasswordBean.getProgress().getSatisfiedMethods().add(IdentityVerificationMethod.CHALLENGE_RESPONSES);
return ProcessStatus.Continue;
}
use of com.novell.ldapchai.cr.Challenge in project pwm by pwm-project.
the class SetupResponsesServlet method restValidateResponses.
@ActionHandler(action = "validateResponses")
private ProcessStatus restValidateResponses(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
final SetupResponsesBean setupResponsesBean = getSetupResponseBean(pwmRequest);
final Instant startTime = Instant.now();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final String responseModeParam = pwmRequest.readParameterAsString("responseMode");
final SetupResponsesBean.SetupData setupData = "helpdesk".equalsIgnoreCase(responseModeParam) ? setupResponsesBean.getHelpdeskResponseData() : setupResponsesBean.getResponseData();
boolean success = true;
String userMessage = Message.getLocalizedMessage(pwmSession.getSessionStateBean().getLocale(), Message.Success_ResponsesMeetRules, pwmApplication.getConfig());
try {
// read in the responses from the request
final Map<Challenge, String> responseMap = readResponsesFromJsonRequest(pwmRequest, setupData);
final int minRandomRequiredSetup = setupData.getMinRandomSetup();
pwmApplication.getCrService().validateResponses(setupData.getChallengeSet(), responseMap, minRandomRequiredSetup);
generateResponseInfoBean(pwmRequest, setupData.getChallengeSet(), responseMap, Collections.emptyMap());
} catch (PwmDataValidationException e) {
success = false;
userMessage = e.getErrorInformation().toUserStr(pwmSession, pwmApplication);
}
final ValidationResponseBean validationResponseBean = new ValidationResponseBean(userMessage, success);
final RestResultBean restResultBean = RestResultBean.withData(validationResponseBean);
LOGGER.trace(pwmRequest, "completed rest validate response in " + TimeDuration.fromCurrent(startTime).asCompactString() + ", result=" + JsonUtil.serialize(restResultBean));
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of com.novell.ldapchai.cr.Challenge in project pwm by pwm-project.
the class SetupResponsesServlet method setupResponses.
private void setupResponses(final PwmRequest pwmRequest, final boolean helpdeskMode) throws PwmUnrecoverableException, IOException, ServletException, ChaiUnavailableException {
final SetupResponsesBean setupResponsesBean = getSetupResponseBean(pwmRequest);
final SetupResponsesBean.SetupData setupData = helpdeskMode ? setupResponsesBean.getHelpdeskResponseData() : setupResponsesBean.getResponseData();
final ChallengeSet challengeSet = setupData.getChallengeSet();
final Map<Challenge, String> responseMap;
try {
// build a response set based on the user's challenge set and the html form response.
responseMap = readResponsesFromHttpRequest(pwmRequest, setupData);
// test the responses.
final int minRandomRequiredSetup = setupData.getMinRandomSetup();
pwmRequest.getPwmApplication().getCrService().validateResponses(challengeSet, responseMap, minRandomRequiredSetup);
} catch (PwmDataValidationException e) {
LOGGER.debug(pwmRequest, "error with new " + (helpdeskMode ? "helpdesk" : "user") + " responses: " + e.getErrorInformation().toDebugStr());
setLastError(pwmRequest, e.getErrorInformation());
return;
}
LOGGER.trace(pwmRequest, (helpdeskMode ? "helpdesk" : "user") + " responses are acceptable");
if (helpdeskMode) {
setupResponsesBean.getHelpdeskResponseData().setResponseMap(responseMap);
setupResponsesBean.setHelpdeskResponsesSatisfied(true);
} else {
setupResponsesBean.getResponseData().setResponseMap(responseMap);
setupResponsesBean.setResponsesSatisfied(true);
}
}
Aggregations