Search in sources :

Example 1 with ProcessStatus

use of password.pwm.http.ProcessStatus in project pwm by pwm-project.

the class ControlledPwmServlet method dispatchMethod.

private ProcessStatus dispatchMethod(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    final ProcessAction action = readProcessAction(pwmRequest);
    if (action == null) {
        return ProcessStatus.Continue;
    }
    try {
        final Method interestedMethod = discoverMethodForAction(this.getClass(), action);
        if (interestedMethod != null) {
            interestedMethod.setAccessible(true);
            return (ProcessStatus) interestedMethod.invoke(this, pwmRequest);
        }
    } catch (InvocationTargetException e) {
        final Throwable cause = e.getCause();
        if (cause != null) {
            if (cause instanceof PwmUnrecoverableException) {
                throw (PwmUnrecoverableException) cause;
            }
            final String msg = "unexpected error during action handler for '" + this.getClass().getName() + ":" + action + "', error: " + cause.getMessage();
            LOGGER.error(pwmRequest, msg, e.getCause());
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
        }
        LOGGER.error("uncased invocation error: " + e.getMessage(), e);
    } catch (Throwable e) {
        final String msg = "unexpected error invoking action handler for '" + action + "', error: " + e.getMessage();
        LOGGER.error(msg, e);
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
    }
    final String msg = "missing action handler for '" + action + "'";
    LOGGER.error(msg);
    throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ProcessStatus(password.pwm.http.ProcessStatus) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ProcessStatus

use of password.pwm.http.ProcessStatus in project pwm by pwm-project.

the class ControlledPwmServlet method processAction.

protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException {
    preProcessCheck(pwmRequest);
    final ProcessAction action = readProcessAction(pwmRequest);
    if (action != null) {
        final ProcessStatus status = dispatchMethod(pwmRequest);
        if (status == ProcessStatus.Halt) {
            if (!pwmRequest.getPwmResponse().isCommitted()) {
                if (pwmRequest.getConfig().isDevDebugMode()) {
                    final String msg = "processing complete, handler returned halt but response is not committed";
                    LOGGER.error(pwmRequest, msg, new IllegalStateException(msg));
                }
            }
            return;
        }
        final boolean enablePostRedirectGet = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_SERVLET_ENABLE_POST_REDIRECT_GET));
        if (enablePostRedirectGet) {
            final String servletUrl = pwmRequest.getURL().determinePwmServletPath();
            LOGGER.debug(pwmRequest, "this request is not idempotent, redirecting to self with no action");
            sendOtherRedirect(pwmRequest, servletUrl);
            return;
        }
    }
    examineLastError(pwmRequest);
    if (!pwmRequest.getPwmResponse().isCommitted()) {
        nextStep(pwmRequest);
    }
}
Also used : ProcessStatus(password.pwm.http.ProcessStatus)

Example 3 with ProcessStatus

use of password.pwm.http.ProcessStatus in project pwm by pwm-project.

the class AuthenticationFilter method processUnAuthenticatedSession.

