Search in sources :

Example 1 with IContentAuthorizationHelper

use of com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper 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 2 with IContentAuthorizationHelper

use of com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper 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)

Example 3 with IContentAuthorizationHelper

use of com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper in project entando-core by entando.

the class ContentInfoTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        IContentViewerHelper helper = (IContentViewerHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_VIEWER_HELPER, this.pageContext);
        PublicContentAuthorizationInfo authInfo = helper.getAuthorizationInfo(this.getContentId(), reqCtx);
        if (null == authInfo) {
            return super.doStartTag();
        }
        if (null == this.getParam() && null != this.getVar()) {
            this.pageContext.setAttribute(this.getVar(), authInfo);
        } else if (null != this.getParam()) {
            Object value = null;
            if ("contentId".equals(this.getParam())) {
                value = authInfo.getContentId();
            } else if ("modelId".equals(this.getParam())) {
                value = this.extractModelId(authInfo, reqCtx);
            } else if ("mainGroup".equals(this.getParam())) {
                value = authInfo.getMainGroup();
            } else if ("authToEdit".equals(this.getParam())) {
                IContentAuthorizationHelper contentAuthHelper = (IContentAuthorizationHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_AUTHORIZATION_HELPER, this.pageContext);
                HttpSession session = this.pageContext.getSession();
                UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
                boolean isAuth = contentAuthHelper.isAuthToEdit(currentUser, authInfo);
                value = Boolean.valueOf(isAuth);
            }
            if (null != value) {
                String var = this.getVar();
                if (null == var || "".equals(var)) {
                    this.pageContext.getOut().print(value);
                } else {
                    this.pageContext.setAttribute(this.getVar(), value);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error detected while initializing the tag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error detected while initializing the tag", t);
    }
    return super.doStartTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) IContentViewerHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper) JspException(javax.servlet.jsp.JspException) PublicContentAuthorizationInfo(com.agiletec.plugins.jacms.aps.system.services.content.helper.PublicContentAuthorizationInfo) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession) RequestContext(com.agiletec.aps.system.RequestContext) IContentAuthorizationHelper(com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 IContentAuthorizationHelper (com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper)3 HttpSession (javax.servlet.http.HttpSession)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)2 JspException (javax.servlet.jsp.JspException)2 RequestContext (com.agiletec.aps.system.RequestContext)1 PublicContentAuthorizationInfo (com.agiletec.plugins.jacms.aps.system.services.content.helper.PublicContentAuthorizationInfo)1 IContentViewerHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 ServletRequest (javax.servlet.ServletRequest)1