Search in sources :

Example 1 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method preProcessCheck.

@Override
public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    if (pwmApplication.getSessionStateService().getBean(pwmRequest, ConfigGuideBean.class).getStep() == GuideStep.START) {
        pwmApplication.getSessionStateService().clearBean(pwmRequest, ConfigGuideBean.class);
    }
    final ConfigGuideBean configGuideBean = pwmApplication.getSessionStateService().getBean(pwmRequest, ConfigGuideBean.class);
    if (pwmApplication.getApplicationMode() != PwmApplicationMode.NEW) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "ConfigGuide unavailable unless in NEW mode");
        LOGGER.error(pwmRequest, errorInformation.toDebugStr());
        throw new PwmUnrecoverableException(errorInformation);
    }
    if (!configGuideBean.getFormData().containsKey(ConfigGuideFormField.PARAM_APP_SITEURL)) {
        final URI uri = URI.create(pwmRequest.getHttpServletRequest().getRequestURL().toString());
        final int port = PwmURL.portForUriSchema(uri);
        final String newUri = uri.getScheme() + "://" + uri.getHost() + ":" + port + pwmRequest.getContextPath();
        configGuideBean.getFormData().put(ConfigGuideFormField.PARAM_APP_SITEURL, newUri);
    }
    if (configGuideBean.getStep() == GuideStep.LDAP_CERT) {
        final String ldapServerString = ConfigGuideForm.figureLdapUrlFromFormConfig(configGuideBean.getFormData());
        try {
            final URI ldapServerUri = new URI(ldapServerString);
            if ("ldaps".equalsIgnoreCase(ldapServerUri.getScheme())) {
                configGuideBean.setLdapCertificates(X509Utils.readRemoteCertificates(ldapServerUri));
                configGuideBean.setCertsTrustedbyKeystore(X509Utils.testIfLdapServerCertsInDefaultKeystore(ldapServerUri));
            } else {
                configGuideBean.setLdapCertificates(null);
                configGuideBean.setCertsTrustedbyKeystore(false);
            }
        } catch (Exception e) {
            LOGGER.error("error reading/testing ldap server certificates: " + e.getMessage());
        }
    }
    return ProcessStatus.Continue;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) URI(java.net.URI) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 2 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restExtendSchema.

@ActionHandler(action = "extendSchema")
private ProcessStatus restExtendSchema(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    try {
        final SchemaOperationResult schemaOperationResult = ConfigGuideUtils.extendSchema(pwmRequest.getPwmApplication(), configGuideBean, true);
        pwmRequest.outputJsonResult(RestResultBean.withData(schemaOperationResult.getOperationLog()));
    } catch (Exception e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, e.getMessage(), e);
    }
    return ProcessStatus.Halt;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) ErrorInformation(password.pwm.error.ErrorInformation) SchemaOperationResult(password.pwm.ldap.schema.SchemaOperationResult) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 3 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restUploadJDBCDriver.

@ActionHandler(action = "uploadJDBCDriver")
private ProcessStatus restUploadJDBCDriver(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    try {
        final ConfigGuideBean configGuideBean = getBean(pwmRequest);
        final int maxFileSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.CONFIG_MAX_JDBC_JAR_SIZE));
        final FileValue fileValue = ConfigEditorServletUtils.readFileUploadToSettingValue(pwmRequest, maxFileSize);
        configGuideBean.setDatabaseDriver(fileValue);
        final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
        pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
    } catch (PwmException e) {
        final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
        pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
        LOGGER.error(pwmRequest, e.getErrorInformation().toDebugStr());
    }
    return ProcessStatus.Halt;
}
Also used : FileValue(password.pwm.config.value.FileValue) PwmException(password.pwm.error.PwmException) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 4 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restWriteSetting.

@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    final String profileID = "default";
    final String key = pwmRequest.readParameterAsString("key");
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final PwmSetting setting = PwmSetting.forKey(key);
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    try {
        final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
        final List<String> errorMsgs = storedValue.validateValue(setting);
        if (errorMsgs != null && !errorMsgs.isEmpty()) {
            returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
        }
        if (setting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES) {
            configGuideBean.getFormData().put(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA, JsonUtil.serialize((Serializable) storedValue.toNativeObject()));
        }
    } catch (Exception e) {
        final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
        LOGGER.error(errorMsg, e);
        throw new IllegalStateException(errorMsg, e);
    }
    returnMap.put("key", key);
    returnMap.put("category", setting.getCategory().toString());
    returnMap.put("syntax", setting.getSyntax().toString());
    returnMap.put("isDefault", storedConfigurationImpl.isDefaultValue(setting, profileID));
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Serializable(java.io.Serializable) StoredValue(password.pwm.config.StoredValue) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideUtils method forwardToJSP.

static void forwardToJSP(final PwmRequest pwmRequest) throws IOException, ServletException, 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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) LDAPPermissionCalculator(password.pwm.util.LDAPPermissionCalculator) ServletContext(javax.servlet.ServletContext)

Aggregations

ConfigGuideBean (password.pwm.http.bean.ConfigGuideBean)13 PwmException (password.pwm.error.PwmException)7 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)6 IOException (java.io.IOException)6 ServletException (javax.servlet.ServletException)6 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 LinkedHashMap (java.util.LinkedHashMap)5 ErrorInformation (password.pwm.error.ErrorInformation)4 RestResultBean (password.pwm.ws.server.RestResultBean)4 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 PwmApplication (password.pwm.PwmApplication)2 PwmSetting (password.pwm.config.PwmSetting)2 UserMatchViewerFunction (password.pwm.config.function.UserMatchViewerFunction)2 URI (java.net.URI)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1