[KEYCLOAK-8049] - Prevent users from not choosing a group

This commit is contained in:
Pedro Igor 2019-12-17 18:32:33 -03:00 committed by Stian Thorgersen
parent 90b35cc13d
commit 421ec34557
3 changed files with 22 additions and 3 deletions

View file

@ -171,8 +171,9 @@ public class GroupPolicyProviderFactory implements PolicyProviderFactory<GroupPo
group = authorization.getRealm().getGroupById(definition.getId());
}
if (group == null) {
String path = definition.getPath();
if (group == null && path != null) {
String canonicalPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
if (canonicalPath != null) {

View file

@ -169,6 +169,20 @@ public class GroupPolicyManagementTest extends AbstractAuthorizationSettingsTest
assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
@Test
public void testSaveWithInInvalidGroup() throws InterruptedException {
authorizationPage.navigateTo();
GroupPolicyRepresentation expected = new GroupPolicyRepresentation();
expected.setName("Test Invalid Group Policy");
expected.setDescription("description");
expected.addGroupPath("/Groups", true);
authorizationPage.authorizationTabs().policies().create(expected, false);
alert.assertDanger("Error! You must choose a group");
}
private GroupPolicyRepresentation createPolicy(GroupPolicyRepresentation expected) {
GroupPolicy policy = authorizationPage.authorizationTabs().policies().create(expected);
assertAlertSuccess();

View file

@ -1772,7 +1772,7 @@ module.controller('ResourceServerPolicyRoleDetailCtrl', function($scope, $route,
}
});
module.controller('ResourceServerPolicyGroupDetailCtrl', function($scope, $route, realm, client, Client, Groups, Group, PolicyController) {
module.controller('ResourceServerPolicyGroupDetailCtrl', function($scope, $route, realm, client, Client, Groups, Group, PolicyController, Notifications) {
PolicyController.onInit({
getPolicyType : function() {
return "group";
@ -1821,6 +1821,10 @@ module.controller('ResourceServerPolicyGroupDetailCtrl', function($scope, $route
return
}
}
if (group.id == "realm") {
Notifications.error("You must choose a group");
return;
}
$scope.selectedGroups.push({id: group.id, path: group.path});
$scope.changed = true;
}