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);
}
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);
}
}
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());
}
}
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());
}
}
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);
}
}
}
Aggregations