Search in sources :

Example 1 with Shortcut

use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.

the class ShortcutLoader method completeLoading.

private void completeLoading() {
    Iterator<Shortcut> shorCutIter = this.getShortcuts().values().iterator();
    while (shorCutIter.hasNext()) {
        Shortcut shortcut = shorCutIter.next();
        String menuSectionCode = shortcut.getMenuSectionCode();
        MenuSection section = this.getManuSections().get(menuSectionCode);
        shortcut.setMenuSection(section);
    }
}
Also used : Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut) MenuSection(org.entando.entando.apsadmin.system.services.shortcut.model.MenuSection)

Example 2 with Shortcut

use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.

the class ShortcutManager method checkShortcutConfig.

private String[] checkShortcutConfig(UserDetails user, String[] config) throws Throwable {
    if (null == config) {
        config = new String[this.getUserShortcutsMaxNumber()];
    }
    try {
        if (config.length != this.getUserShortcutsMaxNumber()) {
            String[] newConfig = new String[this.getUserShortcutsMaxNumber()];
            for (int i = 0; i < config.length; i++) {
                if (i >= newConfig.length)
                    continue;
                newConfig[i] = config[i];
            }
            config = newConfig;
        }
        for (int i = 0; i < config.length; i++) {
            String code = config[i];
            Shortcut shortcut = this.getShortcuts().get(code);
            String reqPerm = (null == shortcut) ? null : shortcut.getRequiredPermission();
            if (null == shortcut || (null != reqPerm && !this.getAuthorizationManager().isAuthOnPermission(user, reqPerm))) {
                config[i] = null;
            }
        }
    } catch (Throwable t) {
        _logger.error("Error checking Shortcut Config by user {}", user.getUsername(), t);
        // ApsSystemUtils.logThrowable(t, this, "checkShortcutConfig");
        throw new ApsSystemException("Error checking Shortcut Config by user " + user.getUsername(), t);
    }
    return config;
}
Also used : Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 3 with Shortcut

use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.

the class ShortcutManager method getAllowedShortcuts.

@Override
public List<Shortcut> getAllowedShortcuts(UserDetails user) throws ApsSystemException {
    List<Shortcut> allowedShortcuts = new ArrayList<Shortcut>();
    if (null == user) {
        _logger.info("Required allowed shortcut for null user");
        return allowedShortcuts;
    }
    try {
        Iterator<Shortcut> shorCutIter = this.getShortcuts().values().iterator();
        while (shorCutIter.hasNext()) {
            Shortcut shortcut = shorCutIter.next();
            String permissionName = shortcut.getRequiredPermission();
            if (null == permissionName || this.getAuthorizationManager().isAuthOnPermission(user, permissionName)) {
                allowedShortcuts.add(shortcut.clone());
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting allowed shortcuts by user {}", user.getUsername(), t);
        // ApsSystemUtils.logThrowable(t, this, "getAllowedShortcuts");
        throw new ApsSystemException("Error extracting allowed shortcuts by user " + user.getUsername(), t);
    }
    BeanComparator comparator = new BeanComparator("source");
    Collections.sort(allowedShortcuts, comparator);
    return allowedShortcuts;
}
Also used : Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 4 with Shortcut

use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.

the class ShortcutListTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    UserDetails currentUser = (UserDetails) this.pageContext.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    try {
        Object retval = null;
        IShortcutManager shortcutManager = (IShortcutManager) ApsWebApplicationUtils.getBean(ApsAdminSystemConstants.SHORTCUT_MANAGER, this.pageContext);
        List<Shortcut> myShortcuts = shortcutManager.getAllowedShortcuts(currentUser);
        if (this.getType().equalsIgnoreCase(TYPE_LIST_OBJECT)) {
            retval = (Object) myShortcuts;
        } else if (this.getType().equalsIgnoreCase(TYPE_LIST_ITEMS)) {
            retval = (Object) this.getAllowedShortcutSelectItems(myShortcuts, currentUser);
        } else {
            _logger.warn("Invalid param for attribute 'value'. Expected '{}' or '{}' but was {}", TYPE_LIST_ITEMS, TYPE_LIST_OBJECT, this.getType());
        }
        ValueStack stack = super.getStack();
        stack.getContext().put(this.getVar(), retval);
        stack.setValue("#attr['" + this.getVar() + "']", retval, false);
    } catch (Throwable t) {
        _logger.error("Error extracting shortcuts for user '{}'", currentUser.getUsername(), t);
        throw new JspException("Error extracting shortcuts", t);
    }
    return super.doStartTag();
}
Also used : JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ValueStack(com.opensymphony.xwork2.util.ValueStack) Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut) IShortcutManager(org.entando.entando.apsadmin.system.services.shortcut.IShortcutManager)

Example 5 with Shortcut

use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.

the class TestShortcutManager method testGetAllowedShortcuts.

public void testGetAllowedShortcuts() throws Throwable {
    assertNotNull(this._shortcutManager);
    String expectedShortcut = "core.tools.setting";
    UserDetails adminUser = super.getUser("admin");
    List<Shortcut> shortcuts = this._shortcutManager.getAllowedShortcuts(adminUser);
    assertTrue(this.containsShortcut(shortcuts, expectedShortcut));
    UserDetails editorCoach = super.getUser("editorCoach");
    shortcuts = this._shortcutManager.getAllowedShortcuts(editorCoach);
    assertFalse(this.containsShortcut(shortcuts, expectedShortcut));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut)

Aggregations

Shortcut (org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BeanComparator (org.apache.commons.beanutils.BeanComparator)2 SelectItem (com.agiletec.aps.util.SelectItem)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 List (java.util.List)1 JspException (javax.servlet.jsp.JspException)1 IShortcutManager (org.entando.entando.apsadmin.system.services.shortcut.IShortcutManager)1 MenuSection (org.entando.entando.apsadmin.system.services.shortcut.model.MenuSection)1 Element (org.jdom.Element)1