use of password.pwm.config.value.data.ShortcutItem in project pwm by pwm-project.
the class ShortcutServlet method handleUserSelection.
private void handleUserSelection(final PwmRequest pwmRequest, final ShortcutsBean shortcutsBean) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final String link = pwmRequest.readParameterAsString("link");
final Map<String, ShortcutItem> visibleItems = shortcutsBean.getVisibleItems();
if (link != null && visibleItems.keySet().contains(link)) {
final ShortcutItem item = visibleItems.get(link);
pwmApplication.getStatisticsManager().incrementValue(Statistic.SHORTCUTS_SELECTED);
LOGGER.trace(pwmSession, "shortcut link selected: " + link + ", setting link for 'forwardURL' to " + item.getShortcutURI());
pwmSession.getSessionStateBean().setForwardURL(item.getShortcutURI().toString());
pwmRequest.sendRedirectToContinue();
return;
}
LOGGER.error(pwmSession, "unknown/unexpected link requested to " + link);
pwmRequest.forwardToJsp(JspUrl.SHORTCUT);
}
use of password.pwm.config.value.data.ShortcutItem in project pwm by pwm-project.
the class ShortcutServlet method figureVisibleShortcuts.
/**
* Loop through each configured shortcut setting to determine if the shortcut is is able to the user pwmSession.
*/
private static Map<String, ShortcutItem> figureVisibleShortcuts(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException {
final Collection<String> configValues = pwmRequest.getConfig().readSettingAsLocalizedStringArray(PwmSetting.SHORTCUT_ITEMS, pwmRequest.getLocale());
final Set<String> labelsFromHeader = new HashSet<>();
{
final Map<String, List<String>> headerValueMap = pwmRequest.readHeaderValuesMap();
final List<String> interestedHeaderNames = pwmRequest.getConfig().readSettingAsStringArray(PwmSetting.SHORTCUT_HEADER_NAMES);
for (final Map.Entry<String, List<String>> entry : headerValueMap.entrySet()) {
final String headerName = entry.getKey();
if (interestedHeaderNames.contains(headerName)) {
for (final String loopValues : entry.getValue()) {
labelsFromHeader.addAll(StringHelper.tokenizeString(loopValues, ","));
}
}
}
}
final List<ShortcutItem> configuredItems = new ArrayList<>();
for (final String loopStr : configValues) {
final ShortcutItem item = ShortcutItem.parsePwmConfigInput(loopStr);
configuredItems.add(item);
}
final Map<String, ShortcutItem> visibleItems = new LinkedHashMap<>();
if (!labelsFromHeader.isEmpty()) {
LOGGER.trace("detected the following labels from headers: " + StringHelper.stringCollectionToString(labelsFromHeader, ","));
visibleItems.keySet().retainAll(labelsFromHeader);
} else {
for (final ShortcutItem item : configuredItems) {
final boolean queryMatch = LdapPermissionTester.testQueryMatch(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getPwmSession().getUserInfo().getUserIdentity(), item.getLdapQuery());
if (queryMatch) {
visibleItems.put(item.getLabel(), item);
}
}
}
return visibleItems;
}
use of password.pwm.config.value.data.ShortcutItem in project pwm by pwm-project.
the class ShortcutServlet method processAction.
protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.SHORTCUT_ENABLE)) {
pwmRequest.respondWithError(PwmError.ERROR_SERVICE_NOT_AVAILABLE.toInfo());
return;
}
final ShortcutsBean shortcutsBean = pwmApplication.getSessionStateService().getBean(pwmRequest, ShortcutsBean.class);
if (shortcutsBean.getVisibleItems() == null) {
LOGGER.debug(pwmSession, "building visible shortcut list for user");
final Map<String, ShortcutItem> visibleItems = figureVisibleShortcuts(pwmRequest);
shortcutsBean.setVisibleItems(visibleItems);
} else {
LOGGER.trace(pwmSession, "using cashed shortcut values");
}
final ShortcutAction action = readProcessAction(pwmRequest);
if (action != null) {
pwmRequest.validatePwmFormID();
switch(action) {
case selectShortcut:
handleUserSelection(pwmRequest, shortcutsBean);
return;
default:
JavaHelper.unhandledSwitchStatement(action);
}
}
forwardToJsp(pwmRequest, shortcutsBean);
}
Aggregations