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