Search in sources :

Example 71 with PwmApplication

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());
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ErrorInformation(password.pwm.error.ErrorInformation) SessionLabel(password.pwm.bean.SessionLabel) List(java.util.List)

Example 72 with PwmApplication

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);
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration)

Example 73 with PwmApplication

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());
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) HttpSession(javax.servlet.http.HttpSession) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 74 with PwmApplication

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();
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) List(java.util.List) UserPermission(password.pwm.config.value.data.UserPermission)

Example 75 with PwmApplication

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;
}
Also used : PwmApplication(password.pwm.PwmApplication) UserIdentity(password.pwm.bean.UserIdentity) TimeDuration(password.pwm.util.java.TimeDuration) Date(java.util.Date)

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