mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-16 07:10:48 +00:00
Merge branch 'bug5080'
This commit is contained in:
commit
20aaec2114
5 files changed
+69
-3
No files matched your search
+38
@@ -7,6 +7,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -22,6 +24,7 @@ import com.sap.sse.common.Util;
|
||||
public class UserGroupApiTest extends AbstractSeleniumTest {
|
||||
|
||||
private final UserGroupApi userGroupApi = new UserGroupApi();
|
||||
private final RoleApi roleApi = new RoleApi();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -68,6 +71,41 @@ public class UserGroupApiTest extends AbstractSeleniumTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetaPermissionCheck() {
|
||||
final ApiContext adminCtx = createAdminApiContext(getContextRoot(), SECURITY_CONTEXT);
|
||||
|
||||
// add test users
|
||||
final SecurityApi securityApi = new SecurityApi();
|
||||
final String addingUsername = "adding user";
|
||||
final String addedUsername = "added user";
|
||||
|
||||
securityApi.createUser(adminCtx, addingUsername, "test", "company", "password");
|
||||
securityApi.createUser(adminCtx, addedUsername, "test", "company", "password");
|
||||
|
||||
final ApiContext userCtx = ApiContext.createApiContext(getContextRoot(), SECURITY_CONTEXT, addingUsername,
|
||||
"password");
|
||||
|
||||
// create user group
|
||||
final UserGroup userGroupCreated = userGroupApi.createUserGroup(adminCtx, "test-group-01");
|
||||
assertNotNull("GroupId is missing in reponse!", userGroupCreated.getGroupId());
|
||||
|
||||
// add new role to group with admin user
|
||||
final Role createdRole = roleApi.createRole(adminCtx, "My-Epic-Role");
|
||||
roleApi.updateRole(adminCtx, createdRole.getId(), Arrays.asList("*"), createdRole.getName());
|
||||
userGroupApi.addRoleToGroup(adminCtx, userGroupCreated.getGroupId(), createdRole.getId(), false);
|
||||
|
||||
try {
|
||||
|
||||
// add user to group with a user who does not have one of the roles implicated by the group
|
||||
userGroupApi.addUserToGroup(userCtx, userGroupCreated.getGroupId(), addedUsername);
|
||||
|
||||
fail("Expected unauthorized exception.");
|
||||
} catch (RuntimeException e) {
|
||||
assertTrue("Expected unauthorized exception", e.getMessage().contains("failed (rc=401)"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangeUsersInUserGroup() {
|
||||
final ApiContext adminCtx = createAdminApiContext(getContextRoot(), SECURITY_CONTEXT);
|
||||
|
||||
+7
-1
@@ -391,7 +391,13 @@ public class UserManagementServiceImpl extends RemoteServiceServlet implements U
|
||||
if (userByName == null) {
|
||||
throw new UserManagementException("user '" + username + "' not found.");
|
||||
}
|
||||
getSecurityService().addUserToUserGroup(tenant, userByName);
|
||||
if (getSecurityService().hasCurrentUserMetaPermissionsOfRoleDefinitionsWithQualification(
|
||||
tenant.getRoleDefinitionMap().keySet(), new Ownership(null, tenant))) {
|
||||
getSecurityService().addUserToUserGroup(tenant, userByName);
|
||||
} else {
|
||||
throw new UnauthorizedException(
|
||||
"Current user does not have all the meta permissions of the user group the user would be added to");
|
||||
}
|
||||
} else {
|
||||
throw new UnauthorizedException("Not permitted to add user to group");
|
||||
}
|
||||
|
||||
@@ -569,6 +569,9 @@ public interface SecurityService extends ReplicableWithObjectInputStream<Replica
|
||||
boolean hasCurrentUserMetaPermissionsOfRoleDefinitionWithQualification(RoleDefinition roleDefinition,
|
||||
Ownership qualificationForGrantedPermissions);
|
||||
|
||||
boolean hasCurrentUserMetaPermissionsOfRoleDefinitionsWithQualification(Set<RoleDefinition> roleDefinitions,
|
||||
Ownership qualificationForGrantedPermissions);
|
||||
|
||||
/**
|
||||
* @return {@code true} if the {@link UserStore} is initial or permission vertical migration is necessary.
|
||||
*/
|
||||
|
||||
@@ -1992,6 +1992,20 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCurrentUserMetaPermissionsOfRoleDefinitionsWithQualification(Set<RoleDefinition> roleDefinitions,
|
||||
Ownership qualificationForGrantedPermissions) {
|
||||
boolean result = true;
|
||||
for (final RoleDefinition roleDefinition : roleDefinitions) {
|
||||
result &= hasCurrentUserMetaPermissionsOfRoleDefinitionWithQualification(roleDefinition,
|
||||
qualificationForGrantedPermissions);
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleDefinition getOrCreateRoleDefinitionFromPrototype(final RolePrototype rolePrototype) {
|
||||
final RoleDefinition potentiallyExistingRoleDefinition = store.getRoleDefinition(rolePrototype.getId());
|
||||
|
||||
@@ -198,8 +198,13 @@ public class UserGroupResource extends AbstractSecurityResource {
|
||||
.build();
|
||||
} else {
|
||||
if (getService().hasCurrentUserUpdatePermission(usergroup)) {
|
||||
getService().addUserToUserGroup(usergroup, user);
|
||||
response = Response.ok().build();
|
||||
if (!getService().hasCurrentUserMetaPermissionsOfRoleDefinitionsWithQualification(
|
||||
usergroup.getRoleDefinitionMap().keySet(), new Ownership(null, usergroup))) {
|
||||
response = Response.status(Status.UNAUTHORIZED).build();
|
||||
} else {
|
||||
getService().addUserToUserGroup(usergroup, user);
|
||||
response = Response.ok().build();
|
||||
}
|
||||
} else {
|
||||
response = Response.status(Status.UNAUTHORIZED).build();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user