Search in sources :

Example 1 with ShortcutItem

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);
}
Also used : PwmApplication(password.pwm.PwmApplication) ShortcutItem(password.pwm.config.value.data.ShortcutItem) PwmSession(password.pwm.http.PwmSession)

Example 2 with ShortcutItem

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;
}
Also used : ArrayList(java.util.ArrayList) ShortcutItem(password.pwm.config.value.data.ShortcutItem) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with ShortcutItem

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);
}
Also used : PwmApplication(password.pwm.PwmApplication) ShortcutsBean(password.pwm.http.bean.ShortcutsBean) ShortcutItem(password.pwm.config.value.data.ShortcutItem) PwmSession(password.pwm.http.PwmSession)

Aggregations

ShortcutItem (password.pwm.config.value.data.ShortcutItem)3 PwmApplication (password.pwm.PwmApplication)2 PwmSession (password.pwm.http.PwmSession)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 ShortcutsBean (password.pwm.http.bean.ShortcutsBean)1