|
@@ -24,11 +24,6 @@ package password.pwm.http.servlet.configguide;
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.novell.ldapchai.exception.ChaiUnavailableException;
|
|
import com.novell.ldapchai.exception.ChaiUnavailableException;
|
|
-import com.novell.ldapchai.provider.ChaiConfiguration;
|
|
|
|
-import com.novell.ldapchai.provider.ChaiProvider;
|
|
|
|
-import com.novell.ldapchai.provider.ChaiProviderFactory;
|
|
|
|
-import com.novell.ldapchai.provider.ChaiSetting;
|
|
|
|
-import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
|
|
import password.pwm.AppProperty;
|
|
import password.pwm.AppProperty;
|
|
import password.pwm.PwmApplication;
|
|
import password.pwm.PwmApplication;
|
|
import password.pwm.PwmApplicationMode;
|
|
import password.pwm.PwmApplicationMode;
|
|
@@ -39,7 +34,6 @@ import password.pwm.config.PwmSetting;
|
|
import password.pwm.config.function.UserMatchViewerFunction;
|
|
import password.pwm.config.function.UserMatchViewerFunction;
|
|
import password.pwm.config.profile.LdapProfile;
|
|
import password.pwm.config.profile.LdapProfile;
|
|
import password.pwm.config.stored.ConfigurationProperty;
|
|
import password.pwm.config.stored.ConfigurationProperty;
|
|
-import password.pwm.config.stored.ConfigurationReader;
|
|
|
|
import password.pwm.config.stored.StoredConfigurationImpl;
|
|
import password.pwm.config.stored.StoredConfigurationImpl;
|
|
import password.pwm.config.value.FileValue;
|
|
import password.pwm.config.value.FileValue;
|
|
import password.pwm.error.ErrorInformation;
|
|
import password.pwm.error.ErrorInformation;
|
|
@@ -56,39 +50,29 @@ import password.pwm.health.HealthTopic;
|
|
import password.pwm.health.LDAPStatusChecker;
|
|
import password.pwm.health.LDAPStatusChecker;
|
|
import password.pwm.http.ContextManager;
|
|
import password.pwm.http.ContextManager;
|
|
import password.pwm.http.HttpMethod;
|
|
import password.pwm.http.HttpMethod;
|
|
|
|
+import password.pwm.http.ProcessStatus;
|
|
import password.pwm.http.PwmHttpRequestWrapper;
|
|
import password.pwm.http.PwmHttpRequestWrapper;
|
|
import password.pwm.http.PwmRequest;
|
|
import password.pwm.http.PwmRequest;
|
|
-import password.pwm.http.PwmRequestAttribute;
|
|
|
|
-import password.pwm.http.PwmSession;
|
|
|
|
import password.pwm.http.PwmURL;
|
|
import password.pwm.http.PwmURL;
|
|
import password.pwm.http.bean.ConfigGuideBean;
|
|
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.configeditor.ConfigEditorServlet;
|
|
import password.pwm.http.servlet.configeditor.ConfigEditorServlet;
|
|
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.SchemaManager;
|
|
|
|
import password.pwm.ldap.schema.SchemaOperationResult;
|
|
import password.pwm.ldap.schema.SchemaOperationResult;
|
|
-import password.pwm.util.LDAPPermissionCalculator;
|
|
|
|
import password.pwm.util.java.JavaHelper;
|
|
import password.pwm.util.java.JavaHelper;
|
|
import password.pwm.util.java.JsonUtil;
|
|
import password.pwm.util.java.JsonUtil;
|
|
-import password.pwm.util.java.Percent;
|
|
|
|
import password.pwm.util.java.TimeDuration;
|
|
import password.pwm.util.java.TimeDuration;
|
|
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;
|
|
import password.pwm.ws.server.rest.bean.HealthData;
|
|
import password.pwm.ws.server.rest.bean.HealthData;
|
|
|
|
|
|
-import javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.annotation.WebServlet;
|
|
import javax.servlet.annotation.WebServlet;
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStream;
|
|
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
-import java.net.InetAddress;
|
|
|
|
-import java.net.InetSocketAddress;
|
|
|
|
-import java.net.Socket;
|
|
|
|
-import java.net.SocketAddress;
|
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -106,14 +90,12 @@ import java.util.Map;
|
|
PwmConstants.URL_PREFIX_PRIVATE + "/config/ConfigGuide"
|
|
PwmConstants.URL_PREFIX_PRIVATE + "/config/ConfigGuide"
|
|
}
|
|
}
|
|
)
|
|
)
|
|
-public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
|
|
|
|
+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 = "default";
|
|
private static final String LDAP_PROFILE_KEY = "default";
|
|
|
|
|
|
-
|
|
|
|
public enum ConfigGuideAction implements AbstractPwmServlet.ProcessAction {
|
|
public enum ConfigGuideAction implements AbstractPwmServlet.ProcessAction {
|
|
ldapHealth(HttpMethod.GET),
|
|
ldapHealth(HttpMethod.GET),
|
|
updateForm(HttpMethod.POST),
|
|
updateForm(HttpMethod.POST),
|
|
@@ -141,22 +123,23 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- protected ConfigGuideAction readProcessAction(final PwmRequest request)
|
|
|
|
- throws PwmUnrecoverableException
|
|
|
|
- {
|
|
|
|
- try {
|
|
|
|
- return ConfigGuideAction.valueOf(request.readParameterAsString(PwmConstants.PARAM_ACTION_REQUEST));
|
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Class<? extends ProcessAction> getProcessActionsClass() {
|
|
|
|
+ return ConfigGuideAction.class;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private ConfigGuideBean getBean(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
|
|
|
|
+ return pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigGuideBean.class);
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void processAction(final PwmRequest pwmRequest)
|
|
|
|
- throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException
|
|
|
|
|
|
+ protected void nextStep(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
|
|
|
|
+ ConfigGuideUtils.forwardToJSP(pwmRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException
|
|
{
|
|
{
|
|
- final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
|
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
|
|
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
|
|
|
|
|
|
if (pwmApplication.getSessionStateService().getBean(pwmRequest, ConfigGuideBean.class).getStep() == GuideStep.START) {
|
|
if (pwmApplication.getSessionStateService().getBean(pwmRequest, ConfigGuideBean.class).getStep() == GuideStep.START) {
|
|
@@ -167,9 +150,8 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
|
|
|
|
if (pwmApplication.getApplicationMode() != PwmApplicationMode.NEW) {
|
|
if (pwmApplication.getApplicationMode() != PwmApplicationMode.NEW) {
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE,"ConfigGuide unavailable unless in NEW mode");
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE,"ConfigGuide unavailable unless in NEW mode");
|
|
- LOGGER.error(pwmSession, errorInformation.toDebugStr());
|
|
|
|
- pwmRequest.respondWithError(errorInformation);
|
|
|
|
- return;
|
|
|
|
|
|
+ LOGGER.error(pwmRequest, errorInformation.toDebugStr());
|
|
|
|
+ throw new PwmUnrecoverableException(errorInformation);
|
|
}
|
|
}
|
|
|
|
|
|
if (!configGuideBean.getFormData().containsKey(ConfigGuideFormField.PARAM_APP_SITEURL)) {
|
|
if (!configGuideBean.getFormData().containsKey(ConfigGuideFormField.PARAM_APP_SITEURL)) {
|
|
@@ -195,121 +177,38 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- final ConfigGuideAction action = readProcessAction(pwmRequest);
|
|
|
|
- if (action != null) {
|
|
|
|
- pwmRequest.validatePwmFormID();
|
|
|
|
- switch (action) {
|
|
|
|
- case ldapHealth:
|
|
|
|
- restLdapHealth(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case updateForm:
|
|
|
|
- restUpdateLdapForm(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case gotoStep:
|
|
|
|
- restGotoStep(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case useConfiguredCerts:
|
|
|
|
- restUseConfiguredCerts(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case uploadConfig:
|
|
|
|
- restUploadConfig(pwmRequest);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case extendSchema:
|
|
|
|
- restExtendSchema(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case viewAdminMatches:
|
|
|
|
- restViewAdminMatches(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case browseLdap:
|
|
|
|
- restBrowseLdap(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case uploadJDBCDriver:
|
|
|
|
- restUploadJDBCDriver(pwmRequest, configGuideBean);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- case skipGuide:
|
|
|
|
- restSkipGuide(pwmRequest);
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- JavaHelper.unhandledSwitchStatement(action);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!pwmRequest.getPwmResponse().getHttpServletResponse().isCommitted()) {
|
|
|
|
- forwardToJSP(pwmRequest);
|
|
|
|
- }
|
|
|
|
|
|
+ return ProcessStatus.Continue;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void restUploadConfig(final PwmRequest pwmRequest)
|
|
|
|
|
|
+ @ActionHandler(action = "uploadConfig")
|
|
|
|
+ private ProcessStatus restUploadConfig(final PwmRequest pwmRequest)
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
{
|
|
{
|
|
- final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
|
|
|
|
- final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
|
- final HttpServletRequest req = pwmRequest.getHttpServletRequest();
|
|
|
|
-
|
|
|
|
- if (pwmApplication.getApplicationMode() == PwmApplicationMode.RUNNING) {
|
|
|
|
- final String errorMsg = "config upload is not permitted when in running mode";
|
|
|
|
- final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_UPLOAD_FAILURE,errorMsg,new String[]{errorMsg});
|
|
|
|
- pwmRequest.respondWithError(errorInformation, true);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (ServletFileUpload.isMultipartContent(req)) {
|
|
|
|
- final InputStream uploadedFile = pwmRequest.readFileUploadStream(PwmConstants.PARAM_FILE_UPLOAD);
|
|
|
|
- if (uploadedFile != null) {
|
|
|
|
- try {
|
|
|
|
- final StoredConfigurationImpl storedConfig = StoredConfigurationImpl.fromXml(uploadedFile);
|
|
|
|
- final List<String> configErrors = storedConfig.validateValues();
|
|
|
|
- if (configErrors != null && !configErrors.isEmpty()) {
|
|
|
|
- throw new PwmOperationalException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR,configErrors.get(0)));
|
|
|
|
- }
|
|
|
|
- writeConfig(ContextManager.getContextManager(req.getSession()),storedConfig);
|
|
|
|
- LOGGER.trace(pwmSession, "read config from file: " + storedConfig.toString());
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
|
|
|
|
- pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
|
|
|
|
- req.getSession().invalidate();
|
|
|
|
- } catch (PwmException e) {
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
|
|
|
|
- pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
|
|
|
|
- LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_UPLOAD_FAILURE, "error reading config file: no file present in upload");
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
|
|
|
|
- pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
|
|
|
|
- LOGGER.error(pwmSession, errorInformation.toDebugStr());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ ConfigGuideUtils.restUploadConfig(pwmRequest);
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- private void restUseConfiguredCerts(
|
|
|
|
- final PwmRequest pwmRequest,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
|
|
+ @ActionHandler(action = "useConfiguredCerts")
|
|
|
|
+ private ProcessStatus restUseConfiguredCerts(
|
|
|
|
+ final PwmRequest pwmRequest
|
|
)
|
|
)
|
|
throws PwmUnrecoverableException, IOException
|
|
throws PwmUnrecoverableException, IOException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
+
|
|
final boolean value = Boolean.parseBoolean(pwmRequest.readParameterAsString("value"));
|
|
final boolean value = Boolean.parseBoolean(pwmRequest.readParameterAsString("value"));
|
|
configGuideBean.setUseConfiguredCerts(value);
|
|
configGuideBean.setUseConfiguredCerts(value);
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- private void restLdapHealth(
|
|
|
|
- final PwmRequest pwmRequest,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
|
|
+ @ActionHandler(action = "ldapHealth")
|
|
|
|
+ private ProcessStatus restLdapHealth(
|
|
|
|
+ final PwmRequest pwmRequest
|
|
)
|
|
)
|
|
throws IOException, PwmUnrecoverableException
|
|
throws IOException, PwmUnrecoverableException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
|
|
final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
|
|
final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
|
|
final Configuration tempConfiguration = new Configuration(storedConfigurationImpl);
|
|
final Configuration tempConfiguration = new Configuration(storedConfigurationImpl);
|
|
@@ -324,7 +223,7 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
switch (configGuideBean.getStep()) {
|
|
switch (configGuideBean.getStep()) {
|
|
case LDAP_SERVER: {
|
|
case LDAP_SERVER: {
|
|
try {
|
|
try {
|
|
- checkLdapServer(configGuideBean);
|
|
|
|
|
|
+ ConfigGuideUtils.checkLdapServer(configGuideBean);
|
|
records.add(password.pwm.health.HealthRecord.forMessage(HealthMessage.LDAP_OK));
|
|
records.add(password.pwm.health.HealthRecord.forMessage(HealthMessage.LDAP_OK));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Can not connect to remote server: " + e.getMessage()));
|
|
records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Can not connect to remote server: " + e.getMessage()));
|
|
@@ -400,20 +299,16 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
jsonOutput.overall = HealthMonitor.getMostSevereHealthStatus(records).toString();
|
|
jsonOutput.overall = HealthMonitor.getMostSevereHealthStatus(records).toString();
|
|
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
|
|
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- public static Percent stepProgress(final GuideStep step) {
|
|
|
|
- final int ordinal = step.ordinal();
|
|
|
|
- final int total = GuideStep.values().length - 2;
|
|
|
|
- return new Percent(ordinal,total);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void restViewAdminMatches(
|
|
|
|
- final PwmRequest pwmRequest,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
|
|
+ @ActionHandler(action = "viewAdminMatches")
|
|
|
|
+ private ProcessStatus restViewAdminMatches(
|
|
|
|
+ final PwmRequest pwmRequest
|
|
)
|
|
)
|
|
- throws IOException, ServletException
|
|
|
|
|
|
+ throws IOException, ServletException, PwmUnrecoverableException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
|
|
try {
|
|
try {
|
|
final UserMatchViewerFunction userMatchViewerFunction = new UserMatchViewerFunction();
|
|
final UserMatchViewerFunction userMatchViewerFunction = new UserMatchViewerFunction();
|
|
@@ -422,20 +317,23 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(output));
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(output));
|
|
} catch (PwmException e) {
|
|
} catch (PwmException e) {
|
|
LOGGER.error(pwmRequest,e.getErrorInformation());
|
|
LOGGER.error(pwmRequest,e.getErrorInformation());
|
|
- pwmRequest.respondWithError(e.getErrorInformation());
|
|
|
|
|
|
+ pwmRequest.respondWithError(e.getErrorInformation(), false);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error while testing matches = " + e.getMessage());
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error while testing matches = " + e.getMessage());
|
|
LOGGER.error(pwmRequest,errorInformation);
|
|
LOGGER.error(pwmRequest,errorInformation);
|
|
pwmRequest.respondWithError(errorInformation);
|
|
pwmRequest.respondWithError(errorInformation);
|
|
}
|
|
}
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- private void restBrowseLdap(
|
|
|
|
- final PwmRequest pwmRequest,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
|
|
+ @ActionHandler(action = "browseLdap")
|
|
|
|
+ private ProcessStatus restBrowseLdap(
|
|
|
|
+ final PwmRequest pwmRequest
|
|
)
|
|
)
|
|
throws IOException, ServletException, PwmUnrecoverableException
|
|
throws IOException, ServletException, PwmUnrecoverableException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
+
|
|
final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
|
|
final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
|
|
if (configGuideBean.getStep() == GuideStep.LDAP_PROXY) {
|
|
if (configGuideBean.getStep() == GuideStep.LDAP_PROXY) {
|
|
storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_KEY, null);
|
|
storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_KEY, null);
|
|
@@ -445,7 +343,7 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
final Instant startTime = Instant.now();
|
|
final Instant startTime = Instant.now();
|
|
final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
|
|
final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
|
|
final String profile = inputMap.get("profile");
|
|
final String profile = inputMap.get("profile");
|
|
- final String dn = inputMap.containsKey("dn") ? inputMap.get("dn") : "";
|
|
|
|
|
|
+ final String dn = inputMap.getOrDefault("dn", "");
|
|
|
|
|
|
final LdapBrowser ldapBrowser = new LdapBrowser(storedConfiguration);
|
|
final LdapBrowser ldapBrowser = new LdapBrowser(storedConfiguration);
|
|
final LdapBrowser.LdapBrowseResult result = ldapBrowser.doBrowse(profile, dn);
|
|
final LdapBrowser.LdapBrowseResult result = ldapBrowser.doBrowse(profile, dn);
|
|
@@ -456,14 +354,18 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
+ ", result=" + JsonUtil.serialize(result));
|
|
+ ", result=" + JsonUtil.serialize(result));
|
|
|
|
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(result));
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(result));
|
|
|
|
+
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- private void restUpdateLdapForm(
|
|
|
|
- final PwmRequest pwmRequest,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
|
|
+ @ActionHandler(action = "updateForm")
|
|
|
|
+ private ProcessStatus restUpdateForm(
|
|
|
|
+ final PwmRequest pwmRequest
|
|
)
|
|
)
|
|
throws IOException, PwmUnrecoverableException
|
|
throws IOException, PwmUnrecoverableException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
+
|
|
final String bodyString = pwmRequest.readRequestBodyAsString();
|
|
final String bodyString = pwmRequest.readRequestBodyAsString();
|
|
final Map<ConfigGuideFormField,String> incomingFormData = JsonUtil.deserialize(bodyString, new TypeToken<Map<ConfigGuideFormField, String>>() {
|
|
final Map<ConfigGuideFormField,String> incomingFormData = JsonUtil.deserialize(bodyString, new TypeToken<Map<ConfigGuideFormField, String>>() {
|
|
});
|
|
});
|
|
@@ -473,58 +375,55 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
}
|
|
}
|
|
|
|
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
|
|
+
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- private void restGotoStep(final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean)
|
|
|
|
|
|
+ @ActionHandler(action = "gotoStep")
|
|
|
|
+ private ProcessStatus restGotoStep(final PwmRequest pwmRequest)
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
{
|
|
{
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
+
|
|
final String requestedStep = pwmRequest.readParameterAsString("step");
|
|
final String requestedStep = pwmRequest.readParameterAsString("step");
|
|
- GuideStep step = null;
|
|
|
|
|
|
+ GuideStep step = GuideStep.START;
|
|
if (requestedStep != null && requestedStep.length() > 0) {
|
|
if (requestedStep != null && requestedStep.length() > 0) {
|
|
try {
|
|
try {
|
|
step = GuideStep.valueOf(requestedStep);
|
|
step = GuideStep.valueOf(requestedStep);
|
|
- } catch (IllegalArgumentException e) { /* */ }
|
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
+ final String errorMsg = "unknown goto step request: " + requestedStep;
|
|
|
|
+ LOGGER.error(pwmRequest, errorMsg);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if (GuideStep.START.equals(GuideStep.valueOf(requestedStep))) {
|
|
|
|
|
|
+ if (step == GuideStep.START) {
|
|
configGuideBean.getFormData().clear();
|
|
configGuideBean.getFormData().clear();
|
|
configGuideBean.getFormData().putAll(ConfigGuideForm.defaultForm());
|
|
configGuideBean.getFormData().putAll(ConfigGuideForm.defaultForm());
|
|
- }
|
|
|
|
-
|
|
|
|
- if ("NEXT".equals(requestedStep)) {
|
|
|
|
|
|
+ } else if (step == GuideStep.NEXT) {
|
|
step = configGuideBean.getStep().next();
|
|
step = configGuideBean.getStep().next();
|
|
while (step != GuideStep.FINISH && !step.visible(configGuideBean)) {
|
|
while (step != GuideStep.FINISH && !step.visible(configGuideBean)) {
|
|
step =step.next();
|
|
step =step.next();
|
|
}
|
|
}
|
|
- } else if ("PREVIOUS".equals(requestedStep)) {
|
|
|
|
|
|
+ } else if (step == GuideStep.PREVIOUS) {
|
|
step = configGuideBean.getStep().previous();
|
|
step = configGuideBean.getStep().previous();
|
|
while (step != GuideStep.START && !step.visible(configGuideBean)) {
|
|
while (step != GuideStep.START && !step.visible(configGuideBean)) {
|
|
step = step.previous();
|
|
step = step.previous();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (step == null) {
|
|
|
|
- final String errorMsg = "unknown goto step request: " + requestedStep;
|
|
|
|
- final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR,errorMsg);
|
|
|
|
- final RestResultBean restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
|
|
|
|
- LOGGER.error(pwmRequest,errorInformation.toDebugStr());
|
|
|
|
- pwmRequest.outputJsonResult(restResultBean);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (step == GuideStep.FINISH) {
|
|
if (step == GuideStep.FINISH) {
|
|
final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
|
|
final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
|
|
try {
|
|
try {
|
|
- writeConfig(contextManager, configGuideBean);
|
|
|
|
|
|
+ ConfigGuideUtils.writeConfig(contextManager, configGuideBean);
|
|
pwmRequest.getPwmSession().getSessionStateBean().setTheme(null);
|
|
pwmRequest.getPwmSession().getSessionStateBean().setTheme(null);
|
|
} catch (PwmException e) {
|
|
} catch (PwmException e) {
|
|
final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
|
|
final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
- return;
|
|
|
|
|
|
+ return ProcessStatus.Halt;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
final RestResultBean restResultBean = RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN,"error during save: " + e.getMessage()), pwmRequest);
|
|
final RestResultBean restResultBean = RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN,"error during save: " + e.getMessage()), pwmRequest);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
pwmRequest.outputJsonResult(restResultBean);
|
|
- return;
|
|
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
final HashMap<String,String> resultData = new HashMap<>();
|
|
final HashMap<String,String> resultData = new HashMap<>();
|
|
resultData.put("serverRestart","true");
|
|
resultData.put("serverRestart","true");
|
|
@@ -535,125 +434,34 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
LOGGER.trace("setting current step to: " + step);
|
|
LOGGER.trace("setting current step to: " + step);
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
- private void writeConfig(
|
|
|
|
- final ContextManager contextManager,
|
|
|
|
- final ConfigGuideBean configGuideBean
|
|
|
|
- ) throws PwmOperationalException, PwmUnrecoverableException {
|
|
|
|
- final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
|
|
|
|
- final String configPassword = configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_CONFIG_PASSWORD);
|
|
|
|
- if (configPassword != null && configPassword.length() > 0) {
|
|
|
|
- storedConfiguration.setPassword(configPassword);
|
|
|
|
- } else {
|
|
|
|
- storedConfiguration.writeConfigProperty(ConfigurationProperty.PASSWORD_HASH, null);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "false");
|
|
|
|
- writeConfig(contextManager, storedConfiguration);
|
|
|
|
|
|
+ return ProcessStatus.Continue;
|
|
}
|
|
}
|
|
|
|
|
|
- private static void writeConfig(
|
|
|
|
- final ContextManager contextManager,
|
|
|
|
- final StoredConfigurationImpl storedConfiguration
|
|
|
|
- ) throws PwmOperationalException, PwmUnrecoverableException {
|
|
|
|
- final ConfigurationReader configReader = contextManager.getConfigReader();
|
|
|
|
- final PwmApplication pwmApplication = contextManager.getPwmApplication();
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- // add a random security key
|
|
|
|
- storedConfiguration.initNewRandomSecurityKey();
|
|
|
|
-
|
|
|
|
- configReader.saveConfiguration(storedConfiguration, pwmApplication, null);
|
|
|
|
-
|
|
|
|
- contextManager.requestPwmApplicationRestart();
|
|
|
|
- } catch (PwmException e) {
|
|
|
|
- throw new PwmOperationalException(e.getErrorInformation());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG,"unable to save configuration: " + e.getLocalizedMessage());
|
|
|
|
- throw new PwmOperationalException(errorInformation);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- static void forwardToJSP(
|
|
|
|
- final PwmRequest pwmRequest
|
|
|
|
- )
|
|
|
|
- throws IOException, ServletException, PwmUnrecoverableException
|
|
|
|
|
|
+ @ActionHandler(action = "extendSchema")
|
|
|
|
+ private ProcessStatus restExtendSchema(final PwmRequest pwmRequest)
|
|
|
|
+ throws IOException, PwmUnrecoverableException
|
|
{
|
|
{
|
|
- final ConfigGuideBean configGuideBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest,ConfigGuideBean.class);
|
|
|
|
-
|
|
|
|
- if (configGuideBean.getStep() == GuideStep.LDAP_PERMISSIONS) {
|
|
|
|
- final LDAPPermissionCalculator ldapPermissionCalculator = new LDAPPermissionCalculator(ConfigGuideForm.generateStoredConfig(configGuideBean));
|
|
|
|
- pwmRequest.setAttribute(PwmRequestAttribute.LdapPermissionItems, ldapPermissionCalculator);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final HttpServletRequest req = pwmRequest.getHttpServletRequest();
|
|
|
|
- final ServletContext servletContext = req.getSession().getServletContext();
|
|
|
|
- String destURL = '/' + PwmConstants.URL_JSP_CONFIG_GUIDE;
|
|
|
|
- destURL = destURL.replace("%1%", configGuideBean.getStep().toString().toLowerCase());
|
|
|
|
- servletContext.getRequestDispatcher(destURL).forward(req, pwmRequest.getPwmResponse().getHttpServletResponse());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static SchemaOperationResult extendSchema(final ConfigGuideBean configGuideBean, final boolean doSchemaExtension) {
|
|
|
|
- final Map<ConfigGuideFormField,String> form = configGuideBean.getFormData();
|
|
|
|
- final boolean ldapServerSecure = "true".equalsIgnoreCase(form.get(ConfigGuideFormField.PARAM_LDAP_SECURE));
|
|
|
|
- final String ldapUrl = "ldap" + (ldapServerSecure ? "s" : "") + "://" + form.get(ConfigGuideFormField.PARAM_LDAP_HOST) + ":" + form.get(ConfigGuideFormField.PARAM_LDAP_PORT);
|
|
|
|
- try {
|
|
|
|
- final ChaiConfiguration chaiConfiguration = new ChaiConfiguration(ldapUrl, form.get(ConfigGuideFormField.PARAM_LDAP_PROXY_DN), form.get(ConfigGuideFormField.PARAM_LDAP_PROXY_PW));
|
|
|
|
- chaiConfiguration.setSetting(ChaiSetting.PROMISCUOUS_SSL,"true");
|
|
|
|
- final ChaiProvider chaiProvider = ChaiProviderFactory.createProvider(chaiConfiguration);
|
|
|
|
- if (doSchemaExtension) {
|
|
|
|
- return SchemaManager.extendSchema(chaiProvider);
|
|
|
|
- } else {
|
|
|
|
- return SchemaManager.checkExistingSchema(chaiProvider);
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- LOGGER.error("unable to create schema extender object: " + e.getMessage());
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
|
|
|
|
- private void restExtendSchema(final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean)
|
|
|
|
- throws IOException
|
|
|
|
- {
|
|
|
|
try {
|
|
try {
|
|
- final SchemaOperationResult schemaOperationResult = extendSchema(configGuideBean, true);
|
|
|
|
|
|
+ final SchemaOperationResult schemaOperationResult = ConfigGuideUtils.extendSchema(configGuideBean, true);
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(schemaOperationResult.getOperationLog()));
|
|
pwmRequest.outputJsonResult(RestResultBean.withData(schemaOperationResult.getOperationLog()));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN,e.getMessage());
|
|
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN,e.getMessage());
|
|
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
|
|
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
|
|
LOGGER.error(pwmRequest, e.getMessage(), e);
|
|
LOGGER.error(pwmRequest, e.getMessage(), e);
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private void checkLdapServer(final ConfigGuideBean configGuideBean) throws PwmOperationalException, IOException {
|
|
|
|
- final Map<ConfigGuideFormField,String> formData = configGuideBean.getFormData();
|
|
|
|
- final String host = formData.get(ConfigGuideFormField.PARAM_LDAP_HOST);
|
|
|
|
- final int port = Integer.parseInt(formData.get(ConfigGuideFormField.PARAM_LDAP_PORT));
|
|
|
|
-
|
|
|
|
- { // socket test
|
|
|
|
- final InetAddress inetAddress = InetAddress.getByName(host);
|
|
|
|
- final SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
|
|
|
|
- final Socket socket = new Socket();
|
|
|
|
-
|
|
|
|
- final int timeout = 2000;
|
|
|
|
- socket.connect(socketAddress, timeout);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if (Boolean.parseBoolean(formData.get(ConfigGuideFormField.PARAM_LDAP_SECURE))) {
|
|
|
|
- X509Utils.readRemoteCertificates(host, port);
|
|
|
|
- }
|
|
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- static void restUploadJDBCDriver(final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean)
|
|
|
|
|
|
+ @ActionHandler(action = "uploadJDBCDriver")
|
|
|
|
+ private ProcessStatus restUploadJDBCDriver(final PwmRequest pwmRequest)
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
throws PwmUnrecoverableException, IOException, ServletException
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
|
|
+ final ConfigGuideBean configGuideBean = getBean(pwmRequest);
|
|
final int maxFileSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.CONFIG_MAX_JDBC_JAR_SIZE));
|
|
final int maxFileSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.CONFIG_MAX_JDBC_JAR_SIZE));
|
|
final FileValue fileValue = ConfigEditorServlet.readFileUploadToSettingValue(pwmRequest, maxFileSize);
|
|
final FileValue fileValue = ConfigEditorServlet.readFileUploadToSettingValue(pwmRequest, maxFileSize);
|
|
configGuideBean.setDatabaseDriver(fileValue);
|
|
configGuideBean.setDatabaseDriver(fileValue);
|
|
@@ -664,9 +472,13 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
|
|
pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
|
|
LOGGER.error(pwmRequest, e.getErrorInformation().toDebugStr());
|
|
LOGGER.error(pwmRequest, e.getErrorInformation().toDebugStr());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return ProcessStatus.Halt;
|
|
}
|
|
}
|
|
|
|
|
|
- private void restSkipGuide(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
|
|
|
|
|
|
+ @ActionHandler(action = "skipGuide")
|
|
|
|
+ private ProcessStatus restSkipGuide(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException
|
|
|
|
+ {
|
|
final Map<String,String> inputJson = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
|
|
final Map<String,String> inputJson = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
|
|
final String password = inputJson.get("password");
|
|
final String password = inputJson.get("password");
|
|
final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
|
|
final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
|
|
@@ -674,14 +486,15 @@ public class ConfigGuideServlet extends AbstractPwmServlet {
|
|
final StoredConfigurationImpl storedConfiguration = new StoredConfigurationImpl();
|
|
final StoredConfigurationImpl storedConfiguration = new StoredConfigurationImpl();
|
|
storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "true");
|
|
storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "true");
|
|
storedConfiguration.setPassword(password);
|
|
storedConfiguration.setPassword(password);
|
|
- writeConfig(contextManager, storedConfiguration);
|
|
|
|
|
|
+ ConfigGuideUtils.writeConfig(contextManager, storedConfiguration);
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
|
|
pwmRequest.invalidateSession();
|
|
pwmRequest.invalidateSession();
|
|
} catch (PwmOperationalException e) {
|
|
} catch (PwmOperationalException e) {
|
|
LOGGER.error("error during skip config guide: " + e.getMessage(),e);
|
|
LOGGER.error("error during skip config guide: " + e.getMessage(),e);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ return ProcessStatus.Halt;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|