|
@@ -60,15 +60,19 @@ import password.pwm.http.bean.ConfigGuideBean;
|
|
import password.pwm.http.servlet.AbstractPwmServlet;
|
|
import password.pwm.http.servlet.AbstractPwmServlet;
|
|
import password.pwm.http.servlet.ControlledPwmServlet;
|
|
import password.pwm.http.servlet.ControlledPwmServlet;
|
|
import password.pwm.http.servlet.configeditor.ConfigEditorServletUtils;
|
|
import password.pwm.http.servlet.configeditor.ConfigEditorServletUtils;
|
|
|
|
+import password.pwm.http.servlet.configeditor.DomainManageMode;
|
|
|
|
+import password.pwm.http.servlet.configeditor.ReadSettingResponse;
|
|
import password.pwm.http.servlet.configeditor.data.NavTreeSettings;
|
|
import password.pwm.http.servlet.configeditor.data.NavTreeSettings;
|
|
import password.pwm.http.servlet.configeditor.data.SettingData;
|
|
import password.pwm.http.servlet.configeditor.data.SettingData;
|
|
import password.pwm.http.servlet.configeditor.data.SettingDataMaker;
|
|
import password.pwm.http.servlet.configeditor.data.SettingDataMaker;
|
|
import password.pwm.i18n.Message;
|
|
import password.pwm.i18n.Message;
|
|
import password.pwm.ldap.LdapBrowser;
|
|
import password.pwm.ldap.LdapBrowser;
|
|
import password.pwm.ldap.schema.SchemaOperationResult;
|
|
import password.pwm.ldap.schema.SchemaOperationResult;
|
|
|
|
+import password.pwm.util.java.JavaHelper;
|
|
import password.pwm.util.java.MiscUtil;
|
|
import password.pwm.util.java.MiscUtil;
|
|
-import password.pwm.util.json.JsonFactory;
|
|
|
|
|
|
+import password.pwm.util.java.StringUtil;
|
|
import password.pwm.util.java.TimeDuration;
|
|
import password.pwm.util.java.TimeDuration;
|
|
|
|
+import password.pwm.util.json.JsonFactory;
|
|
import password.pwm.util.logging.PwmLogger;
|
|
import password.pwm.util.logging.PwmLogger;
|
|
import password.pwm.util.secure.X509Utils;
|
|
import password.pwm.util.secure.X509Utils;
|
|
import password.pwm.ws.server.RestResultBean;
|
|
import password.pwm.ws.server.RestResultBean;
|
|
@@ -84,8 +88,6 @@ import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
@@ -104,6 +106,8 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
private static final PwmLogger LOGGER = PwmLogger.getLogger( ConfigGuideServlet.class.getName() );
|
|
private static final PwmLogger LOGGER = PwmLogger.getLogger( ConfigGuideServlet.class.getName() );
|
|
|
|
|
|
private static final String LDAP_PROFILE_KEY = PwmConstants.PROFILE_ID_DEFAULT;
|
|
private static final String LDAP_PROFILE_KEY = PwmConstants.PROFILE_ID_DEFAULT;
|
|
|
|
+ public static final String PARAM_STEP = "step";
|
|
|
|
+ public static final String PARAM_KEY = "key";
|
|
|
|
|
|
public enum ConfigGuideAction implements AbstractPwmServlet.ProcessAction
|
|
public enum ConfigGuideAction implements AbstractPwmServlet.ProcessAction
|
|
{
|
|
{
|
|
@@ -118,8 +122,7 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
skipGuide( HttpMethod.POST ),
|
|
skipGuide( HttpMethod.POST ),
|
|
readSetting( HttpMethod.POST ),
|
|
readSetting( HttpMethod.POST ),
|
|
writeSetting( HttpMethod.POST ),
|
|
writeSetting( HttpMethod.POST ),
|
|
- settingData( HttpMethod.GET ),;
|
|
|
|
-
|
|
|
|
|
|
+ settingData( HttpMethod.POST ),;
|
|
|
|
|
|
private final HttpMethod method;
|
|
private final HttpMethod method;
|
|
|
|
|
|
@@ -406,84 +409,17 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
{
|
|
{
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
|
|
|
|
- final String requestedStep = pwmRequest.readParameterAsString( "step" );
|
|
|
|
- GuideStep step = GuideStep.START;
|
|
|
|
- if ( requestedStep != null && requestedStep.length() > 0 )
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- step = GuideStep.valueOf( requestedStep );
|
|
|
|
- }
|
|
|
|
- catch ( final IllegalArgumentException e )
|
|
|
|
- {
|
|
|
|
- final String errorMsg = "unknown goto step request: " + requestedStep;
|
|
|
|
- LOGGER.error( pwmRequest, () -> errorMsg );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ final String requestedStep = pwmRequest.readParameterAsString( PARAM_STEP );
|
|
|
|
|
|
- if ( step == GuideStep.START )
|
|
|
|
- {
|
|
|
|
- configGuideBean.getFormData().clear();
|
|
|
|
- configGuideBean.getFormData().putAll( ConfigGuideForm.defaultForm() );
|
|
|
|
- }
|
|
|
|
- else if ( step == GuideStep.NEXT )
|
|
|
|
- {
|
|
|
|
- step = configGuideBean.getStep().next();
|
|
|
|
- while ( step != GuideStep.FINISH && !step.visible( configGuideBean ) )
|
|
|
|
- {
|
|
|
|
- step = step.next();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else if ( step == GuideStep.PREVIOUS )
|
|
|
|
- {
|
|
|
|
- step = configGuideBean.getStep().previous();
|
|
|
|
- while ( step != GuideStep.START && !step.visible( configGuideBean ) )
|
|
|
|
- {
|
|
|
|
- step = step.previous();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ final GuideStep inputStep = StringUtil.isEmpty( requestedStep )
|
|
|
|
+ ? GuideStep.START
|
|
|
|
+ : JavaHelper.readEnumFromString( GuideStep.class, requestedStep )
|
|
|
|
+ .orElseThrow( () -> PwmUnrecoverableException.newException(
|
|
|
|
+ PwmError.ERROR_INTERNAL, "unknown step value" ) );
|
|
|
|
|
|
- if ( step == GuideStep.FINISH )
|
|
|
|
- {
|
|
|
|
- final ContextManager contextManager = ContextManager.getContextManager( pwmRequest );
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- ConfigGuideUtils.writeConfig( contextManager, configGuideBean );
|
|
|
|
- pwmRequest.getPwmSession().getSessionStateBean().setTheme( null );
|
|
|
|
- }
|
|
|
|
- catch ( final PwmException e )
|
|
|
|
- {
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.fromError( e.getErrorInformation(), pwmRequest );
|
|
|
|
- pwmRequest.outputJsonResult( restResultBean );
|
|
|
|
- return ProcessStatus.Halt;
|
|
|
|
- }
|
|
|
|
- catch ( final Exception e )
|
|
|
|
- {
|
|
|
|
- LOGGER.error( pwmRequest, () -> "error during save: " + e.getMessage(), e );
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.fromError( new ErrorInformation(
|
|
|
|
- PwmError.ERROR_INTERNAL,
|
|
|
|
- "error during save: " + e.getMessage()
|
|
|
|
- ), pwmRequest );
|
|
|
|
- pwmRequest.outputJsonResult( restResultBean );
|
|
|
|
- return ProcessStatus.Halt;
|
|
|
|
- }
|
|
|
|
- final HashMap<String, String> resultData = new HashMap<>();
|
|
|
|
- resultData.put( "serverRestart", "true" );
|
|
|
|
- pwmRequest.outputJsonResult( RestResultBean.withData( resultData, Map.class ) );
|
|
|
|
- pwmRequest.invalidateSession();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- configGuideBean.setStep( step );
|
|
|
|
- pwmRequest.outputJsonResult( RestResultBean.forSuccessMessage( pwmRequest, Message.Success_Unknown ) );
|
|
|
|
-
|
|
|
|
- {
|
|
|
|
- final GuideStep finalStep = step;
|
|
|
|
- LOGGER.trace( pwmRequest, () -> "setting current step to: " + finalStep );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ final GuideStep nextEffectiveStep = ConfigGuideUtils.figureNextEffectiveStep( configGuideBean, inputStep );
|
|
|
|
|
|
- return ProcessStatus.Continue;
|
|
|
|
|
|
+ return ConfigGuideUtils.executeNextStep( pwmRequest, configGuideBean, nextEffectiveStep );
|
|
}
|
|
}
|
|
|
|
|
|
@ActionHandler( action = "extendSchema" )
|
|
@ActionHandler( action = "extendSchema" )
|
|
@@ -558,26 +494,24 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
@ActionHandler( action = "readSetting" )
|
|
@ActionHandler( action = "readSetting" )
|
|
public ProcessStatus restReadSetting( final PwmRequest pwmRequest ) throws PwmUnrecoverableException, IOException
|
|
public ProcessStatus restReadSetting( final PwmRequest pwmRequest ) throws PwmUnrecoverableException, IOException
|
|
{
|
|
{
|
|
- final String profileID = "default";
|
|
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
|
|
|
|
- final String settingKey = pwmRequest.readParameterAsString( "key" );
|
|
|
|
- final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
|
|
|
|
|
|
+ final String settingKey = pwmRequest.readParameterAsString( PARAM_KEY );
|
|
final PwmSetting pwmSetting = PwmSetting.forKey( settingKey )
|
|
final PwmSetting pwmSetting = PwmSetting.forKey( settingKey )
|
|
.orElseThrow( () -> new IllegalStateException( "invalid setting parameter value" ) );
|
|
.orElseThrow( () -> new IllegalStateException( "invalid setting parameter value" ) );
|
|
|
|
|
|
- final StoredConfigKey key = StoredConfigKey.forSetting( pwmSetting, profileID, DomainID.DOMAIN_ID_DEFAULT );
|
|
|
|
|
|
+ final StoredConfigKey key = StoredConfigKey.forSetting( pwmSetting, ConfigGuideForm.LDAP_PROFILE_NAME, DomainID.DOMAIN_ID_DEFAULT );
|
|
|
|
|
|
- final Object returnValue;
|
|
|
|
- returnValue = StoredConfigurationUtil.getValueOrDefault( storedConfiguration, key ).toNativeObject();
|
|
|
|
- returnMap.put( "isDefault", StoredConfigurationUtil.isDefaultValue( storedConfiguration, key ) );
|
|
|
|
- returnMap.put( "key", settingKey );
|
|
|
|
- returnMap.put( "category", pwmSetting.getCategory().toString() );
|
|
|
|
- returnMap.put( "syntax", pwmSetting.getSyntax().toString() );
|
|
|
|
|
|
+ final ReadSettingResponse readSettingResponse = ReadSettingResponse.builder()
|
|
|
|
+ .isDefault( StoredConfigurationUtil.isDefaultValue( storedConfiguration, key ) )
|
|
|
|
+ .key( settingKey )
|
|
|
|
+ .category( pwmSetting.getCategory().toString() )
|
|
|
|
+ .syntax( pwmSetting.getSyntax().toString() )
|
|
|
|
+ .value( StoredConfigurationUtil.getValueOrDefault( storedConfiguration, key ).toNativeObject() )
|
|
|
|
+ .build();
|
|
|
|
|
|
- returnMap.put( "value", returnValue );
|
|
|
|
- pwmRequest.outputJsonResult( RestResultBean.withData( returnMap, Map.class ) );
|
|
|
|
|
|
+ pwmRequest.outputJsonResult( RestResultBean.withData( readSettingResponse, ReadSettingResponse.class ) );
|
|
|
|
|
|
return ProcessStatus.Halt;
|
|
return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
@@ -586,26 +520,23 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
public ProcessStatus restWriteSetting( final PwmRequest pwmRequest )
|
|
public ProcessStatus restWriteSetting( final PwmRequest pwmRequest )
|
|
throws PwmUnrecoverableException, IOException
|
|
throws PwmUnrecoverableException, IOException
|
|
{
|
|
{
|
|
- final String profileID = "default";
|
|
|
|
- final String settingKey = pwmRequest.readParameterAsString( "key" );
|
|
|
|
final String bodyString = pwmRequest.readRequestBodyAsString();
|
|
final String bodyString = pwmRequest.readRequestBodyAsString();
|
|
- final PwmSetting pwmSetting = PwmSetting.forKey( settingKey )
|
|
|
|
|
|
+ final PwmSetting pwmSetting = PwmSetting.forKey( pwmRequest.readParameterAsString( PARAM_KEY ) )
|
|
.orElseThrow( () -> new IllegalStateException( "invalid setting parameter value" ) );
|
|
.orElseThrow( () -> new IllegalStateException( "invalid setting parameter value" ) );
|
|
|
|
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
final ConfigGuideBean configGuideBean = getBean( pwmRequest );
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
|
|
|
|
- final StoredConfigKey key = StoredConfigKey.forSetting( pwmSetting, profileID, DomainID.DOMAIN_ID_DEFAULT );
|
|
|
|
-
|
|
|
|
- final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
|
|
|
|
|
|
+ final StoredConfigKey key = StoredConfigKey.forSetting( pwmSetting, ConfigGuideForm.LDAP_PROFILE_NAME, DomainID.DOMAIN_ID_DEFAULT );
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
final StoredValue storedValue = ValueFactory.fromJson( pwmSetting, bodyString );
|
|
final StoredValue storedValue = ValueFactory.fromJson( pwmSetting, bodyString );
|
|
- final List<String> errorMsgs = storedValue.validateValue( pwmSetting );
|
|
|
|
- if ( errorMsgs != null && !errorMsgs.isEmpty() )
|
|
|
|
|
|
+ final List<String> errorMessages = storedValue.validateValue( pwmSetting );
|
|
|
|
+ if ( errorMessages != null && !errorMessages.isEmpty() )
|
|
{
|
|
{
|
|
- returnMap.put( "errorMessage", pwmSetting.getLabel( pwmRequest.getLocale() ) + ": " + errorMsgs.get( 0 ) );
|
|
|
|
|
|
+ final String msg = pwmSetting.getLabel( pwmRequest.getLocale() ) + ": " + errorMessages.get( 0 );
|
|
|
|
+ throw new PwmUnrecoverableException( new ErrorInformation( PwmError.CONFIG_FORMAT_ERROR, msg ) );
|
|
}
|
|
}
|
|
|
|
|
|
if ( pwmSetting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES )
|
|
if ( pwmSetting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES )
|
|
@@ -615,17 +546,23 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
}
|
|
}
|
|
catch ( final Exception e )
|
|
catch ( final Exception e )
|
|
{
|
|
{
|
|
|
|
+ if ( e instanceof PwmUnrecoverableException )
|
|
|
|
+ {
|
|
|
|
+ throw ( PwmUnrecoverableException ) e;
|
|
|
|
+ }
|
|
|
|
+
|
|
final String errorMsg = "error writing default value for setting " + pwmSetting + ", error: " + e.getMessage();
|
|
final String errorMsg = "error writing default value for setting " + pwmSetting + ", error: " + e.getMessage();
|
|
- LOGGER.error( () -> errorMsg, e );
|
|
|
|
- throw new IllegalStateException( errorMsg, e );
|
|
|
|
|
|
+ throw new PwmUnrecoverableException( new ErrorInformation( PwmError.CONFIG_FORMAT_ERROR, errorMsg ) );
|
|
}
|
|
}
|
|
- returnMap.put( "key", settingKey );
|
|
|
|
- returnMap.put( "category", pwmSetting.getCategory().toString() );
|
|
|
|
- returnMap.put( "syntax", pwmSetting.getSyntax().toString() );
|
|
|
|
- returnMap.put( "isDefault", StoredConfigurationUtil.isDefaultValue( storedConfiguration, key ) );
|
|
|
|
- pwmRequest.outputJsonResult( RestResultBean.withData( returnMap, Map.class ) );
|
|
|
|
|
|
|
|
|
|
+ final ReadSettingResponse readSettingResponse = ReadSettingResponse.builder()
|
|
|
|
+ .key( pwmSetting.getKey() )
|
|
|
|
+ .category( pwmSetting.getCategory().toString() )
|
|
|
|
+ .syntax( pwmSetting.getSyntax().toString() )
|
|
|
|
+ .isDefault( StoredConfigurationUtil.isDefaultValue( storedConfiguration, key ) )
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
+ pwmRequest.outputJsonResult( RestResultBean.withData( readSettingResponse, ReadSettingResponse.class ) );
|
|
return ProcessStatus.Halt;
|
|
return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -637,14 +574,14 @@ public class ConfigGuideServlet extends ControlledPwmServlet
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
final StoredConfiguration storedConfiguration = ConfigGuideForm.generateStoredConfig( configGuideBean );
|
|
|
|
|
|
final SettingData settingData = SettingDataMaker.generateSettingData(
|
|
final SettingData settingData = SettingDataMaker.generateSettingData(
|
|
- ConfigGuideForm.DOMAIN_ID,
|
|
|
|
|
|
+ DomainID.systemId(),
|
|
storedConfiguration,
|
|
storedConfiguration,
|
|
pwmRequest.getLabel(),
|
|
pwmRequest.getLabel(),
|
|
pwmRequest.getLocale(),
|
|
pwmRequest.getLocale(),
|
|
- NavTreeSettings.forBasic()
|
|
|
|
|
|
+ NavTreeSettings.builder().domainManageMode( DomainManageMode.single ).build()
|
|
);
|
|
);
|
|
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.withData( settingData, SettingData.class );
|
|
|
|
|
|
+ final RestResultBean<SettingData> restResultBean = RestResultBean.withData( settingData, SettingData.class );
|
|
pwmRequest.outputJsonResult( restResultBean );
|
|
pwmRequest.outputJsonResult( restResultBean );
|
|
return ProcessStatus.Halt;
|
|
return ProcessStatus.Halt;
|
|
}
|
|
}
|