Search in sources :

Example 11 with Role

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

the class AuthorizationManager method getUsersByAuthorities.

@Override
public List<String> getUsersByAuthorities(String groupName, String roleName, boolean includeAdmin) throws ApsSystemException {
    List<String> usernames = null;
    try {
        List<String> groupNames = null;
        if (!StringUtils.isEmpty(groupName)) {
            groupNames = new ArrayList<String>();
            groupNames.add(groupName);
            if (includeAdmin && !groupName.equals(Group.ADMINS_GROUP_NAME)) {
                groupNames.add(Group.ADMINS_GROUP_NAME);
            }
        }
        List<String> roleNames = null;
        if (!StringUtils.isEmpty(roleName)) {
            roleNames = new ArrayList<String>();
            roleNames.add(roleName);
            if (includeAdmin) {
                List<Role> adminRoles = this.getRoleManager().getRolesWithPermission(Permission.SUPERUSER);
                if (null != adminRoles) {
                    for (int i = 0; i < adminRoles.size(); i++) {
                        Role role = adminRoles.get(i);
                        if (null != role && !roleNames.contains(role.getName())) {
                            roleNames.add(role.getName());
                        }
                    }
                }
            }
        }
        usernames = this.getAuthorizationDAO().getUsersByAuthorities(groupNames, roleNames);
    } catch (Throwable t) {
        _logger.error("Error extracting usernames by authorities - group '{}' : role {}", groupName, roleName, t);
        throw new ApsSystemException("Error extracting usernames by authorities", t);
    }
    return usernames;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 12 with Role

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

the class AuthorizationManager method addAuthoritiesByPermissionName.

private void addAuthoritiesByPermissionName(UserDetails user, String permissionName, List auths) {
    List<Role> roles = this.getRolesWithPermission(user, permissionName);
    for (int i = 0; i < roles.size(); i++) {
        Role role = roles.get(i);
        List groupAuths = this.getRelatedAuthorities(user, role);
        if (null != groupAuths) {
            auths.addAll(groupAuths);
        }
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with Role

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

the class TestUserAuthorizationAction method addTestUserAndAuthorities.

private void addTestUserAndAuthorities() throws ApsSystemException {
    Group groupForTest = new Group();
    groupForTest.setName(TEST_GROUP_NAME);
    groupForTest.setDescription("group test description");
    this._groupManager.addGroup(groupForTest);
    Role roleForTest = new Role();
    roleForTest.setName(TEST_ROLE_NAME);
    roleForTest.setDescription("role test description");
    this._roleManager.addRole(roleForTest);
    User user = new User();
    user.setUsername(TEST_USER_NAME);
    user.setPassword(TEST_USER_PASSWORD);
    this._userManager.addUser(user);
    this._authorizationManager.addUserAuthorization(TEST_USER_NAME, Group.FREE_GROUP_NAME, TEST_ROLE_NAME);
    this._authorizationManager.addUserAuthorization(TEST_USER_NAME, TEST_GROUP_NAME, "admin");
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group) User(com.agiletec.aps.system.services.user.User)

Example 14 with Role

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

the class TestUserAuthorizationAction method removeTestUserAndAuthorities.

private void removeTestUserAndAuthorities() throws ApsSystemException {
    this._userManager.removeUser(TEST_USER_NAME);
    Group groupForTest = this._groupManager.getGroup(TEST_GROUP_NAME);
    this._groupManager.removeGroup(groupForTest);
    Role roleForTest = this._roleManager.getRole(TEST_ROLE_NAME);
    this._roleManager.removeRole(roleForTest);
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group)

Example 15 with Role

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

the class TestRoleAction method testEdit.

public void testEdit() throws Throwable {
    String roleName = "editor";
    String result = this.executeEdit("admin", roleName);
    assertEquals(Action.SUCCESS, result);
    RoleAction roleAction = (RoleAction) this.getAction();
    Role role = this._roleManager.getRole(roleName);
    assertEquals(ApsAdminSystemConstants.EDIT, roleAction.getStrutsAction());
    assertEquals(role.getName(), roleAction.getName());
    assertEquals(role.getDescription(), roleAction.getDescription());
    assertEquals(role.getPermissions().size(), roleAction.getPermissionNames().size());
    assertEquals(this._roleManager.getPermissions().size(), roleAction.getSystemPermissions().size());
}
Also used : Role(com.agiletec.aps.system.services.role.Role)

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