Search in sources :

Example 16 with Group

use of com.agiletec.aps.system.services.group.Group 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 17 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class UserAuthorizationAction method addAuthorization.

public String addAuthorization() {
    try {
        if (!this.checkAuthorizationSessionBean()) {
            return "userList";
        }
        String groupName = this.getGroupName();
        String roleName = this.getRoleName();
        Group group = this.getGroupManager().getGroup(groupName);
        Role role = this.getRoleManager().getRole(roleName);
        if (!StringUtils.isEmpty(groupName) && null == group) {
            this.addFieldError("groupName", this.getText("error.userAuthorization.invalidGroup", new String[] { groupName }));
        }
        if (!StringUtils.isEmpty(roleName) && null == role) {
            this.addFieldError("roleName", this.getText("error.userAuthorization.invalidRole", new String[] { groupName }));
        }
        if (null == group && null == role) {
            this.addFieldError("groupName", this.getText("error.userAuthorization.invalidGroupAndRole"));
            this.addFieldError("roleName", this.getText("error.userAuthorization.invalidGroupAndRole"));
        }
        if (this.hasFieldErrors()) {
            return INPUT;
        }
        Authorization authorization = new Authorization(group, role);
        boolean result = this.getUserAuthsFormBean().addAuthorization(authorization);
        if (!result) {
            this.addActionError(this.getText("error.userAuthorization.alreadyExists", new String[] { groupName, roleName }));
            return INPUT;
        }
    } catch (Throwable t) {
        _logger.error("error adding user authorization", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Authorization(com.agiletec.aps.system.services.authorization.Authorization) Group(com.agiletec.aps.system.services.group.Group)

Example 18 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class ContentGroupBulkAction method join.

public String join() {
    try {
        String groupName = this.getGroupName();
        Group group = this.getGroupManager().getGroup(groupName);
        if (null != group) {
            this.getExtraGroupNames().add(groupName);
        }
    } catch (Throwable t) {
        _logger.error("Error joining group for bulk action", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 19 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class BaseContentDispenser method getRenderizationInfo.

protected ContentRenderizationInfo getRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, RequestContext reqCtx, boolean cacheable) {
    ContentRenderizationInfo renderInfo = null;
    try {
        UserDetails currentUser = (null != reqCtx) ? (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) : null;
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            renderInfo = this.getBaseRenderizationInfo(authInfo, contentId, modelId, langCode, currentUser, reqCtx, cacheable);
            if (null == renderInfo) {
                return null;
            }
        } else {
            String renderedContent = "Current user '" + currentUser.getUsername() + "' can't view this content";
            Content contentToRender = this.getContentManager().loadContent(contentId, true, cacheable);
            renderInfo = new ContentRenderizationInfo(contentToRender, renderedContent, modelId, langCode, null);
            renderInfo.setRenderedContent(renderedContent);
            return renderInfo;
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 20 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class BaseContentDispenser method getBaseRenderizationInfo.

public ContentRenderizationInfo getBaseRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, UserDetails currentUser, RequestContext reqCtx, boolean cacheable) {
    ContentRenderizationInfo renderInfo = null;
    try {
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            Content contentToRender = this.getContentManager().loadContent(contentId, true, cacheable);
            String renderedContent = this.buildRenderedContent(contentToRender, modelId, langCode, reqCtx);
            if (null != renderedContent && renderedContent.trim().length() > 0) {
                List<AttributeRole> roles = this.getContentManager().getAttributeRoles();
                renderInfo = new ContentRenderizationInfo(contentToRender, renderedContent, modelId, langCode, roles);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeRole(com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)

Aggregations

Group (com.agiletec.aps.system.services.group.Group)68 UserDetails (com.agiletec.aps.system.services.user.UserDetails)15 Role (com.agiletec.aps.system.services.role.Role)13 ArrayList (java.util.ArrayList)13 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 BeanComparator (org.apache.commons.beanutils.BeanComparator)5 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 HashSet (java.util.HashSet)4 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)4 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 AttributeRole (com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)2 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)2 Authorization (com.agiletec.aps.system.services.authorization.Authorization)2 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)2 ExtendedResourceAction (com.agiletec.plugins.jacms.apsadmin.content.attribute.action.resource.ExtendedResourceAction)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2