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;
}
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);
}
}
}
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");
}
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);
}
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());
}
Aggregations