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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations