Search in sources :

Example 1 with LdapBrowser

use of password.pwm.ldap.LdapBrowser in project pwm by pwm-project.

the class ConfigGuideServlet method restBrowseLdap.

@ActionHandler(action = "browseLdap")
private ProcessStatus restBrowseLdap(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
    if (configGuideBean.getStep() == GuideStep.LDAP_PROXY) {
        storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_KEY, null);
        storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_PASSWORD, LDAP_PROFILE_KEY, null);
    }
    final Instant startTime = Instant.now();
    final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String profile = inputMap.get("profile");
    final String dn = inputMap.getOrDefault("dn", "");
    final LdapBrowser ldapBrowser = new LdapBrowser(pwmRequest.getPwmApplication().getLdapConnectionService().getChaiProviderFactory(), storedConfiguration);
    final LdapBrowser.LdapBrowseResult result = ldapBrowser.doBrowse(profile, dn);
    ldapBrowser.close();
    LOGGER.trace(pwmRequest, "performed ldapBrowse operation in " + TimeDuration.fromCurrent(startTime).asCompactString() + ", result=" + JsonUtil.serialize(result));
    pwmRequest.outputJsonResult(RestResultBean.withData(result));
    return ProcessStatus.Halt;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Instant(java.time.Instant) LdapBrowser(password.pwm.ldap.LdapBrowser)

Example 2 with LdapBrowser

use of password.pwm.ldap.LdapBrowser in project pwm by pwm-project.

the class ConfigEditorServlet method restBrowseLdap.

@ActionHandler(action = "browseLdap")
private ProcessStatus restBrowseLdap(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String profile = inputMap.get("profile");
    final String dn = inputMap.containsKey("dn") ? inputMap.get("dn") : "";
    final LdapBrowser ldapBrowser = new LdapBrowser(pwmRequest.getPwmApplication().getLdapConnectionService().getChaiProviderFactory(), configManagerBean.getStoredConfiguration());
    LdapBrowser.LdapBrowseResult result;
    try {
        result = ldapBrowser.doBrowse(profile, dn);
    } catch (PwmUnrecoverableException e) {
        // Probably was given a bad dn, better just browse without a DN than error out completely
        result = ldapBrowser.doBrowse(profile, "");
    }
    ldapBrowser.close();
    LOGGER.trace(pwmRequest, "performed ldapBrowse operation in " + TimeDuration.fromCurrent(startTime).asCompactString() + ", result=" + JsonUtil.serialize(result));
    pwmRequest.outputJsonResult(RestResultBean.withData(result));
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LdapBrowser(password.pwm.ldap.LdapBrowser)

Aggregations

Instant (java.time.Instant)2 LdapBrowser (password.pwm.ldap.LdapBrowser)2 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 ConfigGuideBean (password.pwm.http.bean.ConfigGuideBean)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1