Search in sources :

Example 36 with Role

use of com.agiletec.aps.system.services.role.Role in project entando-core by entando.

the class UserControllerUnitTest method mockedRole.

private Role mockedRole() {
    Role role = new Role();
    role.setDescription("descr1");
    role.setName("role1");
    return role;
}
Also used : Role(com.agiletec.aps.system.services.role.Role)

Example 37 with Role

use of com.agiletec.aps.system.services.role.Role in project entando-core by entando.

the class AuthorizationManager method isAuthOnSinglePermission.

private boolean isAuthOnSinglePermission(UserDetails user, String permissionName) {
    if (null == user) {
        return false;
    }
    List<Role> rolesWithPermission = this.getRolesWithPermission(user, permissionName);
    for (int i = 0; i < rolesWithPermission.size(); i++) {
        Role role = rolesWithPermission.get(i);
        boolean check = this.checkAuth(user, role.getAuthority(), true);
        if (check) {
            return true;
        }
    }
    return false;
}
Also used : Role(com.agiletec.aps.system.services.role.Role)

Example 38 with Role

use of com.agiletec.aps.system.services.role.Role in project entando-core by entando.

the class AuthorizationManager method isAuthOnGroupAndPermission.

@Override
public boolean isAuthOnGroupAndPermission(UserDetails user, String groupName, String permissionName, boolean chechAdmin) {
    if (null == user || null == groupName || null == permissionName) {
        return false;
    }
    List<Role> roles = new ArrayList<Role>();
    List<Role> rolesWithPermission = this.getRoleManager().getRolesWithPermission(permissionName);
    if (null != rolesWithPermission) {
        roles.addAll(rolesWithPermission);
    }
    if (chechAdmin) {
        List<Role> rolesWithSupPermission = this.getRoleManager().getRolesWithPermission(Permission.SUPERUSER);
        if (null != rolesWithSupPermission) {
            roles.addAll(rolesWithSupPermission);
        }
    }
    for (int i = 0; i < roles.size(); i++) {
        Role role = roles.get(i);
        if (null != role) {
            boolean check = this.isAuthOnGroupAndRole(user, groupName, role.getName(), chechAdmin);
            if (check) {
                return true;
            }
        }
    }
    return false;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ArrayList(java.util.ArrayList)

Example 39 with Role

use of com.agiletec.aps.system.services.role.Role in project entando-core by entando.

the class AuthorizationManager method addUserAuthorization.

@Override
public void addUserAuthorization(String username, String groupName, String roleName) throws ApsSystemException {
    try {
        Group group = (null != groupName) ? this.getGroupManager().getGroup(groupName) : null;
        if (null != groupName && null == group) {
            _logger.warn("invalid authorization -  invalid referenced group name");
            return;
        }
        Role role = (null != roleName) ? this.getRoleManager().getRole(roleName) : null;
        if (null != roleName && null == role) {
            _logger.warn("invalid authorization -  invalid referenced role name");
            return;
        }
        Authorization authorization = new Authorization(group, role);
        this.addUserAuthorization(username, authorization);
    } catch (Throwable t) {
        _logger.error("Error adding user authorization for user '{}'", username, t);
        throw new ApsSystemException("Error adding user authorization for user " + username, t);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 40 with Role

use of com.agiletec.aps.system.services.role.Role in project entando-core by entando.

the class AuthorizationManager method getUserAuthorizations.

@Override
public List<Authorization> getUserAuthorizations(String username) throws ApsSystemException {
    List<Authorization> authorizations = null;
    try {
        Map<String, Group> groups = (Map<String, Group>) this.getAuthorityMap(this.getGroupManager().getGroups());
        Map<String, Role> roles = (Map<String, Role>) this.getAuthorityMap(this.getRoleManager().getRoles());
        authorizations = this.getAuthorizationDAO().getUserAuthorizations(username, groups, roles);
    } catch (Throwable t) {
        _logger.error("Error extracting user authorizations for user '{}'", username, t);
        throw new ApsSystemException("Error extracting user authorizations for user " + username, t);
    }
    return authorizations;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Role (com.agiletec.aps.system.services.role.Role)40 Group (com.agiletec.aps.system.services.group.Group)13 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 ArrayList (java.util.ArrayList)5 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)5 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)4 IRoleManager (com.agiletec.aps.system.services.role.IRoleManager)4 List (java.util.List)4 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)4 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)4 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)3 Filter (org.entando.entando.web.common.model.Filter)3 RoleRequest (org.entando.entando.web.role.model.RoleRequest)3 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)3 Authorization (com.agiletec.aps.system.services.authorization.Authorization)2 IAuthorizationService (com.agiletec.aps.system.services.authorization.IAuthorizationService)2