Search in sources :

Example 1 with PhotoDataBean

use of password.pwm.ldap.PhotoDataBean in project pwm by pwm-project.

the class HelpdeskServlet method processUserPhotoImageRequest.

@ActionHandler(action = "photo")
private ProcessStatus processUserPhotoImageRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final UserIdentity userIdentity = readUserKeyRequestParameter(pwmRequest);
    final HelpdeskProfile helpdeskProfile = getHelpdeskProfile(pwmRequest);
    HelpdeskServletUtil.checkIfUserIdentityViewable(pwmRequest, helpdeskProfile, userIdentity);
    final ChaiUser chaiUser = getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
    LOGGER.debug(pwmRequest, "received user photo request to view user " + userIdentity.toString());
    final PhotoDataBean photoData;
    try {
        photoData = LdapOperationsHelper.readPhotoDataFromLdap(pwmRequest.getConfig(), chaiUser, userIdentity);
    } catch (PwmOperationalException e) {
        final ErrorInformation errorInformation = e.getErrorInformation();
        LOGGER.error(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation, false);
        return ProcessStatus.Halt;
    }
    try (OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream()) {
        final HttpServletResponse resp = pwmRequest.getPwmResponse().getHttpServletResponse();
        resp.setContentType(photoData.getMimeType());
        outputStream.write(photoData.getContents());
    }
    return ProcessStatus.Halt;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PhotoDataBean(password.pwm.ldap.PhotoDataBean) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) OutputStream(java.io.OutputStream) HelpdeskProfile(password.pwm.config.profile.HelpdeskProfile) HttpServletResponse(javax.servlet.http.HttpServletResponse) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 2 with PhotoDataBean

use of password.pwm.ldap.PhotoDataBean in project pwm by pwm-project.

the class PeopleSearchServlet method processUserPhotoImageRequest.

@ActionHandler(action = "photo")
private ProcessStatus processUserPhotoImageRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final String userKey = pwmRequest.readParameterAsString(PARAM_USERKEY, PwmHttpRequestWrapper.Flag.BypassValidation);
    if (userKey.length() < 1) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, PARAM_USERKEY + " parameter is missing");
        LOGGER.error(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation, false);
        return ProcessStatus.Halt;
    }
    final PeopleSearchDataReader peopleSearchDataReader = new PeopleSearchDataReader(pwmRequest);
    final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
    try {
        peopleSearchDataReader.checkIfUserIdentityViewable(userIdentity);
    } catch (PwmOperationalException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "error during photo request while checking if requested userIdentity is within search scope: " + e.getMessage());
        LOGGER.error(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation, false);
        return ProcessStatus.Halt;
    }
    LOGGER.debug(pwmRequest, "received user photo request to view user " + userIdentity.toString());
    final PhotoDataBean photoData;
    try {
        photoData = peopleSearchDataReader.readPhotoDataFromLdap(userIdentity);
    } catch (PwmOperationalException e) {
        final ErrorInformation errorInformation = e.getErrorInformation();
        LOGGER.error(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation, false);
        return ProcessStatus.Halt;
    }
    addExpiresHeadersToResponse(pwmRequest);
    try (OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream()) {
        final HttpServletResponse resp = pwmRequest.getPwmResponse().getHttpServletResponse();
        resp.setContentType(photoData.getMimeType());
        outputStream.write(photoData.getContents());
    }
    return ProcessStatus.Halt;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PhotoDataBean(password.pwm.ldap.PhotoDataBean) UserIdentity(password.pwm.bean.UserIdentity) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

OutputStream (java.io.OutputStream)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 UserIdentity (password.pwm.bean.UserIdentity)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PhotoDataBean (password.pwm.ldap.PhotoDataBean)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)1