Search in sources :

Example 61 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class PeopleSearchDataReader method figurePhotoURL.

private String figurePhotoURL(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final boolean enabled = peopleSearchConfiguration.isPhotosEnabled(pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel());
    if (!enabled) {
        LOGGER.debug(pwmRequest, "detailed user data lookup for " + userIdentity.toString() + ", failed photo query filter, denying photo view");
        return null;
    }
    final String overrideURL = peopleSearchConfiguration.getPhotoUrlOverride(userIdentity);
    try {
        if (overrideURL != null && !overrideURL.isEmpty()) {
            final MacroMachine macroMachine = getMacroMachine(userIdentity);
            return macroMachine.expandMacros(overrideURL);
        }
        try {
            readPhotoDataFromLdap(userIdentity);
        } catch (PwmOperationalException e) {
            LOGGER.debug(pwmRequest, "determined " + userIdentity + " does not have photo data available while generating detail data");
            return null;
        }
    } catch (ChaiUnavailableException e) {
        throw PwmUnrecoverableException.fromChaiException(e);
    }
    String returnUrl = pwmRequest.getURLwithoutQueryString();
    returnUrl = PwmURL.appendAndEncodeUrlParameters(returnUrl, PwmConstants.PARAM_ACTION_REQUEST, PeopleSearchServlet.PeopleSearchActions.photo.name());
    returnUrl = PwmURL.appendAndEncodeUrlParameters(returnUrl, PwmConstants.PARAM_USERKEY, userIdentity.toObfuscatedKey(pwmApplication));
    return returnUrl;
}
Also used : PwmApplication(password.pwm.PwmApplication) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) MacroMachine(password.pwm.util.macro.MacroMachine) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 62 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class ErrorMessageTag method doEndTag.

