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