Search in sources :

Example 26 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class RestStatusServer method doGetStatusData.

@RestMethodHandler(method = HttpMethod.GET, produces = HttpContentType.json, consumes = HttpContentType.json)
public RestResultBean doGetStatusData(final RestRequest restRequest) throws PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final String username = restRequest.readParameterAsString("username");
    final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
    try {
        final ChaiProvider chaiProvider = targetUserIdentity.getChaiProvider();
        final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), chaiProvider);
        final MacroMachine macroMachine = MacroMachine.forUser(restRequest.getPwmApplication(), restRequest.getLocale(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity());
        final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, restRequest.getPwmApplication().getConfig(), restRequest.getLocale(), macroMachine);
        StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_STATUS);
        final RestResultBean restResultBean = RestResultBean.withData(publicUserInfoBean);
        LOGGER.debug(restRequest.getSessionLabel(), "completed REST status request in " + TimeDuration.compactFromCurrent(startTime) + ", result=" + JsonUtil.serialize(restResultBean));
        return restResultBean;
    } catch (PwmException e) {
        return RestResultBean.fromError(e.getErrorInformation());
    } catch (Exception e) {
        final String errorMsg = "unexpected error building json response: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) Instant(java.time.Instant) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) PublicUserInfoBean(password.pwm.bean.pub.PublicUserInfoBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) RestResultBean(password.pwm.ws.server.RestResultBean) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 27 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class PeopleSearchServlet method restLoadClientData.

@ActionHandler(action = "clientData")
private ProcessStatus restLoadClientData(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final PeopleSearchConfiguration peopleSearchConfiguration = PeopleSearchConfiguration.fromConfiguration(pwmRequest.getPwmApplication());
    final PeopleSearchClientConfigBean peopleSearchClientConfigBean = PeopleSearchClientConfigBean.fromConfig(pwmRequest.getPwmApplication(), peopleSearchConfiguration, pwmRequest.getLocale(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel());
    final RestResultBean restResultBean = RestResultBean.withData(peopleSearchClientConfigBean);
    LOGGER.trace(pwmRequest, "returning clientData: " + JsonUtil.serialize(restResultBean));
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : RestResultBean(password.pwm.ws.server.RestResultBean)

Example 28 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class PeopleSearchServlet method restSearchRequest.

@ActionHandler(action = "search")
private ProcessStatus restSearchRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final Map<String, Object> jsonBodyMap = pwmRequest.readBodyAsJsonMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String username = jsonBodyMap.get("username") == null ? null : jsonBodyMap.get("username").toString();
    final boolean includeDisplayName = pwmRequest.readParameterAsBoolean("includeDisplayName");
    final PeopleSearchDataReader peopleSearchDataReader = new PeopleSearchDataReader(pwmRequest);
    final SearchResultBean searchResultBean = peopleSearchDataReader.makeSearchResultBean(username, includeDisplayName);
    final RestResultBean restResultBean = RestResultBean.withData(searchResultBean);
    addExpiresHeadersToResponse(pwmRequest);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.trace(pwmRequest, "returning " + searchResultBean.getSearchResults().size() + " results for search request '" + username + "'");
    return ProcessStatus.Halt;
}
Also used : RestResultBean(password.pwm.ws.server.RestResultBean)

Example 29 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class RestCheckPasswordServer method doOperation.

public RestResultBean doOperation(final RestRequest restRequest, final JsonInput jsonInput) throws PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    if (StringUtil.isEmpty(jsonInput.getPassword1())) {
        final String errorMessage = "missing field '" + FIELD_PASSWORD_1 + "'";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMessage, new String[] { FIELD_PASSWORD_1 });
        return RestResultBean.fromError(restRequest, errorInformation);
    }
    try {
        final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInput.getUsername());
        final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiProvider());
        final PasswordCheckRequest checkRequest = new PasswordCheckRequest(targetUserIdentity.getUserIdentity(), StringUtil.isEmpty(jsonInput.getPassword1()) ? null : new PasswordData(jsonInput.getPassword1()), StringUtil.isEmpty(jsonInput.getPassword2()) ? null : new PasswordData(jsonInput.getPassword2()), userInfo);
        restRequest.getPwmApplication().getStatisticsManager().incrementValue(Statistic.REST_CHECKPASSWORD);
        final PasswordUtility.PasswordCheckInfo passwordCheckInfo = PasswordUtility.checkEnteredPassword(restRequest.getPwmApplication(), restRequest.getLocale(), targetUserIdentity.getChaiUser(), checkRequest.getUserInfo(), null, checkRequest.getPassword1(), checkRequest.getPassword2());
        final JsonOutput jsonOutput = JsonOutput.fromPasswordCheckInfo(passwordCheckInfo);
        final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
        final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
        LOGGER.trace(restRequest.getSessionLabel(), "REST /checkpassword response (" + timeDuration.asCompactString() + "): " + JsonUtil.serialize(jsonOutput));
        return restResultBean;
    } catch (PwmException e) {
        LOGGER.debug(restRequest.getSessionLabel(), "REST /checkpassword error during execution: " + e.getMessage());
        return RestResultBean.fromError(restRequest, e.getErrorInformation());
    } catch (Exception e) {
        final String errorMessage = "unexpected error executing web service: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
        LOGGER.error(restRequest.getSessionLabel(), errorInformation.toDebugStr(), e);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : Instant(java.time.Instant) PasswordUtility(password.pwm.util.operations.PasswordUtility) UserInfo(password.pwm.ldap.UserInfo) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PasswordData(password.pwm.util.PasswordData) TimeDuration(password.pwm.util.java.TimeDuration) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 30 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class RestRandomPasswordServer method doPostRandomPasswordForm.

@RestMethodHandler(method = HttpMethod.POST, consumes = HttpContentType.form, produces = HttpContentType.json)
public RestResultBean doPostRandomPasswordForm(final RestRequest restRequest) throws PwmUnrecoverableException {
    final JsonInput jsonInput = new JsonInput();
    jsonInput.username = restRequest.readParameterAsString("username", PwmHttpRequestWrapper.Flag.BypassValidation);
    jsonInput.strength = restRequest.readParameterAsInt("strength", 0);
    jsonInput.maxLength = restRequest.readParameterAsInt("maxLength", 0);
    jsonInput.minLength = restRequest.readParameterAsInt("minLength", 0);
    jsonInput.chars = restRequest.readParameterAsString("chars", PwmHttpRequestWrapper.Flag.BypassValidation);
    jsonInput.noUser = restRequest.readParameterAsBoolean("noUser");
    try {
        final JsonOutput jsonOutput = doOperation(restRequest, jsonInput);
        final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
        return restResultBean;
    } catch (PwmException e) {
        LOGGER.error(restRequest.getSessionLabel(), "error executing rest-json random password request: " + e.getMessage(), e);
        return RestResultBean.fromError(restRequest, e.getErrorInformation());
    } catch (Exception e) {
        final String errorMessage = "unexpected error executing web service: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) RestResultBean(password.pwm.ws.server.RestResultBean) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Aggregations

RestResultBean (password.pwm.ws.server.RestResultBean)63 ErrorInformation (password.pwm.error.ErrorInformation)27 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmException (password.pwm.error.PwmException)16 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)15 Instant (java.time.Instant)14 PwmOperationalException (password.pwm.error.PwmOperationalException)14 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)11 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)10 IOException (java.io.IOException)10 PwmApplication (password.pwm.PwmApplication)10 PwmSession (password.pwm.http.PwmSession)10 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)9 ArrayList (java.util.ArrayList)8 ServletException (javax.servlet.ServletException)8 UserInfo (password.pwm.ldap.UserInfo)8 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)8 HelpdeskAuditRecord (password.pwm.svc.event.HelpdeskAuditRecord)8