Search in sources :

Example 11 with IAuthorizationManager

use of com.agiletec.aps.system.services.authorization.IAuthorizationManager in project entando-core by entando.

the class AbstractWidgetExecutorService method isUserAllowed.

protected boolean isUserAllowed(RequestContext reqCtx, Widget widget) {
    if (null == widget) {
        return false;
    }
    String widgetTypeGroup = widget.getType().getMainGroup();
    try {
        if (null == widgetTypeGroup || widgetTypeGroup.equals(Group.FREE_GROUP_NAME)) {
            return true;
        }
        IAuthorizationManager authorizationManager = (IAuthorizationManager) ApsWebApplicationUtils.getBean(SystemConstants.AUTHORIZATION_SERVICE, reqCtx.getRequest());
        UserDetails currentUser = (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        return authorizationManager.isAuthOnGroup(currentUser, widgetTypeGroup);
    } catch (Throwable t) {
        _logger.error("Error checking user authorities", t);
    }
    return false;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 12 with IAuthorizationManager

use of com.agiletec.aps.system.services.authorization.IAuthorizationManager in project entando-core by entando.

the class PreviewRequestAuthorizator method isAllowed.

private boolean isAllowed(UserDetails currentUser, IPage currentPage, HttpServletRequest request) {
    boolean isValid = false;
    IAuthorizationManager authManager = this.getAuthManager();
    if (authManager.isAuthOnPermission(currentUser, Permission.SUPERUSER)) {
        isValid = true;
    } else {
        String token = request.getParameter("token");
        if (StringUtils.isNotEmpty(token)) {
            String result = this.getPageTokenMager().decrypt(token);
            if (result != null && currentPage != null && result.equals(currentPage.getCode())) {
                isValid = true;
            }
        }
    }
    if (isValid) {
        isValid = authManager.isAuth(currentUser, currentPage);
    }
    return isValid;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager)

Example 13 with IAuthorizationManager

use of com.agiletec.aps.system.services.authorization.IAuthorizationManager in project entando-core by entando.

the class ContentWrapper method isUserAllowed.

public boolean isUserAllowed(String permissionName) {
    try {
        IAuthorizationManager authManager = (IAuthorizationManager) this.getBeanFactory().getBean(SystemConstants.AUTHORIZATION_SERVICE);
        UserDetails currentUser = (UserDetails) this.getReqCtx().getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        if (null == currentUser)
            return false;
        if (!authManager.isAuthOnGroup(currentUser, this.getEntity().getMainGroup()))
            return false;
        if (null != permissionName && permissionName.trim().length() > 0 && !authManager.isAuthOnPermission(currentUser, permissionName))
            return false;
    } catch (Throwable t) {
        _logger.error("Error checking authority - permission {}", permissionName, t);
        // ApsSystemUtils.logThrowable(t, this, "isUserAllowed", "Error checking authority - permission " + permissionName);
        return false;
    }
    return true;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Aggregations

IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)13 UserDetails (com.agiletec.aps.system.services.user.UserDetails)11 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Group (com.agiletec.aps.system.services.group.Group)2 HashSet (java.util.HashSet)2 HttpSession (javax.servlet.http.HttpSession)2 Lang (com.agiletec.aps.system.services.lang.Lang)1 Role (com.agiletec.aps.system.services.role.Role)1 IUserManager (com.agiletec.aps.system.services.user.IUserManager)1 PublicContentAuthorizationInfo (com.agiletec.plugins.jacms.aps.system.services.content.helper.PublicContentAuthorizationInfo)1 ResourceInstance (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 ICmsSearchEngineManager (com.agiletec.plugins.jacms.aps.system.services.searchengine.ICmsSearchEngineManager)1 ArrayList (java.util.ArrayList)1 JspException (javax.servlet.jsp.JspException)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 OAuthAccessResourceRequest (org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest)1 IApiOAuth2TokenManager (org.entando.entando.aps.system.services.oauth2.IApiOAuth2TokenManager)1 OAuth2Token (org.entando.entando.aps.system.services.oauth2.model.OAuth2Token)1