Search in sources :

Example 1 with Role

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

the class TestAuthorityManager method testSetRemoveUserAuthorizations_1.

public void testSetRemoveUserAuthorizations_1() throws Throwable {
    String username = "pageManagerCustomers";
    String groupName = "management";
    String roleName = "pageManager";
    Group groupForTest = this.getGroup(groupName);
    assertNotNull(groupForTest);
    Role roleForTest = this.getRole(roleName);
    assertNotNull(roleForTest);
    List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
    assertNotNull(usersByGroup);
    assertEquals(0, usersByGroup.size());
    try {
        this._authorizationManager.addUserAuthorization(username, groupName, roleName);
        usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
        assertNotNull(usersByGroup);
        assertEquals(1, usersByGroup.size());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._authorizationManager.deleteUserAuthorization(username, groupName, roleName);
        usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
        assertNotNull(usersByGroup);
        assertEquals(0, usersByGroup.size());
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group)

Example 2 with Role

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

the class RoleService method getRoles.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<RoleDto> getRoles(RestListRequest restRequest) {
    List<Role> roles = this.getRoleManager().getRoles();
    roles = sortRoleList(restRequest, roles);
    if (null != restRequest.getFilter()) {
        for (Filter f : restRequest.getFilter()) {
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_CODE)) {
                roles = roles.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_DESCR)) {
                roles = roles.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Role> subList = restRequest.getSublist(roles);
    List<RoleDto> dtoSlice = this.getDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<RoleDto> paginatedResult = new SearcherDaoPaginatedResult(roles.size(), dtoSlice);
    PagedMetadata<RoleDto> pagedMetadata = new PagedMetadata<>(restRequest, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 3 with Role

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

the class RoleService method addRole.

@Override
public RoleDto addRole(RoleRequest roleRequest) {
    try {
        Role role = this.createRole(roleRequest);
        BeanPropertyBindingResult validationResult = this.validateRoleForAdd(role);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getRoleManager().addRole(role);
        RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
        return dto;
    } catch (ApsSystemException e) {
        logger.error("Error adding a role", e);
        throw new RestServerError("error in add role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 4 with Role

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

the class RoleService method removeRole.

@Override
public void removeRole(String roleCode) {
    try {
        Role role = this.getRoleManager().getRole(roleCode);
        if (null == role) {
            logger.info("role {} does not exists", roleCode);
            return;
        }
        BeanPropertyBindingResult validationResult = this.validateRoleForDelete(role);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getRoleManager().removeRole(role);
    } catch (ApsSystemException e) {
        logger.error("Error in delete role {}", roleCode, e);
        throw new RestServerError("error in delete role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 5 with Role

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

the class RoleService method createRole.

protected Role createRole(RoleRequest roleRequest) {
    Role role = new Role();
    role.setName(roleRequest.getCode());
    role.setDescription(roleRequest.getName());
    if (null != roleRequest.getPermissions()) {
        roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
    }
    return role;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Role(com.agiletec.aps.system.services.role.Role) RoleValidator(org.entando.entando.web.role.validator.RoleValidator) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IRoleManager(com.agiletec.aps.system.services.role.IRoleManager) IAuthorizationService(com.agiletec.aps.system.services.authorization.IAuthorizationService) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RoleRequest(org.entando.entando.web.role.model.RoleRequest) Permission(com.agiletec.aps.system.services.role.Permission) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) PostConstruct(javax.annotation.PostConstruct) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) Comparator(java.util.Comparator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder)

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