use of password.pwm.PwmApplication in project pwm by pwm-project.
the class RestServlet method service.
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final Instant startTime = Instant.now();
RestResultBean restResultBean = RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE), false);
final PwmApplication pwmApplication;
try {
pwmApplication = ContextManager.getContextManager(req.getServletContext()).getPwmApplication();
} catch (PwmUnrecoverableException e) {
outputRestResultBean(restResultBean, req, resp);
return;
}
final Locale locale;
{
final List<Locale> knownLocales = pwmApplication.getConfig().getKnownLocales();
locale = LocaleHelper.localeResolver(req.getLocale(), knownLocales);
}
final SessionLabel sessionLabel;
try {
sessionLabel = new SessionLabel("rest-" + REQUEST_COUNTER.next(), null, null, RequestInitializationFilter.readUserIPAddress(req, pwmApplication.getConfig()), RequestInitializationFilter.readUserHostname(req, pwmApplication.getConfig()));
} catch (PwmUnrecoverableException e) {
restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown());
outputRestResultBean(restResultBean, req, resp);
return;
}
LOGGER.trace(sessionLabel, "beginning rest service invocation");
if (pwmApplication.getApplicationMode() != PwmApplicationMode.RUNNING) {
outputRestResultBean(restResultBean, req, resp);
return;
}
if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.ENABLE_EXTERNAL_WEBSERVICES)) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "webservices are not enabled");
restResultBean = RestResultBean.fromError(errorInformation, pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown());
outputRestResultBean(restResultBean, req, resp);
return;
}
try {
final RestAuthentication restAuthentication = new RestAuthenticationProcessor(pwmApplication, sessionLabel, req).readRestAuthentication();
LOGGER.debug(sessionLabel, "rest request authentication status: " + JsonUtil.serialize(restAuthentication));
final RestRequest restRequest = RestRequest.forRequest(pwmApplication, restAuthentication, sessionLabel, req);
RequestInitializationFilter.addStaticResponseHeaders(pwmApplication, resp);
preCheck(restRequest);
preCheckRequest(restRequest);
restResultBean = invokeWebService(restRequest);
} catch (PwmUnrecoverableException e) {
restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown());
} catch (Throwable e) {
final String errorMsg = "internal error during rest service invocation: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
restResultBean = RestResultBean.fromError(errorInformation, pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown());
LOGGER.error(sessionLabel, errorInformation);
}
outputRestResultBean(restResultBean, req, resp);
LOGGER.trace(sessionLabel, "completed rest invocation in " + TimeDuration.compactFromCurrent(startTime) + " success=" + !restResultBean.isError());
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class RestResultBean method fromError.
public static RestResultBean fromError(final RestRequest restRequestBean, final ErrorInformation errorInformation) {
final PwmApplication pwmApplication = restRequestBean.getPwmApplication();
final Configuration config = restRequestBean.getPwmApplication().getConfig();
final Locale locale = restRequestBean.getLocale();
return fromError(errorInformation, pwmApplication, locale, config, false);
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class HttpEventManager method sessionDidActivate.
public void sessionDidActivate(final HttpSessionEvent event) {
try {
final HttpSession httpSession = event.getSession();
final PwmSession pwmSession = PwmSessionWrapper.readPwmSession(httpSession);
LOGGER.trace(pwmSession.getLabel(), "activating (de-passivating) session");
final PwmApplication pwmApplication = ContextManager.getPwmApplication(httpSession);
if (pwmApplication != null) {
pwmApplication.getSessionTrackService().addSessionData(pwmSession);
}
} catch (PwmUnrecoverableException e) {
LOGGER.error("unable to activate (de-passivate) session: " + e.getMessage());
}
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class UserMatchViewerFunction method discoverMatchingUsers.
public Collection<UserIdentity> discoverMatchingUsers(final PwmApplication pwmApplication, final int maxResultSize, final StoredConfigurationImpl storedConfiguration, final PwmSetting setting, final String profile) throws Exception {
final Configuration config = new Configuration(storedConfiguration);
final PwmApplication tempApplication = new PwmApplication(pwmApplication.getPwmEnvironment().makeRuntimeInstance(config));
final List<UserPermission> permissions = (List<UserPermission>) storedConfiguration.readSetting(setting, profile).toNativeObject();
for (final UserPermission userPermission : permissions) {
if (userPermission.getType() == UserPermission.Type.ldapQuery) {
if (userPermission.getLdapBase() != null && !userPermission.getLdapBase().isEmpty()) {
testIfLdapDNIsValid(tempApplication, userPermission.getLdapBase(), userPermission.getLdapProfileID());
}
} else if (userPermission.getType() == UserPermission.Type.ldapGroup) {
testIfLdapDNIsValid(tempApplication, userPermission.getLdapBase(), userPermission.getLdapProfileID());
}
}
return LdapPermissionTester.discoverMatchingUsers(tempApplication, maxResultSize, permissions, SessionLabel.SYSTEM_LABEL).keySet();
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class UserMatchViewerFunction method provideFunction.
@Override
public Serializable provideFunction(final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration, final PwmSetting setting, final String profile, final String extraData) throws Exception {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final Date startSearchTime = new Date();
final int maxResultSize = Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_EDITOR_QUERY_FILTER_TEST_LIMIT));
final Collection<UserIdentity> users = discoverMatchingUsers(pwmApplication, maxResultSize, storedConfiguration, setting, profile);
final TimeDuration searchDuration = TimeDuration.fromCurrent(startSearchTime);
final UserMatchViewerResults userMatchViewerResults = new UserMatchViewerResults();
final boolean sizeExceeded = users.size() >= maxResultSize;
userMatchViewerResults.setUsers(users);
userMatchViewerResults.setSearchOperationSummary(LocaleHelper.getLocalizedMessage(Display.Display_SearchResultsInfo, pwmRequest, String.valueOf(users.size()), searchDuration.asLongString(pwmRequest.getLocale())));
userMatchViewerResults.setSizeExceeded(sizeExceeded);
return userMatchViewerResults;
}
Aggregations