private void processUnAuthenticatedSession(final PwmRequest pwmRequest, final PwmFilterChain chain) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final HttpServletRequest req = pwmRequest.getHttpServletRequest();
    final boolean bypassSso = pwmRequest.getPwmSession().getLoginInfoBean().isLoginFlag(LoginInfoBean.LoginFlag.noSso);
    if (!bypassSso && pwmRequest.getPwmApplication().getApplicationMode() == PwmApplicationMode.RUNNING) {
        final ProcessStatus authenticationProcessStatus = attemptAuthenticationMethods(pwmRequest);
        if (authenticationProcessStatus == ProcessStatus.Halt) {
            return;
        }
    }
    final String originalRequestedUrl = pwmRequest.getURLwithQueryString();
    if (pwmRequest.isAuthenticated()) {
        // redirect back to self so request starts over as authenticated.
        LOGGER.trace(pwmRequest, "inline authentication occurred during this request, redirecting to current url to restart request");
        pwmRequest.getPwmResponse().sendRedirect(originalRequestedUrl);
        return;
    }
    // handle if authenticated during filter process.
    if (pwmSession.isAuthenticated()) {
        pwmSession.getSessionStateBean().setSessionIdRecycleNeeded(true);
        LOGGER.debug(pwmSession, "session authenticated during request, issuing redirect to originally requested url: " + originalRequestedUrl);
        pwmRequest.sendRedirect(originalRequestedUrl);
        return;
    }
    if (pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.BASIC_AUTH_FORCE)) {
        final String displayMessage = LocaleHelper.getLocalizedMessage(Display.Title_Application, pwmRequest);
        pwmRequest.getPwmResponse().setHeader(HttpHeader.WWW_Authenticate, "Basic realm=\"" + displayMessage + "\"");
        pwmRequest.getPwmResponse().setStatus(401);
        return;
    }
    if (pwmRequest.getURL().isLoginServlet()) {
        chain.doFilter();
        return;
    }
    // user is not authenticated so forward to LoginPage.
    LOGGER.trace(pwmSession.getLabel(), "user requested resource requiring authentication (" + req.getRequestURI() + "), but is not authenticated; redirecting to LoginServlet");
    LoginServlet.redirectToLoginServlet(pwmRequest);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmApplication(password.pwm.PwmApplication) ProcessStatus(password.pwm.http.ProcessStatus) PwmSession(password.pwm.http.PwmSession)

Example 4 with ProcessStatus

use of password.pwm.http.ProcessStatus in project pwm by pwm-project.

the class ConfigEditorServlet method restSearchSettings.

@ActionHandler(action = "search")
private ProcessStatus restSearchSettings(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String bodyData = pwmRequest.readRequestBodyAsString();
    final Map<String, String> valueMap = JsonUtil.deserializeStringMap(bodyData);
    final Locale locale = pwmRequest.getLocale();
    final RestResultBean restResultBean;
    final String searchTerm = valueMap.get("search");
    final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
    if (searchTerm != null && !searchTerm.isEmpty()) {
        final ArrayList<StoredConfigurationImpl.ConfigRecordID> searchResults = new ArrayList<>(configManagerBean.getStoredConfiguration().search(searchTerm, locale));
        final ConcurrentHashMap<String, Map<String, SearchResultItem>> returnData = new ConcurrentHashMap<>();
        searchResults.parallelStream().filter(recordID -> recordID.getRecordType() == StoredConfigurationImpl.ConfigRecordID.RecordType.SETTING).forEach(recordID -> {
            final PwmSetting setting = (PwmSetting) recordID.getRecordID();
            final SearchResultItem item = new SearchResultItem(setting.getCategory().toString(), storedConfiguration.readSetting(setting, recordID.getProfileID()).toDebugString(locale), setting.getCategory().toMenuLocationDebug(recordID.getProfileID(), locale), storedConfiguration.isDefaultValue(setting, recordID.getProfileID()), recordID.getProfileID());
            final String returnCategory = item.getNavigation();
            returnData.putIfAbsent(returnCategory, new ConcurrentHashMap<>());
            returnData.get(returnCategory).put(setting.getKey(), item);
        });
        final TreeMap<String, Map<String, SearchResultItem>> outputMap = new TreeMap<>();
        for (final String key : returnData.keySet()) {
            outputMap.put(key, new TreeMap<>(returnData.get(key)));
        }
        restResultBean = RestResultBean.withData(outputMap);
        LOGGER.trace(pwmRequest, "finished search operation with " + returnData.size() + " results in " + TimeDuration.fromCurrent(startTime).asCompactString());
    } else {
        restResultBean = RestResultBean.withData(new ArrayList<StoredConfigurationImpl.ConfigRecordID>());
    }
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) SmsItemBean(password.pwm.bean.SmsItemBean) PwmSetting(password.pwm.config.PwmSetting) ServletException(javax.servlet.ServletException) AppProperty(password.pwm.AppProperty) PwmConstants(password.pwm.PwmConstants) PwmError(password.pwm.error.PwmError) Message(password.pwm.i18n.Message) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ValueMetaData(password.pwm.config.stored.ValueMetaData) ErrorInformation(password.pwm.error.ErrorInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) SessionLabel(password.pwm.bean.SessionLabel) Locale(java.util.Locale) RestResultBean(password.pwm.ws.server.RestResultBean) Map(java.util.Map) UserIdentity(password.pwm.bean.UserIdentity) HealthStatus(password.pwm.health.HealthStatus) PwmSettingCategory(password.pwm.config.PwmSettingCategory) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) JsonUtil(password.pwm.util.java.JsonUtil) ValueFactory(password.pwm.config.value.ValueFactory) ProcessStatus(password.pwm.http.ProcessStatus) PwmOperationalException(password.pwm.error.PwmOperationalException) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PwmSettingTemplate(password.pwm.config.PwmSettingTemplate) Instant(java.time.Instant) Serializable(java.io.Serializable) ConfigurationChecker(password.pwm.health.ConfigurationChecker) List(java.util.List) HttpMethod(password.pwm.http.HttpMethod) HealthRecord(password.pwm.health.HealthRecord) StoredValue(password.pwm.config.StoredValue) PasswordData(password.pwm.util.PasswordData) LDAPStatusChecker(password.pwm.health.LDAPStatusChecker) ConfigurationProperty(password.pwm.config.stored.ConfigurationProperty) ActionValue(password.pwm.config.value.ActionValue) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) LdapBrowser(password.pwm.ldap.LdapBrowser) PwmSettingTemplateSet(password.pwm.config.PwmSettingTemplateSet) Configuration(password.pwm.config.Configuration) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) PwmSettingSyntax(password.pwm.config.PwmSettingSyntax) MacroMachine(password.pwm.util.macro.MacroMachine) PwmSession(password.pwm.http.PwmSession) ControlledPwmServlet(password.pwm.http.servlet.ControlledPwmServlet) PwmApplication(password.pwm.PwmApplication) SettingUIFunction(password.pwm.config.SettingUIFunction) StringUtil(password.pwm.util.java.StringUtil) RestRandomPasswordServer(password.pwm.ws.server.rest.RestRandomPasswordServer) HashMap(java.util.HashMap) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmRequest(password.pwm.http.PwmRequest) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AbstractPwmServlet(password.pwm.http.servlet.AbstractPwmServlet) ResourceBundle(java.util.ResourceBundle) StringTokenizer(java.util.StringTokenizer) RemoteWebServiceValue(password.pwm.config.value.RemoteWebServiceValue) PwmException(password.pwm.error.PwmException) HealthTopic(password.pwm.health.HealthTopic) JspUrl(password.pwm.http.JspUrl) RandomPasswordGenerator(password.pwm.util.RandomPasswordGenerator) FileValue(password.pwm.config.value.FileValue) PwmApplicationMode(password.pwm.PwmApplicationMode) PwmHttpRequestWrapper(password.pwm.http.PwmHttpRequestWrapper) PwmLogger(password.pwm.util.logging.PwmLogger) IOException(java.io.IOException) ConfigManagerServlet(password.pwm.http.servlet.configmanager.ConfigManagerServlet) X509CertificateValue(password.pwm.config.value.X509CertificateValue) WebServlet(javax.servlet.annotation.WebServlet) DatabaseStatusChecker(password.pwm.health.DatabaseStatusChecker) PrivateKeyValue(password.pwm.config.value.PrivateKeyValue) SmsQueueManager(password.pwm.util.queue.SmsQueueManager) TreeMap(java.util.TreeMap) HttpsServerCertificateManager(password.pwm.util.secure.HttpsServerCertificateManager) Config(password.pwm.i18n.Config) Collections(java.util.Collections) TimeDuration(password.pwm.util.java.TimeDuration) HealthData(password.pwm.ws.server.rest.bean.HealthData) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

ProcessStatus (password.pwm.http.ProcessStatus)4 PwmApplication (password.pwm.PwmApplication)2 PwmSession (password.pwm.http.PwmSession)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1