Search in sources :

Example 41 with UserDetails

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

Example 42 with UserDetails

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

the class NavigatorParser method parseSpec.

/**
 * Crea e restituisce una lista di oggetti NavigatorTarget, che wrappano
 * pagine del portale e possono essere utilizzati dai sub-tag.
 *
 * @param spec L'espressione usata la specificazione delle pagine da
 * selezionare; possono essere assolute o relative o miste.
 * @param reqCtx Il contesto della richiesta corrente.
 * @return La lista di oggetti NavigatorTarget.
 */
@Override
public List<NavigatorTarget> parseSpec(String spec, RequestContext reqCtx) {
    IPage currentPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
    UserDetails currentUser = (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    return this.parseSpec(spec, currentPage, currentUser);
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 43 with UserDetails

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

the class CheckPermissionTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    HttpSession session = this.pageContext.getSession();
    try {
        boolean isAuthorized = false;
        UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        IAuthorizationManager authManager = (IAuthorizationManager) ApsWebApplicationUtils.getBean(SystemConstants.AUTHORIZATION_SERVICE, this.pageContext);
        boolean isGroupSetted = StringUtils.isNotEmpty(this.getGroupName());
        boolean isPermissionSetted = StringUtils.isNotEmpty(this.getPermission());
        boolean isAuthGr = isGroupSetted && (authManager.isAuthOnGroup(currentUser, this.getGroupName()) || authManager.isAuthOnGroup(currentUser, Group.ADMINS_GROUP_NAME));
        boolean isAuthPerm = isPermissionSetted && (authManager.isAuthOnPermission(currentUser, this.getPermission()) || authManager.isAuthOnPermission(currentUser, Permission.SUPERUSER));
        if (isGroupSetted && !isPermissionSetted) {
            isAuthorized = isAuthGr;
        } else if (!isGroupSetted && isPermissionSetted) {
            isAuthorized = isAuthPerm;
        } else if (isGroupSetted && isPermissionSetted && isAuthGr && isAuthPerm) {
            isAuthorized = authManager.isAuthOnGroupAndPermission(currentUser, this.getGroupName(), this.getPermission(), true);
        }
        if (null != this.getVar()) {
            this.pageContext.setAttribute(this.getVar(), isAuthorized);
        }
        if (isAuthorized) {
            return EVAL_BODY_INCLUDE;
        } else {
            return SKIP_BODY;
        }
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        throw new JspException("Error during tag initialization ", t);
    }
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession)

Example 44 with UserDetails

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

the class ContentInfoTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    int result = super.doStartTag();
    try {
        if (null != this.getMasterObject()) {
            HttpSession session = this.pageContext.getSession();
            UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
            IContentAuthorizationHelper contentAuthHelper = (IContentAuthorizationHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_AUTHORIZATION_HELPER, this.pageContext);
            boolean isAuthOnEdit = false;
            if (this.isRecord()) {
                // PENSARE ALL'OPPORTUNITA'... meno prestante nel caso di oggetto contenuto!
                String keyValue = (String) super.findValue(this.getKey(), String.class);
                isAuthOnEdit = contentAuthHelper.isAuthToEdit(currentUser, keyValue, false);
            } else {
                isAuthOnEdit = contentAuthHelper.isAuthToEdit(currentUser, (Content) this.getMasterObject());
            }
            if (isAuthOnEdit) {
                if (null != this.getAuthToEditVar()) {
                    ValueStack stack = this.getStack();
                    stack.getContext().put(this.getAuthToEditVar(), isAuthOnEdit);
                    stack.setValue("#attr['" + this.getAuthToEditVar() + "']", isAuthOnEdit, false);
                }
                result = EVAL_BODY_INCLUDE;
            }
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag", "Error on doStartTag");
        throw new JspException("Error on doStartTag", t);
    }
    return result;
}
Also used : JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ValueStack(com.opensymphony.xwork2.util.ValueStack) HttpSession(javax.servlet.http.HttpSession) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) IContentAuthorizationHelper(com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper)

Example 45 with UserDetails

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

the class ContentTypeInfoTag method getPropertyValue.

@Override
protected Object getPropertyValue(Object masterObject, String propertyValue) {
    if (null == propertyValue || !propertyValue.equals("isAuthToEdit")) {
        return super.getPropertyValue(masterObject, propertyValue);
    }
    try {
        HttpSession session = this.pageContext.getSession();
        UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        Content prototype = (Content) masterObject;
        IContentAuthorizationHelper helper = (IContentAuthorizationHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_AUTHORIZATION_HELPER, this.pageContext);
        return helper.isAuthToEdit(currentUser, prototype);
    } catch (Throwable t) {
        _logger.error("Error extracting property value : Master Object '{}' - property '{}'", masterObject.getClass().getName(), propertyValue, t);
    }
    return null;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) IContentAuthorizationHelper(com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper)

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