Search in sources :

Example 1 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class LDAPStatusChecker method healthForNewConfiguration.

public static HealthData healthForNewConfiguration(final PwmApplication pwmApplication, final Configuration config, final Locale locale, final String profileID, final boolean testContextless, final boolean fullTest) throws PwmUnrecoverableException {
    final PwmApplication tempApplication = new PwmApplication(pwmApplication.getPwmEnvironment().makeRuntimeInstance(config));
    final LDAPStatusChecker ldapStatusChecker = new LDAPStatusChecker();
    final List<HealthRecord> profileRecords = new ArrayList<>();
    final LdapProfile ldapProfile = config.getLdapProfiles().get(profileID);
    profileRecords.addAll(ldapStatusChecker.checkBasicLdapConnectivity(tempApplication, config, ldapProfile, testContextless));
    if (fullTest) {
        profileRecords.addAll(ldapStatusChecker.checkLdapServerUrls(pwmApplication, config, ldapProfile));
    }
    if (profileRecords.isEmpty()) {
        profileRecords.add(HealthRecord.forMessage(HealthMessage.LDAP_OK));
    }
    if (fullTest) {
        profileRecords.addAll(ldapStatusChecker.doLdapTestUserCheck(config, ldapProfile, tempApplication));
    }
    return HealthRecord.asHealthDataBean(config, locale, profileRecords);
}
Also used : PwmApplication(password.pwm.PwmApplication) ArrayList(java.util.ArrayList) LdapProfile(password.pwm.config.profile.LdapProfile)

Example 2 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class ContextManager method initialize.

public void initialize() {
    try {
        Locale.setDefault(PwmConstants.DEFAULT_LOCALE);
    } catch (Exception e) {
        outputError("unable to set default locale as Java machine default locale: " + e.getMessage());
    }
    Configuration configuration = null;
    PwmApplicationMode mode = PwmApplicationMode.ERROR;
    final ParameterReader parameterReader = new ParameterReader(servletContext);
    final File applicationPath;
    {
        final String applicationPathStr = parameterReader.readApplicationPath();
        if (applicationPathStr == null || applicationPathStr.isEmpty()) {
            startupErrorInformation = new ErrorInformation(PwmError.ERROR_ENVIRONMENT_ERROR, "application path is not specified");
            return;
        } else {
            applicationPath = new File(applicationPathStr);
        }
    }
    File configurationFile = null;
    try {
        configurationFile = locateConfigurationFile(applicationPath);
        configReader = new ConfigurationReader(configurationFile);
        configReader.getStoredConfiguration().lock();
        configuration = configReader.getConfiguration();
        mode = startupErrorInformation == null ? configReader.getConfigMode() : PwmApplicationMode.ERROR;
        if (startupErrorInformation == null) {
            startupErrorInformation = configReader.getConfigFileError();
        }
        if (PwmApplicationMode.ERROR == mode) {
            outputError("Startup Error: " + (startupErrorInformation == null ? "un-specified error" : startupErrorInformation.toDebugStr()));
        }
    } catch (Throwable e) {
        handleStartupError("unable to initialize application due to configuration related error: ", e);
    }
    LOGGER.debug("configuration file was loaded from " + (configurationFile == null ? "null" : configurationFile.getAbsoluteFile()));
    final Collection<PwmEnvironment.ApplicationFlag> applicationFlags = parameterReader.readApplicationFlags();
    final Map<PwmEnvironment.ApplicationParameter, String> applicationParams = parameterReader.readApplicationParams();
    try {
        final PwmEnvironment pwmEnvironment = new PwmEnvironment.Builder(configuration, applicationPath).setApplicationMode(mode).setConfigurationFile(configurationFile).setContextManager(this).setFlags(applicationFlags).setParams(applicationParams).createPwmEnvironment();
        pwmApplication = new PwmApplication(pwmEnvironment);
    } catch (Exception e) {
        handleStartupError("unable to initialize application: ", e);
    }
    final String threadName = JavaHelper.makeThreadName(pwmApplication, this.getClass()) + " timer";
    taskMaster = new Timer(threadName, true);
    taskMaster.schedule(new RestartFlagWatcher(), 1031, 1031);
    boolean reloadOnChange = true;
    long fileScanFrequencyMs = 5000;
    {
        if (pwmApplication != null) {
            reloadOnChange = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_RELOAD_ON_CHANGE));
            fileScanFrequencyMs = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_FILE_SCAN_FREQUENCY));
        }
        if (reloadOnChange) {
            taskMaster.schedule(new ConfigFileWatcher(), fileScanFrequencyMs, fileScanFrequencyMs);
        }
        checkConfigForSaveOnRestart(configReader, pwmApplication);
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) PwmEnvironment(password.pwm.PwmEnvironment) PwmApplicationMode(password.pwm.PwmApplicationMode) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) Timer(java.util.Timer) File(java.io.File) ConfigurationReader(password.pwm.config.stored.ConfigurationReader)

