Search in sources :

Example 31 with MacroMachine

use of password.pwm.util.macro.MacroMachine 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 32 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class PeopleSearchDataReader method makeUserDetailLinks.

private List<LinkReferenceBean> makeUserDetailLinks(final UserIdentity actorIdentity) throws PwmUnrecoverableException {
    final String userLinksStr = pwmRequest.getConfig().readAppProperty(AppProperty.PEOPLESEARCH_VIEW_DETAIL_LINKS);
    if (StringUtil.isEmpty(userLinksStr)) {
        return Collections.emptyList();
    }
    final Map<String, String> linkMap;
    try {
        linkMap = JsonUtil.deserializeStringMap(userLinksStr);
    } catch (Exception e) {
        LOGGER.warn(pwmRequest, "error de-serializing configured app property json for detail links: " + e.getMessage());
        return Collections.emptyList();
    }
    final List<LinkReferenceBean> returnList = new ArrayList<>();
    final MacroMachine macroMachine = getMacroMachine(actorIdentity);
    for (final Map.Entry<String, String> entry : linkMap.entrySet()) {
        final String key = entry.getKey();
        final String value = entry.getValue();
        final String parsedValue = macroMachine.expandMacros(value);
        final LinkReferenceBean linkReference = new LinkReferenceBean();
        linkReference.setName(key);
        linkReference.setLink(parsedValue);
        returnList.add(linkReference);
    }
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) MacroMachine(password.pwm.util.macro.MacroMachine) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Example 33 with MacroMachine

use of password.pwm.util.macro.MacroMachine 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 34 with MacroMachine

use of password.pwm.util.macro.MacroMachine 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 35 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class SuccessMessageTag method doEndTag.

public int doEndTag() throws javax.servlet.jsp.JspTagException {
    try {
        final HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
        final PwmRequest pwmRequest = PwmRequest.forRequest(req, (HttpServletResponse) pageContext.getResponse());
        final String successMsg = (String) pwmRequest.getAttribute(PwmRequestAttribute.SuccessMessage);
        final String outputMsg;
        if (successMsg == null || successMsg.isEmpty()) {
            outputMsg = Message.getLocalizedMessage(pwmRequest.getLocale(), Message.Success_Unknown, pwmRequest.getConfig());
        } else {
            if (pwmRequest.isAuthenticated()) {
                final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
                outputMsg = macroMachine.expandMacros(successMsg);
            } else {
                outputMsg = successMsg;
            }
        }
        pageContext.getOut().write(outputMsg);
    } catch (Exception e) {
        throw new JspTagException(e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmRequest(password.pwm.http.PwmRequest) MacroMachine(password.pwm.util.macro.MacroMachine) JspTagException(javax.servlet.jsp.JspTagException) JspTagException(javax.servlet.jsp.JspTagException)

Aggregations

MacroMachine (password.pwm.util.macro.MacroMachine)61 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)20 Locale (java.util.Locale)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Configuration (password.pwm.config.Configuration)13 UserInfo (password.pwm.ldap.UserInfo)13 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 PwmApplication (password.pwm.PwmApplication)12 FormConfiguration (password.pwm.config.value.data.FormConfiguration)12 ChaiUser (com.novell.ldapchai.ChaiUser)10 PwmException (password.pwm.error.PwmException)10 List (java.util.List)9 EmailItemBean (password.pwm.bean.EmailItemBean)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 Map (java.util.Map)8 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)8 PwmSession (password.pwm.http.PwmSession)8 Instant (java.time.Instant)7