Search in sources :

Example 26 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ActivityStreamTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    try {
        IActionLogManager loggerManager = (IActionLogManager) ApsWebApplicationUtils.getBean(SystemConstants.ACTION_LOGGER_MANAGER, this.pageContext);
        UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        List<Integer> ids = loggerManager.getActivityStream(currentUser);
        if (null != this.getVar()) {
            ValueStack stack = this.getStack();
            stack.getContext().put(this.getVar(), ids);
            stack.setValue("#attr['" + this.getVar() + "']", ids, false);
        }
    } catch (Throwable t) {
        _logger.error("Error on doStartTag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error on doStartTag", t);
    }
    return super.doEndTag();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ValueStack(com.opensymphony.xwork2.util.ValueStack) IActionLogManager(org.entando.entando.aps.system.services.actionlog.IActionLogManager)

Example 27 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class GroupsByPermissionTag method getAllowedGroups.

protected Set<String> getAllowedGroups() {
    Set<String> groupCodes = new HashSet<String>();
    UserDetails currentUser = (UserDetails) this.pageContext.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    String permissionName = this.getPermission();
    if (null != currentUser && null != permissionName) {
        IAuthorizationManager authManager = (IAuthorizationManager) ApsWebApplicationUtils.getBean(SystemConstants.AUTHORIZATION_SERVICE, this.pageContext);
        List<Group> groupsByPermission = authManager.getGroupsByPermission(currentUser, permissionName);
        if (null != groupsByPermission) {
            for (Group group : groupsByPermission) {
                if (null != group) {
                    groupCodes.add(group.getName());
                }
            }
        }
    }
    return groupCodes;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashSet(java.util.HashSet)

Example 28 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails 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 29 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class UserAction method validate.

@Override
public void validate() {
    super.validate();
    if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        this.checkAddUserUser();
    } else {
        try {
            if (this.hasActionErrors() || this.hasErrors() || this.hasFieldErrors()) {
                String username = this.getUsername();
                UserDetails user = this.getUserManager().getUser(username);
                this.setUser(user);
            }
        } catch (Throwable t) {
            _logger.error("Error validating user", t);
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 30 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApsAdminBaseTestCase method setUserOnSession.

protected void setUserOnSession(String username) throws Exception {
    if (null == username) {
        this.removeUserOnSession();
        return;
    }
    // nel database di test, username e password sono uguali
    UserDetails currentUser = this.getUser(username, username);
    HttpSession session = this._request.getSession();
    session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, currentUser);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7