Search in sources :

Example 1 with PwmURL

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

the class AuthenticationFilter method processFilter.

public void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain chain) throws IOException, ServletException {
    final PwmURL pwmURL = pwmRequest.getURL();
    if (pwmURL.isPublicUrl() && !pwmURL.isLoginServlet()) {
        chain.doFilter();
        return;
    }
    try {
        final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
        final PwmSession pwmSession = pwmRequest.getPwmSession();
        if (pwmApplication.getApplicationMode() == PwmApplicationMode.NEW) {
            if (pwmRequest.getURL().isConfigGuideURL()) {
                chain.doFilter();
                return;
            }
        }
        if (pwmApplication.getApplicationMode() == PwmApplicationMode.CONFIGURATION) {
            if (pwmRequest.getURL().isConfigManagerURL()) {
                chain.doFilter();
                return;
            }
        }
        // user is already authenticated
        if (pwmSession.isAuthenticated()) {
            this.processAuthenticatedSession(pwmRequest, chain);
        } else {
            this.processUnAuthenticatedSession(pwmRequest, chain);
        }
    } catch (PwmUnrecoverableException e) {
        LOGGER.error(e.getErrorInformation());
        pwmRequest.respondWithError(e.getErrorInformation(), true);
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) PwmURL(password.pwm.http.PwmURL) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmSession(password.pwm.http.PwmSession)

Example 2 with PwmURL

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

the class ApplicationModeFilter method checkConfigModes.

private static ProcessStatus checkConfigModes(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmApplicationMode mode = pwmApplication.getApplicationMode();
    final PwmURL pwmURL = pwmRequest.getURL();
    if (mode == PwmApplicationMode.NEW) {
        // check if current request is actually for the config url, if it is, just do nothing.
        if (pwmURL.isCommandServletURL() || pwmURL.isRestService()) {
            return ProcessStatus.Continue;
        }
        if (pwmURL.isConfigGuideURL() || pwmURL.isReferenceURL()) {
            return ProcessStatus.Continue;
        } else {
            LOGGER.debug("unable to find a valid configuration, redirecting " + pwmURL + " to ConfigGuide");
            pwmRequest.sendRedirect(PwmServletDefinition.ConfigGuide);
            return ProcessStatus.Halt;
        }
    }
    if (mode == PwmApplicationMode.ERROR) {
        ErrorInformation rootError = ContextManager.getContextManager(pwmRequest.getHttpServletRequest().getSession()).getStartupErrorInformation();
        if (rootError == null) {
            rootError = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE, "Application startup failed.");
        }
        pwmRequest.respondWithError(rootError);
        return ProcessStatus.Halt;
    }
    // allow oauth
    if (pwmURL.isOauthConsumer()) {
        return ProcessStatus.Continue;
    }
    // block if public request and not running or in trial
    if (!PwmConstants.TRIAL_MODE) {
        if (mode != PwmApplicationMode.RUNNING) {
            final boolean permittedURl = pwmURL.isResourceURL() || pwmURL.isIndexPage() || pwmURL.isConfigManagerURL() || pwmURL.isConfigGuideURL() || pwmURL.isCommandServletURL() || pwmURL.isReferenceURL() || pwmURL.isLoginServlet() || pwmURL.isLogoutURL() || pwmURL.isOauthConsumer() || pwmURL.isAdminUrl() || pwmURL.isRestService();
            if (!permittedURl) {
                final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_APPLICATION_NOT_RUNNING);
                pwmRequest.respondWithError(errorInformation);
                return ProcessStatus.Halt;
            }
        }
    }
    return ProcessStatus.Continue;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) PwmURL(password.pwm.http.PwmURL) PwmApplicationMode(password.pwm.PwmApplicationMode)

Example 3 with PwmURL

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

the class ObsoleteUrlFilter method redirectOldUrls.

private ProcessStatus redirectOldUrls(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    if (pwmRequest == null || pwmRequest.getURL() == null) {
        return ProcessStatus.Continue;
    }
    final PwmURL pwmURL = pwmRequest.getURL();
    if (pwmURL.isResourceURL() || pwmURL.isCommandServletURL()) {
        return ProcessStatus.Continue;
    }
    if (pwmRequest.getMethod() != HttpMethod.GET) {
        return ProcessStatus.Continue;
    }
    if (!pwmRequest.readParametersAsMap().isEmpty()) {
        return ProcessStatus.Continue;
    }
    final String requestUrl = pwmRequest.getURLwithoutQueryString();
    final String requestServletUrl = requestUrl.substring(pwmRequest.getContextPath().length(), requestUrl.length());
    for (final PwmServletDefinition pwmServletDefinition : PwmServletDefinition.values()) {
        boolean match = false;
        for (final String patternUrl : pwmServletDefinition.urlPatterns()) {
            if (patternUrl.equals(requestServletUrl)) {
                match = true;
                break;
            }
        }
        if (match) {
            if (!pwmServletDefinition.servletUrl().equals(requestServletUrl)) {
                LOGGER.debug(pwmRequest, "obsolete url of '" + requestServletUrl + "' detected, redirecting to canonical URL of '" + pwmServletDefinition.servletUrl() + "'");
                StatisticsManager.incrementStat(pwmRequest, Statistic.OBSOLETE_URL_REQUESTS);
                pwmRequest.sendRedirect(pwmServletDefinition);
                return ProcessStatus.Halt;
            }
        }
    }
    return ProcessStatus.Continue;
}
Also used : PwmURL(password.pwm.http.PwmURL) PwmServletDefinition(password.pwm.http.servlet.PwmServletDefinition)