Example 3 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class HttpEventManager method sessionDestroyed.

public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
    final HttpSession httpSession = httpSessionEvent.getSession();
    try {
        if (httpSession.getAttribute(PwmConstants.SESSION_ATTR_PWM_SESSION) != null) {
            final PwmSession pwmSession = PwmSessionWrapper.readPwmSession(httpSession);
            if (pwmSession != null) {
                pwmSession.unauthenticateUser(null);
            }
            final PwmApplication pwmApplication = ContextManager.getPwmApplication(httpSession);
            if (pwmApplication != null) {
                pwmApplication.getSessionTrackService().removeSessionData(pwmSession);
            }
            LOGGER.trace(pwmSession, "destroyed session");
        } else {
            LOGGER.trace("invalidated uninitialized session");
        }
    } catch (PwmUnrecoverableException e) {
        LOGGER.warn("error during httpSessionDestroyed: " + e.getMessage());
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) HttpSession(javax.servlet.http.HttpSession) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 4 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class HttpEventManager method sessionCreated.

public void sessionCreated(final HttpSessionEvent httpSessionEvent) {
    final HttpSession httpSession = httpSessionEvent.getSession();
    try {
        final ContextManager contextManager = ContextManager.getContextManager(httpSession);
        final PwmApplication pwmApplication = contextManager.getPwmApplication();
        httpSession.setAttribute(PwmConstants.SESSION_ATTR_PWM_APP_NONCE, pwmApplication.getRuntimeNonce());
        if (pwmApplication != null && pwmApplication.getStatisticsManager() != null) {
            pwmApplication.getStatisticsManager().updateEps(EpsStatistic.SESSIONS, 1);
        }
        LOGGER.trace("new http session created");
    } catch (PwmUnrecoverableException e) {
        LOGGER.warn("error during sessionCreated event: " + e.getMessage());
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) HttpSession(javax.servlet.http.HttpSession) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 5 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class RequestInitializationFilter method checkAndInitSessionState.

private void checkAndInitSessionState(final HttpServletRequest request) throws PwmUnrecoverableException {
    final ContextManager contextManager = ContextManager.getContextManager(request.getSession());
    final PwmApplication pwmApplication = contextManager.getPwmApplication();
    {
        // destroy any outdated sessions
        final HttpSession httpSession = request.getSession(false);
        if (httpSession != null) {
            final String sessionPwmAppNonce = (String) httpSession.getAttribute(PwmConstants.SESSION_ATTR_PWM_APP_NONCE);
            if (sessionPwmAppNonce == null || !sessionPwmAppNonce.equals(pwmApplication.getRuntimeNonce())) {
                LOGGER.debug("invalidating http session created with non-current servlet context");
                httpSession.invalidate();
            }
        }
    }
    {
        // handle pwmSession init and assignment.
        final HttpSession httpSession = request.getSession();
        if (httpSession.getAttribute(PwmConstants.SESSION_ATTR_PWM_SESSION) == null) {
            final PwmSession pwmSession = PwmSession.createPwmSession(pwmApplication);
            PwmSessionWrapper.sessionMerge(pwmApplication, pwmSession, httpSession);
        }
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) HttpSession(javax.servlet.http.HttpSession) ContextManager(password.pwm.http.ContextManager) PwmSession(password.pwm.http.PwmSession)

Aggregations

PwmApplication (password.pwm.PwmApplication)120 PwmSession (password.pwm.http.PwmSession)55 ErrorInformation (password.pwm.error.ErrorInformation)54 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)49 PwmOperationalException (password.pwm.error.PwmOperationalException)36 Configuration (password.pwm.config.Configuration)33 UserIdentity (password.pwm.bean.UserIdentity)27 FormConfiguration (password.pwm.config.value.data.FormConfiguration)25 PwmException (password.pwm.error.PwmException)25 IOException (java.io.IOException)22 ServletException (javax.servlet.ServletException)18 UserInfo (password.pwm.ldap.UserInfo)18 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)17 ChaiUser (com.novell.ldapchai.ChaiUser)16 Locale (java.util.Locale)13 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)13 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)13 MacroMachine (password.pwm.util.macro.MacroMachine)12 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)11 Instant (java.time.Instant)10