|
@@ -18,26 +18,20 @@
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
-package password.pwm.http.servlet;
|
|
|
+package password.pwm.http.servlet.setupresponses;
|
|
|
|
|
|
import com.novell.ldapchai.ChaiUser;
|
|
|
-import com.novell.ldapchai.cr.ChaiChallenge;
|
|
|
-import com.novell.ldapchai.cr.ChaiCrFactory;
|
|
|
-import com.novell.ldapchai.cr.ChaiResponseSet;
|
|
|
import com.novell.ldapchai.cr.Challenge;
|
|
|
import com.novell.ldapchai.cr.ChallengeSet;
|
|
|
-import com.novell.ldapchai.exception.ChaiError;
|
|
|
import com.novell.ldapchai.exception.ChaiUnavailableException;
|
|
|
import com.novell.ldapchai.exception.ChaiValidationException;
|
|
|
-import com.novell.ldapchai.provider.ChaiProvider;
|
|
|
-import lombok.Value;
|
|
|
-import password.pwm.Permission;
|
|
|
import password.pwm.PwmConstants;
|
|
|
import password.pwm.PwmDomain;
|
|
|
import password.pwm.bean.LoginInfoBean;
|
|
|
import password.pwm.bean.ResponseInfoBean;
|
|
|
import password.pwm.config.PwmSetting;
|
|
|
import password.pwm.config.profile.ChallengeProfile;
|
|
|
+import password.pwm.config.profile.SetupResponsesProfile;
|
|
|
import password.pwm.error.ErrorInformation;
|
|
|
import password.pwm.error.PwmDataValidationException;
|
|
|
import password.pwm.error.PwmError;
|
|
@@ -50,6 +44,8 @@ import password.pwm.http.PwmRequest;
|
|
|
import password.pwm.http.PwmRequestAttribute;
|
|
|
import password.pwm.http.PwmSession;
|
|
|
import password.pwm.http.bean.SetupResponsesBean;
|
|
|
+import password.pwm.http.servlet.ControlledPwmServlet;
|
|
|
+import password.pwm.http.servlet.PwmServletDefinition;
|
|
|
import password.pwm.i18n.Message;
|
|
|
import password.pwm.ldap.UserInfo;
|
|
|
import password.pwm.ldap.auth.AuthenticationType;
|
|
@@ -67,11 +63,9 @@ import password.pwm.ws.server.RestResultBean;
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.Serializable;
|
|
|
import java.time.Instant;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -89,10 +83,11 @@ import java.util.Map;
|
|
|
)
|
|
|
public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
{
|
|
|
-
|
|
|
private static final PwmLogger LOGGER = PwmLogger.forClass( SetupResponsesServlet.class );
|
|
|
|
|
|
- public enum SetupResponsesAction implements AbstractPwmServlet.ProcessAction
|
|
|
+ public static final String PARAM_RESPONSE_MODE = "responseMode";
|
|
|
+
|
|
|
+ public enum SetupResponsesAction implements ProcessAction
|
|
|
{
|
|
|
validateResponses( HttpMethod.POST ),
|
|
|
setResponses( HttpMethod.POST ),
|
|
@@ -122,19 +117,39 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
return SetupResponsesAction.class;
|
|
|
}
|
|
|
|
|
|
- private SetupResponsesBean getSetupResponseBean( final PwmRequest pwmRequest ) throws PwmUnrecoverableException
|
|
|
+ private SetupResponsesBean getSetupResponseBean( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
- final SetupResponsesBean setupResponsesBean = pwmRequest.getPwmDomain().getSessionStateService().getBean( pwmRequest, SetupResponsesBean.class );
|
|
|
- if ( !setupResponsesBean.isInitialized() )
|
|
|
+ return pwmRequest.getPwmDomain().getSessionStateService().getBean( pwmRequest, SetupResponsesBean.class );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ static SetupResponsesProfile getSetupProfile( final PwmRequest pwmRequest ) throws PwmUnrecoverableException
|
|
|
+ {
|
|
|
+ return pwmRequest.getSetupResponsesProfile( );
|
|
|
+ }
|
|
|
+
|
|
|
+ static ChallengeProfile getChallengeProfile( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
+ {
|
|
|
+ return pwmRequest.getPwmSession().getUserInfo().getChallengeProfile();
|
|
|
+ }
|
|
|
+
|
|
|
+ static ChallengeSet getChallengeSet( final PwmRequest pwmRequest, final ResponseMode responseMode )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
+ {
|
|
|
+ final ChallengeProfile challengeProfile = getChallengeProfile( pwmRequest );
|
|
|
+ if ( responseMode == ResponseMode.helpdesk )
|
|
|
{
|
|
|
- initializeBean( pwmRequest, setupResponsesBean );
|
|
|
+ return challengeProfile.getHelpdeskChallengeSet().orElseThrow();
|
|
|
}
|
|
|
- return setupResponsesBean;
|
|
|
-
|
|
|
+ return challengeProfile.getChallengeSet().orElseThrow();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public ProcessStatus preProcessCheck( final PwmRequest pwmRequest ) throws PwmUnrecoverableException, IOException, ServletException
|
|
|
+ public ProcessStatus preProcessCheck( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException, IOException, ServletException
|
|
|
{
|
|
|
final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
final PwmDomain pwmDomain = pwmRequest.getPwmDomain();
|
|
@@ -150,17 +165,11 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
throw new PwmUnrecoverableException( PwmError.ERROR_PASSWORD_REQUIRED );
|
|
|
}
|
|
|
|
|
|
- if ( !pwmDomain.getConfig().readSettingAsBoolean( PwmSetting.CHALLENGE_ENABLE ) )
|
|
|
+ if ( !pwmDomain.getConfig().readSettingAsBoolean( PwmSetting.SETUP_RESPONSE_ENABLE ) )
|
|
|
{
|
|
|
throw new PwmUnrecoverableException( PwmError.ERROR_SERVICE_NOT_AVAILABLE );
|
|
|
}
|
|
|
|
|
|
- // check to see if the user is permitted to setup responses
|
|
|
- if ( !pwmSession.getSessionManager().checkPermission( pwmDomain, Permission.SETUP_RESPONSE ) )
|
|
|
- {
|
|
|
- throw new PwmUnrecoverableException( PwmError.ERROR_UNAUTHORIZED );
|
|
|
- }
|
|
|
-
|
|
|
// check if the locale has changed since first seen.
|
|
|
if ( pwmSession.getSessionStateBean().getLocale() != pwmDomain.getSessionStateService().getBean( pwmRequest, SetupResponsesBean.class ).getUserLocale() )
|
|
|
{
|
|
@@ -168,11 +177,17 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
pwmDomain.getSessionStateService().getBean( pwmRequest, SetupResponsesBean.class ).setUserLocale( pwmSession.getSessionStateBean().getLocale() );
|
|
|
}
|
|
|
|
|
|
+ final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
+ if ( !setupResponsesBean.isInitialized() )
|
|
|
+ {
|
|
|
+ initializeBean( pwmRequest, setupResponsesBean );
|
|
|
+ }
|
|
|
+
|
|
|
// check to see if the user has any challenges assigned
|
|
|
final UserInfo uiBean = pwmSession.getUserInfo();
|
|
|
- final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
|
|
|
- if ( setupResponsesBean.getResponseData().getChallengeSet() == null || setupResponsesBean.getResponseData().getChallengeSet().getChallenges().isEmpty() )
|
|
|
+ if ( !SetupResponsesUtil.hasChallenges( pwmRequest, ResponseMode.user )
|
|
|
+ && !SetupResponsesUtil.hasChallenges( pwmRequest, ResponseMode.helpdesk ) )
|
|
|
{
|
|
|
final String errorMsg = "no challenge sets configured for user " + uiBean.getUserIdentity();
|
|
|
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_NO_CHALLENGES, errorMsg );
|
|
@@ -184,7 +199,8 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
}
|
|
|
|
|
|
@ActionHandler( action = "confirmResponses" )
|
|
|
- private ProcessStatus processConfirmResponses( final PwmRequest pwmRequest ) throws PwmUnrecoverableException
|
|
|
+ private ProcessStatus processConfirmResponses( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
setupResponsesBean.setConfirmed( true );
|
|
@@ -192,7 +208,8 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
}
|
|
|
|
|
|
@ActionHandler( action = "changeResponses" )
|
|
|
- private ProcessStatus processChangeResponses( final PwmRequest pwmRequest ) throws PwmUnrecoverableException
|
|
|
+ private ProcessStatus processChangeResponses( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
final PwmDomain pwmDomain = pwmRequest.getPwmDomain();
|
|
@@ -246,7 +263,7 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
{
|
|
|
LOGGER.trace( pwmRequest, () -> "request for skip received" );
|
|
|
|
|
|
- final boolean allowSkip = checkIfAllowSkipCr( pwmRequest );
|
|
|
+ final boolean allowSkip = SetupResponsesUtil.checkIfAllowSkipCr( pwmRequest );
|
|
|
|
|
|
if ( allowSkip )
|
|
|
{
|
|
@@ -262,32 +279,31 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
private ProcessStatus restValidateResponses(
|
|
|
final PwmRequest pwmRequest
|
|
|
)
|
|
|
- throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException
|
|
|
+ throws IOException, PwmUnrecoverableException
|
|
|
{
|
|
|
- final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
final Instant startTime = Instant.now();
|
|
|
- final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
- final PwmDomain pwmDomain = pwmRequest.getPwmDomain();
|
|
|
- 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, pwmDomain.getConfig() );
|
|
|
+ final ResponseMode responseMode = pwmRequest.readParameterAsEnum( PARAM_RESPONSE_MODE, ResponseMode.class ).orElseThrow();
|
|
|
+ final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
+
|
|
|
+ final SetupResponsesBean.SetupData setupData = setupResponsesBean.getChallengeData().get( responseMode );
|
|
|
+ final ChallengeSet challengeSet = getChallengeSet( pwmRequest, responseMode );
|
|
|
+
|
|
|
+ boolean success = false;
|
|
|
+ String userMessage = Message.getLocalizedMessage( pwmRequest.getLocale(), Message.Success_ResponsesMeetRules, pwmRequest.getDomainConfig() );
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// read in the responses from the request
|
|
|
final Map<Challenge, String> responseMap = readResponsesFromJsonRequest( pwmRequest, setupData );
|
|
|
final int minRandomRequiredSetup = setupData.getMinRandomSetup();
|
|
|
- pwmDomain.getCrService().validateResponses( setupData.getChallengeSet(), responseMap, minRandomRequiredSetup );
|
|
|
- generateResponseInfoBean( pwmRequest, setupData.getChallengeSet(), responseMap, Collections.emptyMap() );
|
|
|
+ pwmRequest.getPwmDomain().getCrService().validateResponses( challengeSet, responseMap, minRandomRequiredSetup );
|
|
|
+ SetupResponsesUtil.generateResponseInfoBean( pwmRequest, challengeSet, responseMap, Collections.emptyMap() );
|
|
|
+ success = true;
|
|
|
}
|
|
|
catch ( final PwmDataValidationException e )
|
|
|
{
|
|
|
- success = false;
|
|
|
- userMessage = e.getErrorInformation().toUserStr( pwmSession, pwmDomain.getConfig() );
|
|
|
+ userMessage = e.getErrorInformation().toUserStr( pwmRequest.getPwmSession(), pwmRequest.getAppConfig() );
|
|
|
}
|
|
|
|
|
|
final ValidationResponseBean validationResponseBean = new ValidationResponseBean( userMessage, success );
|
|
@@ -301,17 +317,17 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
|
|
|
@ActionHandler( action = "setHelpdeskResponses" )
|
|
|
private ProcessStatus processSetHelpdeskResponses( final PwmRequest pwmRequest )
|
|
|
- throws ChaiUnavailableException, PwmUnrecoverableException, ServletException, IOException
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
- setupResponses( pwmRequest, true );
|
|
|
+ setupResponses( pwmRequest, ResponseMode.helpdesk );
|
|
|
return ProcessStatus.Continue;
|
|
|
}
|
|
|
|
|
|
@ActionHandler( action = "setResponses" )
|
|
|
private ProcessStatus processSetResponses( final PwmRequest pwmRequest )
|
|
|
- throws ChaiUnavailableException, PwmUnrecoverableException, ServletException, IOException
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
- setupResponses( pwmRequest, false );
|
|
|
+ setupResponses( pwmRequest, ResponseMode.user );
|
|
|
return ProcessStatus.Continue;
|
|
|
}
|
|
|
|
|
@@ -321,45 +337,34 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
{
|
|
|
final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
|
|
|
- initializeBean( pwmRequest, setupResponsesBean );
|
|
|
-
|
|
|
- pwmRequest.setAttribute( PwmRequestAttribute.ModuleBean, setupResponsesBean );
|
|
|
- pwmRequest.setAttribute( PwmRequestAttribute.ModuleBean_String, pwmRequest.getPwmDomain().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() )
|
|
|
- {
|
|
|
- final boolean allowskip = checkIfAllowSkipCr( pwmRequest );
|
|
|
- pwmRequest.setAttribute( PwmRequestAttribute.SetupResponses_AllowSkip, allowskip );
|
|
|
- pwmRequest.forwardToJsp( JspUrl.SETUP_RESPONSES );
|
|
|
+ forwardToJsp( pwmRequest, JspUrl.SETUP_RESPONSES_EXISTING );
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if ( !setupResponsesBean.isHelpdeskResponsesSatisfied() )
|
|
|
+ for ( final ResponseMode responseMode : ResponseMode.values() )
|
|
|
{
|
|
|
- if ( setupResponsesBean.getHelpdeskResponseData().getChallengeSet() == null
|
|
|
- || setupResponsesBean.getHelpdeskResponseData().getChallengeSet().getChallenges().isEmpty() )
|
|
|
+ if ( !setupResponsesBean.getResponsesSatisfied().contains( responseMode )
|
|
|
+ && SetupResponsesUtil.hasChallenges( pwmRequest, responseMode ) )
|
|
|
{
|
|
|
- setupResponsesBean.setHelpdeskResponsesSatisfied( true );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pwmRequest.forwardToJsp( JspUrl.SETUP_RESPONSES_HELPDESK );
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.SetupResponses_ChallengeSet, getChallengeSet( pwmRequest, responseMode ) );
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.SetupResponses_AllowSkip, SetupResponsesUtil.checkIfAllowSkipCr( pwmRequest ) );
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.SetupResponses_SetupData, setupResponsesBean.getChallengeData().get( responseMode ) );
|
|
|
+
|
|
|
+ forwardToJsp( pwmRequest, responseMode == ResponseMode.helpdesk
|
|
|
+ ? JspUrl.SETUP_RESPONSES_HELPDESK
|
|
|
+ : JspUrl.SETUP_RESPONSES );
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ( pwmRequest.getDomainConfig().readSettingAsBoolean( PwmSetting.CHALLENGE_SHOW_CONFIRMATION ) )
|
|
|
+ final SetupResponsesProfile setupResponsesProfile = getSetupProfile( pwmRequest );
|
|
|
+ if ( setupResponsesProfile.readSettingAsBoolean( PwmSetting.SETUP_RESPONSES_SHOW_CONFIRMATION ) )
|
|
|
{
|
|
|
if ( !setupResponsesBean.isConfirmed() )
|
|
|
{
|
|
|
- pwmRequest.forwardToJsp( JspUrl.SETUP_RESPONSES_CONFIRM );
|
|
|
+ forwardToJsp( pwmRequest, JspUrl.SETUP_RESPONSES_CONFIRM );
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -367,11 +372,11 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
try
|
|
|
{
|
|
|
// everything good, so lets save responses.
|
|
|
- final ResponseInfoBean responses = generateResponseInfoBean(
|
|
|
+ final ResponseInfoBean responses = SetupResponsesUtil.generateResponseInfoBean(
|
|
|
pwmRequest,
|
|
|
- setupResponsesBean.getResponseData().getChallengeSet(),
|
|
|
- setupResponsesBean.getResponseData().getResponseMap(),
|
|
|
- setupResponsesBean.getHelpdeskResponseData().getResponseMap()
|
|
|
+ getChallengeSet( pwmRequest, ResponseMode.user ),
|
|
|
+ setupResponsesBean.getChallengeData().get( ResponseMode.user ).getResponseMap(),
|
|
|
+ setupResponsesBean.getChallengeData().get( ResponseMode.helpdesk ).getResponseMap()
|
|
|
);
|
|
|
saveResponses( pwmRequest, responses );
|
|
|
pwmRequest.getPwmDomain().getSessionStateService().clearBean( pwmRequest, SetupResponsesBean.class );
|
|
@@ -390,17 +395,29 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void forwardToJsp( final PwmRequest pwmRequest, final JspUrl jspUrl )
|
|
|
+ throws ServletException, PwmUnrecoverableException, IOException
|
|
|
+ {
|
|
|
+ final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
+
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.ModuleBean, setupResponsesBean );
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.ModuleBean_String, pwmRequest.getPwmDomain().getSecureService().encryptObjectToString( setupResponsesBean ) );
|
|
|
+ pwmRequest.setAttribute( PwmRequestAttribute.SetupResponses_ResponseInfo, pwmRequest.getPwmSession().getUserInfo().getResponseInfoBean() );
|
|
|
+
|
|
|
+ pwmRequest.forwardToJsp( jspUrl );
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void setupResponses(
|
|
|
final PwmRequest pwmRequest,
|
|
|
- final boolean helpdeskMode
|
|
|
+ final ResponseMode responseMode
|
|
|
)
|
|
|
- throws PwmUnrecoverableException, IOException, ServletException, ChaiUnavailableException
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
final SetupResponsesBean setupResponsesBean = getSetupResponseBean( pwmRequest );
|
|
|
- final SetupResponsesBean.SetupData setupData = helpdeskMode ? setupResponsesBean.getHelpdeskResponseData() : setupResponsesBean.getResponseData();
|
|
|
+ final SetupResponsesBean.SetupData setupData = setupResponsesBean.getChallengeData().get( responseMode );
|
|
|
|
|
|
- final ChallengeSet challengeSet = setupData.getChallengeSet();
|
|
|
+ final ChallengeSet challengeSet = getChallengeProfile( pwmRequest ).getChallengeSet().orElseThrow();
|
|
|
final Map<Challenge, String> responseMap;
|
|
|
try
|
|
|
{
|
|
@@ -413,22 +430,14 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
}
|
|
|
catch ( final PwmDataValidationException e )
|
|
|
{
|
|
|
- LOGGER.debug( pwmRequest, () -> "error with new " + ( helpdeskMode ? "helpdesk" : "user" ) + " responses: " + e.getErrorInformation().toDebugStr() );
|
|
|
+ LOGGER.debug( pwmRequest, () -> "error with new " + responseMode.name() + " 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 );
|
|
|
- }
|
|
|
+ LOGGER.trace( pwmRequest, () -> responseMode.name() + " responses are acceptable" );
|
|
|
+ setupData.setResponseMap( responseMap );
|
|
|
+ setupResponsesBean.getResponsesSatisfied().add( responseMode );
|
|
|
}
|
|
|
|
|
|
private void saveResponses( final PwmRequest pwmRequest, final ResponseInfoBean responseInfoBean )
|
|
@@ -452,7 +461,8 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
throws PwmDataValidationException, PwmUnrecoverableException
|
|
|
{
|
|
|
final Map<String, String> inputMap = pwmRequest.readParametersAsMap();
|
|
|
- return paramMapToChallengeMap( inputMap, setupData );
|
|
|
+ final ChallengeSet challengeSet = getChallengeProfile( pwmRequest ).getChallengeSet().orElseThrow();
|
|
|
+ return SetupResponsesUtil.paramMapToChallengeMap( challengeSet, inputMap, setupData );
|
|
|
}
|
|
|
|
|
|
private static Map<Challenge, String> readResponsesFromJsonRequest(
|
|
@@ -462,171 +472,10 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
throws PwmDataValidationException, PwmUnrecoverableException, IOException
|
|
|
{
|
|
|
final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap();
|
|
|
- return paramMapToChallengeMap( inputMap, setupData );
|
|
|
+ final ChallengeSet challengeSet = getChallengeProfile( pwmRequest ).getChallengeSet().orElseThrow();
|
|
|
+ return SetupResponsesUtil.paramMapToChallengeMap( challengeSet, inputMap, setupData );
|
|
|
}
|
|
|
|
|
|
- private static Map<Challenge, String> paramMapToChallengeMap(
|
|
|
- final Map<String, String> inputMap,
|
|
|
- final SetupResponsesBean.SetupData setupData
|
|
|
- )
|
|
|
- throws PwmDataValidationException, PwmUnrecoverableException
|
|
|
- {
|
|
|
- //final SetupResponsesBean responsesBean = pwmSession.getSetupResponseBean();
|
|
|
- final Map<Challenge, String> readResponses = new LinkedHashMap<>();
|
|
|
-
|
|
|
- {
|
|
|
- // read in the question texts and responses
|
|
|
- for ( final String indexKey : setupData.getIndexedChallenges().keySet() )
|
|
|
- {
|
|
|
- final Challenge loopChallenge = setupData.getIndexedChallenges().get( indexKey );
|
|
|
- if ( loopChallenge.isRequired() || !setupData.isSimpleMode() )
|
|
|
- {
|
|
|
-
|
|
|
- final Challenge newChallenge;
|
|
|
- if ( !loopChallenge.isAdminDefined() )
|
|
|
- {
|
|
|
- final String questionText = inputMap.get( PwmConstants.PARAM_QUESTION_PREFIX + indexKey );
|
|
|
- newChallenge = new ChaiChallenge(
|
|
|
- loopChallenge.isRequired(),
|
|
|
- questionText,
|
|
|
- loopChallenge.getMinLength(),
|
|
|
- loopChallenge.getMaxLength(),
|
|
|
- loopChallenge.isAdminDefined(),
|
|
|
- loopChallenge.getMaxQuestionCharsInAnswer(),
|
|
|
- loopChallenge.isEnforceWordlist()
|
|
|
- );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- newChallenge = loopChallenge;
|
|
|
- }
|
|
|
-
|
|
|
- final String answer = inputMap.get( PwmConstants.PARAM_RESPONSE_PREFIX + indexKey );
|
|
|
-
|
|
|
- if ( answer != null && answer.length() > 0 )
|
|
|
- {
|
|
|
- readResponses.put( newChallenge, answer );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ( setupData.isSimpleMode() )
|
|
|
- {
|
|
|
- // if in simple mode, read the select-based random challenges
|
|
|
- for ( int i = 0; i < setupData.getIndexedChallenges().size(); i++ )
|
|
|
- {
|
|
|
- final String questionText = inputMap.get( PwmConstants.PARAM_QUESTION_PREFIX + "Random_" + String.valueOf( i ) );
|
|
|
-
|
|
|
- Challenge challenge = null;
|
|
|
- for ( final Challenge loopC : setupData.getChallengeSet().getRandomChallenges() )
|
|
|
- {
|
|
|
- if ( loopC.isAdminDefined() && questionText != null && questionText.equals( loopC.getChallengeText() ) )
|
|
|
- {
|
|
|
- challenge = loopC;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- final String answer = inputMap.get( PwmConstants.PARAM_RESPONSE_PREFIX + "Random_" + String.valueOf( i ) );
|
|
|
- if ( answer != null && answer.length() > 0 )
|
|
|
- {
|
|
|
- readResponses.put( challenge, answer );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return readResponses;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- 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.getPwmDomain().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 ( final ChaiValidationException e )
|
|
|
- {
|
|
|
- final ErrorInformation errorInfo = convertChaiValidationException( e );
|
|
|
- throw new PwmDataValidationException( errorInfo );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static ErrorInformation convertChaiValidationException(
|
|
|
- final ChaiValidationException e
|
|
|
- )
|
|
|
- {
|
|
|
- final String[] fieldNames = new String[] {
|
|
|
- e.getFieldName(),
|
|
|
- };
|
|
|
-
|
|
|
- switch ( e.getErrorCode() )
|
|
|
- {
|
|
|
- case CR_TOO_FEW_CHALLENGES:
|
|
|
- return new ErrorInformation( PwmError.ERROR_MISSING_REQUIRED_RESPONSE, null, fieldNames );
|
|
|
-
|
|
|
- case CR_TOO_FEW_RANDOM_RESPONSES:
|
|
|
- return new ErrorInformation( PwmError.ERROR_MISSING_RANDOM_RESPONSE, null, fieldNames );
|
|
|
-
|
|
|
- case CR_MISSING_REQUIRED_CHALLENGE_TEXT:
|
|
|
- return new ErrorInformation( PwmError.ERROR_MISSING_CHALLENGE_TEXT, null, fieldNames );
|
|
|
-
|
|
|
- case CR_RESPONSE_TOO_LONG:
|
|
|
- return new ErrorInformation( PwmError.ERROR_RESPONSE_TOO_LONG, null, fieldNames );
|
|
|
-
|
|
|
- case CR_RESPONSE_TOO_SHORT:
|
|
|
- case CR_MISSING_REQUIRED_RESPONSE_TEXT:
|
|
|
- return new ErrorInformation( PwmError.ERROR_RESPONSE_TOO_SHORT, null, fieldNames );
|
|
|
-
|
|
|
- case CR_DUPLICATE_RESPONSES:
|
|
|
- return new ErrorInformation( PwmError.ERROR_RESPONSE_DUPLICATE, null, fieldNames );
|
|
|
-
|
|
|
- case CR_TOO_MANY_QUESTION_CHARS:
|
|
|
- return new ErrorInformation( PwmError.ERROR_CHALLENGE_IN_RESPONSE, null, fieldNames );
|
|
|
-
|
|
|
- default:
|
|
|
- return new ErrorInformation( PwmError.ERROR_INTERNAL );
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
private void initializeBean(
|
|
|
final PwmRequest pwmRequest,
|
|
@@ -634,121 +483,35 @@ public class SetupResponsesServlet extends ControlledPwmServlet
|
|
|
)
|
|
|
throws PwmUnrecoverableException
|
|
|
{
|
|
|
- if ( pwmRequest.getPwmSession().getUserInfo().getResponseInfoBean() != null )
|
|
|
+ if ( setupResponsesBean.isInitialized() )
|
|
|
{
|
|
|
- setupResponsesBean.setHasExistingResponses( true );
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- final ChallengeProfile challengeProfile = pwmRequest.getPwmSession().getUserInfo().getChallengeProfile();
|
|
|
- if ( setupResponsesBean.getResponseData() == null )
|
|
|
- {
|
|
|
- //setup user challenge data
|
|
|
- final ChallengeSet userChallengeSet = challengeProfile.getChallengeSet();
|
|
|
- final int minRandomSetup = challengeProfile.getMinRandomSetup();
|
|
|
- final SetupResponsesBean.SetupData userSetupData = populateSetupData( userChallengeSet, minRandomSetup );
|
|
|
- setupResponsesBean.setResponseData( userSetupData );
|
|
|
- }
|
|
|
- if ( setupResponsesBean.getHelpdeskResponseData() == null )
|
|
|
+ if ( pwmRequest.getPwmSession().getUserInfo().getResponseInfoBean() != null )
|
|
|
{
|
|
|
- //setup helpdesk challenge data
|
|
|
- final ChallengeSet helpdeskChallengeSet = challengeProfile.getHelpdeskChallengeSet();
|
|
|
- if ( helpdeskChallengeSet == null )
|
|
|
- {
|
|
|
- setupResponsesBean.setHelpdeskResponseData( new SetupResponsesBean.SetupData() );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- final int minRandomHelpdeskSetup = challengeProfile.getMinHelpdeskRandomsSetup();
|
|
|
- final SetupResponsesBean.SetupData helpdeskSetupData = populateSetupData( helpdeskChallengeSet, minRandomHelpdeskSetup );
|
|
|
- setupResponsesBean.setHelpdeskResponseData( helpdeskSetupData );
|
|
|
- }
|
|
|
+ setupResponsesBean.setHasExistingResponses( true );
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private static SetupResponsesBean.SetupData populateSetupData(
|
|
|
- final ChallengeSet challengeSet,
|
|
|
- final int minRandomSetup
|
|
|
- )
|
|
|
- {
|
|
|
- boolean useSimple = true;
|
|
|
- final Map<String, Challenge> indexedChallenges = new LinkedHashMap<>();
|
|
|
|
|
|
- int minRandom = minRandomSetup;
|
|
|
+ final ChallengeProfile challengeProfile = pwmRequest.getPwmSession().getUserInfo().getChallengeProfile();
|
|
|
|
|
|
{
|
|
|
- if ( minRandom != 0 && minRandom < challengeSet.getMinRandomRequired() )
|
|
|
- {
|
|
|
- minRandom = challengeSet.getMinRandomRequired();
|
|
|
- }
|
|
|
- if ( minRandom > challengeSet.getRandomChallenges().size() )
|
|
|
- {
|
|
|
- minRandom = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- {
|
|
|
- {
|
|
|
- if ( minRandom == 0 )
|
|
|
- {
|
|
|
- useSimple = false;
|
|
|
- }
|
|
|
-
|
|
|
- for ( final Challenge challenge : challengeSet.getChallenges() )
|
|
|
- {
|
|
|
- if ( !challenge.isRequired() && !challenge.isAdminDefined() )
|
|
|
- {
|
|
|
- useSimple = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ( challengeSet.getRandomChallenges().size() == challengeSet.getMinRandomRequired() )
|
|
|
- {
|
|
|
- useSimple = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ final SetupResponsesBean.SetupData userSetupData = challengeProfile.getChallengeSet()
|
|
|
+ .map( challengeSet -> SetupResponsesUtil.populateSetupData( challengeSet, challengeProfile.getMinRandomSetup() ) )
|
|
|
+ .orElse( new SetupResponsesBean.SetupData() );
|
|
|
|
|
|
- {
|
|
|
- int index = 0;
|
|
|
- for ( final Challenge loopChallenge : challengeSet.getChallenges() )
|
|
|
- {
|
|
|
- indexedChallenges.put( String.valueOf( index ), loopChallenge );
|
|
|
- index++;
|
|
|
- }
|
|
|
+ setupResponsesBean.getChallengeData().put( ResponseMode.user, userSetupData );
|
|
|
}
|
|
|
|
|
|
- final SetupResponsesBean.SetupData setupData = new SetupResponsesBean.SetupData();
|
|
|
- setupData.setChallengeSet( challengeSet );
|
|
|
- setupData.setSimpleMode( useSimple );
|
|
|
- setupData.setIndexedChallenges( indexedChallenges );
|
|
|
- setupData.setMinRandomSetup( minRandom );
|
|
|
- return setupData;
|
|
|
- }
|
|
|
-
|
|
|
- @Value
|
|
|
- private static class ValidationResponseBean implements Serializable
|
|
|
- {
|
|
|
- private String message;
|
|
|
- private boolean success;
|
|
|
- }
|
|
|
-
|
|
|
- private static boolean checkIfAllowSkipCr( final PwmRequest pwmRequest )
|
|
|
- throws PwmUnrecoverableException
|
|
|
- {
|
|
|
- if ( pwmRequest.isForcedPageView() )
|
|
|
{
|
|
|
- final boolean admin = pwmRequest.getPwmSession().getSessionManager().checkPermission( pwmRequest.getPwmDomain(), Permission.PWMADMIN );
|
|
|
- if ( admin )
|
|
|
- {
|
|
|
- if ( pwmRequest.getDomainConfig().readSettingAsBoolean( PwmSetting.ADMIN_ALLOW_SKIP_FORCED_ACTIVITIES ) )
|
|
|
- {
|
|
|
- LOGGER.trace( pwmRequest, () -> "allowing c/r answer setup skipping due to user being admin and setting "
|
|
|
- + PwmSetting.ADMIN_ALLOW_SKIP_FORCED_ACTIVITIES.toMenuLocationDebug( null, pwmRequest.getLocale() ) );
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
+ final SetupResponsesBean.SetupData helpdeskSetupData = challengeProfile.getHelpdeskChallengeSet()
|
|
|
+ .map( challengeSet -> SetupResponsesUtil.populateSetupData( challengeSet, challengeProfile.getMinHelpdeskRandomsSetup() ) )
|
|
|
+ .orElse( new SetupResponsesBean.SetupData() );
|
|
|
+ setupResponsesBean.getChallengeData().put( ResponseMode.helpdesk, helpdeskSetupData );
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
+ setupResponsesBean.setInitialized( true );
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|