Example 4 with PwmURL

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

the class SessionFilter method processFilter.

public void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain chain) throws IOException, ServletException, PwmUnrecoverableException {
    final int requestID = REQUEST_COUNTER.incrementAndGet();
    // output request information to debug log
    final Instant startTime = Instant.now();
    pwmRequest.debugHttpRequestToLog("requestID=" + requestID);
    final PwmURL pwmURL = pwmRequest.getURL();
    if (!pwmURL.isRestService() && !pwmURL.isResourceURL()) {
        if (handleStandardRequestOperations(pwmRequest) == ProcessStatus.Halt) {
            return;
        }
    }
    try {
        chain.doFilter();
    } catch (IOException e) {
        LOGGER.trace(pwmRequest.getPwmSession(), "IO exception during servlet processing: " + e.getMessage());
        throw new ServletException(e);
    } catch (Throwable e) {
        if (e instanceof ServletException && e.getCause() != null && e.getCause() instanceof NoClassDefFoundError && e.getCause().getMessage() != null && e.getCause().getMessage().contains("JaxbAnnotationIntrospector")) {
            // this is a jersey 1.18 bug that occurs once per execution
            LOGGER.debug("ignoring JaxbAnnotationIntrospector NoClassDefFoundError: " + e.getMessage());
        } else {
            LOGGER.warn(pwmRequest.getPwmSession(), "unhandled exception " + e.getMessage(), e);
        }
        throw new ServletException(e);
    }
    final TimeDuration requestExecuteTime = TimeDuration.fromCurrent(startTime);
    pwmRequest.debugHttpRequestToLog("completed requestID=" + requestID + " in " + requestExecuteTime.asCompactString());
}
Also used : ServletException(javax.servlet.ServletException) Instant(java.time.Instant) PwmURL(password.pwm.http.PwmURL) TimeDuration(password.pwm.util.java.TimeDuration) IOException(java.io.IOException)

Example 5 with PwmURL

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

the class CaptchaUtility method captchaEnabledForRequest.

public static boolean captchaEnabledForRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    if (!checkIfCaptchaConfigEnabled(pwmRequest)) {
        return false;
    }
    if (checkIfCaptchaParamPresent(pwmRequest)) {
        return false;
    }
    if (checkRequestForCaptchaSkipCookie(pwmRequest)) {
        return false;
    }
    if (!checkIntruderCount(pwmRequest)) {
        return false;
    }
    final Set<ApplicationPage> protectedModules = pwmRequest.getConfig().readSettingAsOptionList(PwmSetting.CAPTCHA_PROTECTED_PAGES, ApplicationPage.class);
    final PwmURL pwmURL = pwmRequest.getURL();
    boolean enabled = false;
    if (protectedModules != null) {
        if (protectedModules.contains(ApplicationPage.LOGIN) && pwmURL.isLoginServlet()) {
            enabled = true;
        } else if (protectedModules.contains(ApplicationPage.FORGOTTEN_PASSWORD) && pwmURL.isForgottenPasswordServlet()) {
            enabled = true;
        } else if (protectedModules.contains(ApplicationPage.FORGOTTEN_USERNAME) && pwmURL.isForgottenUsernameServlet()) {
            enabled = true;
        } else if (protectedModules.contains(ApplicationPage.USER_ACTIVATION) && pwmURL.isUserActivationServlet()) {
            enabled = true;
        } else if (protectedModules.contains(ApplicationPage.NEW_USER_REGISTRATION) && pwmURL.isNewUserRegistrationServlet()) {
            enabled = true;
        }
    }
    return enabled;
}
Also used : ApplicationPage(password.pwm.config.option.ApplicationPage) PwmURL(password.pwm.http.PwmURL)

Aggregations

PwmURL (password.pwm.http.PwmURL)14 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 PwmApplication (password.pwm.PwmApplication)4 PwmException (password.pwm.error.PwmException)4 PwmApplicationMode (password.pwm.PwmApplicationMode)3 PwmSession (password.pwm.http.PwmSession)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LocalSessionStateBean (password.pwm.bean.LocalSessionStateBean)2 Configuration (password.pwm.config.Configuration)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmRequest (password.pwm.http.PwmRequest)2 TimeDuration (password.pwm.util.java.TimeDuration)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1