public int doEndTag() throws javax.servlet.jsp.JspTagException {
    try {
        final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
        PwmApplication pwmApplication = null;
        try {
            pwmApplication = ContextManager.getPwmApplication(pageContext.getSession());
        } catch (PwmException e) {
        /* noop */
        }
        if (pwmRequest == null || pwmApplication == null) {
            return EVAL_PAGE;
        }
        final ErrorInformation error = (ErrorInformation) pwmRequest.getAttribute(PwmRequestAttribute.PwmErrorInfo);
        if (error != null) {
            final boolean allowHtml = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_ERRORS_ALLOW_HTML));
            final boolean showErrorDetail = pwmApplication.determineIfDetailErrorMsgShown();
            String outputMsg = error.toUserStr(pwmRequest.getPwmSession(), pwmApplication);
            if (!allowHtml) {
                outputMsg = StringUtil.escapeHtml(outputMsg);
            }
            if (showErrorDetail) {
                final String errorDetail = error.toDebugStr() == null ? "" : " { " + error.toDebugStr() + " }";
                // detail should always be escaped - it may contain untrusted data
                outputMsg += "<span class='errorDetail'>" + StringUtil.escapeHtml(errorDetail) + "</span>";
            }
            outputMsg = outputMsg.replace("\n", "<br/>");
            final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmApplication);
            outputMsg = macroMachine.expandMacros(outputMsg);
            pageContext.getOut().write(outputMsg);
        }
    } catch (PwmUnrecoverableException e) {
    /* app not running */
    } catch (Exception e) {
        LOGGER.error("error executing error message tag: " + e.getMessage(), e);
        throw new JspTagException(e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) PwmRequest(password.pwm.http.PwmRequest) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmException(password.pwm.error.PwmException)

Example 63 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class PasswordRequirementsTag method doEndTag.

public int doEndTag() throws javax.servlet.jsp.JspTagException {
    try {
        final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
        final PwmSession pwmSession = pwmRequest.getPwmSession();
        final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
        final Configuration config = pwmApplication.getConfig();
        final Locale locale = pwmSession.getSessionStateBean().getLocale();
        pwmSession.getSessionManager().getMacroMachine(pwmApplication);
        final PwmPasswordPolicy passwordPolicy;
        if (getForm() != null && getForm().equalsIgnoreCase("newuser")) {
            final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
            passwordPolicy = newUserProfile.getNewUserPasswordPolicy(pwmApplication, locale);
        } else {
            passwordPolicy = pwmSession.getUserInfo().getPasswordPolicy();
        }
        final String configuredRuleText = passwordPolicy.getRuleText();
        if (configuredRuleText != null && configuredRuleText.length() > 0) {
            pageContext.getOut().write(configuredRuleText);
        } else {
            final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
            final String pre = prepend != null && prepend.length() > 0 ? prepend : "";
            final String sep = separator != null && separator.length() > 0 ? separator : "<br/>";
            final List<String> requirementsList = getPasswordRequirementsStrings(passwordPolicy, config, locale, macroMachine);
            final StringBuilder requirementsText = new StringBuilder();
            for (final String requirementStatement : requirementsList) {
                requirementsText.append(pre);
                requirementsText.append(requirementStatement);
                requirementsText.append(sep);
            }
            pageContext.getOut().write(requirementsText.toString());
        }
    } catch (IOException | PwmException e) {
        LOGGER.error("unexpected error during password requirements generation: " + e.getMessage(), e);
        throw new JspTagException(e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) PwmRequest(password.pwm.http.PwmRequest) Configuration(password.pwm.config.Configuration) IOException(java.io.IOException) NewUserProfile(password.pwm.config.profile.NewUserProfile) PwmException(password.pwm.error.PwmException) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) MacroMachine(password.pwm.util.macro.MacroMachine) PwmSession(password.pwm.http.PwmSession) JspTagException(javax.servlet.jsp.JspTagException)

Example 64 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class PwmFormIDTag method buildPwmFormID.

private static String buildPwmFormID(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    if (pwmRequest == null || pwmRequest.getPwmApplication() == null) {
        return "";
    }
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    if (pwmApplication == null) {
        return "";
    }
    final SessionStateService sessionStateService = pwmApplication.getSessionStateService();
    final String value = sessionStateService.getSessionStateInfo(pwmRequest);
    final FormNonce formID = new FormNonce(pwmRequest.getPwmSession().getLoginInfoBean().getGuid(), Instant.now(), pwmRequest.getPwmSession().getLoginInfoBean().getReqCounter(), value);
    return pwmRequest.getPwmApplication().getSecureService().encryptObjectToString(formID);
}
Also used : PwmApplication(password.pwm.PwmApplication) SessionStateService(password.pwm.http.state.SessionStateService) FormNonce(password.pwm.bean.FormNonce)

Example 65 with PwmApplication

use of password.pwm.PwmApplication in project pwm by pwm-project.

the class PwmUrlTag method figureThemeURL.

private static String figureThemeURL(final PwmRequest pwmRequest, final PwmThemeURL themeUrl) {
    String themeURL = null;
    String themeName = AppProperty.CONFIG_THEME.getDefaultValue();
    if (pwmRequest != null) {
        final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
        themeName = figureThemeName(pwmRequest);
        if ("custom".equals(themeName)) {
            if (themeUrl == PwmThemeURL.MOBILE_THEME_URL) {
                themeURL = pwmApplication.getConfig().readSettingAsString(PwmSetting.DISPLAY_CSS_CUSTOM_MOBILE_STYLE);
            } else {
                themeURL = pwmApplication.getConfig().readSettingAsString(PwmSetting.DISPLAY_CSS_CUSTOM_STYLE);
            }
        }
    }
    if (themeURL == null || themeURL.length() < 1) {
        themeURL = ResourceFileServlet.RESOURCE_PATH + themeUrl.getCssName();
        themeURL = themeURL.replace(ResourceFileServlet.TOKEN_THEME, StringUtil.escapeHtml(themeName));
    }
    return themeURL;
}
Also used : PwmApplication(password.pwm.PwmApplication)

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