Search in sources :

Example 1 with Permission

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

the class TestAuthorizationManager method testCheckAdminUser.

public void testCheckAdminUser() throws Throwable {
    // nel database di test, username e password sono uguali
    UserDetails adminUser = this._authenticationProvider.getUser("admin", "admin");
    assertNotNull(adminUser);
    assertEquals("admin", adminUser.getUsername());
    assertEquals(1, adminUser.getAuthorizations().size());
    List<Group> groups = this._groupManager.getGroups();
    for (int i = 0; i < groups.size(); i++) {
        Group group = groups.get(i);
        boolean check = this._authorizationManager.isAuth(adminUser, group);
        assertTrue(check);
        check = this._authorizationManager.isAuthOnGroup(adminUser, group.getName());
        assertTrue(check);
    }
    List<Permission> permissions = new ArrayList<Permission>(this._roleManager.getPermissions());
    for (int i = 0; i < permissions.size(); i++) {
        Permission perm = permissions.get(i);
        boolean check = this._authorizationManager.isAuth(adminUser, perm);
        assertTrue(check);
        check = this._authorizationManager.isAuthOnPermission(adminUser, perm.getName());
        assertTrue(check);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Permission(com.agiletec.aps.system.services.role.Permission) ArrayList(java.util.ArrayList)

Example 2 with Permission

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

the class PermissionCacheWrapper method initCache.

@Override
public void initCache(IPermissionDAO permissionDAO) throws ApsSystemException {
    try {
        Cache cache = this.getCache();
        this.releaseCachedObjects(cache);
        Map<String, Permission> permissions = permissionDAO.loadPermissions();
        this.insertObjectsOnCache(cache, permissions);
    } catch (Throwable t) {
        _logger.error("Error loading permissions", t);
        throw new ApsSystemException("Error loading permissions", t);
    }
}
Also used : Permission(com.agiletec.aps.system.services.role.Permission) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Cache(org.springframework.cache.Cache)

Example 3 with Permission

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

the class RoleService method getPermissions.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<PermissionDto> getPermissions(RestListRequest requestList) {
    List<Permission> permissions = this.getRoleManager().getPermissions();
    permissions = sortPermissionList(requestList, permissions);
    if (null != requestList.getFilter()) {
        for (Filter f : requestList.getFilter()) {
            if (f.getAttributeName().equals(KEY_FILTER_PERMISSION_CODE)) {
                permissions = permissions.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_PERMISSION_DESCR)) {
                permissions = permissions.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Permission> subList = requestList.getSublist(permissions);
    List<PermissionDto> dtoSlice = this.getPermissionDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<PermissionDto> paginatedResult = new SearcherDaoPaginatedResult(permissions.size(), dtoSlice);
    PagedMetadata<PermissionDto> pagedMetadata = new PagedMetadata<>(requestList, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Permission(com.agiletec.aps.system.services.role.Permission) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 4 with Permission

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

the class AbstractApiAction method getPermissionAutorityOptions.

public List<SelectItem> getPermissionAutorityOptions() {
    List<SelectItem> items = new ArrayList<SelectItem>();
    try {
        List<Permission> permissions = new ArrayList<Permission>();
        permissions.addAll(this.getRoleManager().getPermissions());
        BeanComparator comparator = new BeanComparator("description");
        Collections.sort(permissions, comparator);
        for (int i = 0; i < permissions.size(); i++) {
            Permission permission = permissions.get(i);
            items.add(new SelectItem(permission.getName(), this.getPermissionAutorityOptionPrefix() + permission.getDescription()));
        }
    } catch (Throwable t) {
        _logger.error("Error extracting autority options", t);
    }
    return items;
}
Also used : SelectItem(com.agiletec.aps.util.SelectItem) ArrayList(java.util.ArrayList) Permission(com.agiletec.aps.system.services.role.Permission) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 5 with Permission

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

the class RoleAction method getRolePermissions.

public Set<Permission> getRolePermissions() {
    Set<String> permissionNames = this.getPermissionNames();
    Set<Permission> rolePermissions = new HashSet<Permission>(permissionNames.size());
    Iterator<String> permsIter = permissionNames.iterator();
    while (permsIter.hasNext()) {
        String permissionName = permsIter.next();
        Permission permission = this.getRoleManager().getPermission(permissionName);
        rolePermissions.add(permission);
    }
    return rolePermissions;
}
Also used : Permission(com.agiletec.aps.system.services.role.Permission) HashSet(java.util.HashSet)

Aggregations

Permission (com.agiletec.aps.system.services.role.Permission)5 ArrayList (java.util.ArrayList)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 Group (com.agiletec.aps.system.services.group.Group)1 UserDetails (com.agiletec.aps.system.services.user.UserDetails)1 SelectItem (com.agiletec.aps.util.SelectItem)1 HashSet (java.util.HashSet)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 PermissionDto (org.entando.entando.aps.system.services.role.model.PermissionDto)1 Filter (org.entando.entando.web.common.model.Filter)1 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)1 Cache (org.springframework.cache.Cache)1