[KEYCLOAK-5806] - Create policy button to Aggregated Policies
This commit is contained in:
parent
b121306749
commit
eba47b3c89
29 changed files with 385 additions and 84 deletions
|
@ -17,8 +17,8 @@
|
|||
package org.keycloak.testsuite.console.page.clients.authorization.policy;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.UserPolicyRepresentation;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
||||
|
@ -37,6 +37,10 @@ public class AggregatePolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(AggregatePolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
|
||||
public void createPolicy(AbstractPolicyRepresentation expected) {
|
||||
form().createPolicy(expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,15 @@
|
|||
*/
|
||||
package org.keycloak.testsuite.console.page.clients.authorization.policy;
|
||||
|
||||
import static org.keycloak.testsuite.util.UIUtils.performOperationWithPageReload;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.Logic;
|
||||
import org.keycloak.representations.idm.authorization.RolePolicyRepresentation;
|
||||
import org.keycloak.testsuite.console.page.fragment.ModalDialog;
|
||||
import org.keycloak.testsuite.console.page.fragment.MultipleStringSelect2;
|
||||
import org.keycloak.testsuite.page.Form;
|
||||
|
@ -50,7 +55,16 @@ public class AggregatePolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(AggregatePolicyRepresentation expected) {
|
||||
@FindBy(id = "create-policy-btn")
|
||||
private WebElement createPolicyBtn;
|
||||
|
||||
@FindBy(id = "create-policy")
|
||||
private Select createPolicySelect;
|
||||
|
||||
@Page
|
||||
private RolePolicy rolePolicy;
|
||||
|
||||
public void populate(AggregatePolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
@ -58,9 +72,11 @@ public class AggregatePolicyForm extends Form {
|
|||
Set<String> selectedPolicies = policySelect.getSelected();
|
||||
Set<String> policies = expected.getPolicies();
|
||||
|
||||
for (String policy : policies) {
|
||||
if (!selectedPolicies.contains(policy)) {
|
||||
policySelect.select(policy);
|
||||
if (policies != null) {
|
||||
for (String policy : policies) {
|
||||
if (!selectedPolicies.contains(policy)) {
|
||||
policySelect.select(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +95,9 @@ public class AggregatePolicyForm extends Form {
|
|||
}
|
||||
}
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
@ -97,4 +115,13 @@ public class AggregatePolicyForm extends Form {
|
|||
|
||||
return representation;
|
||||
}
|
||||
|
||||
public void createPolicy(AbstractPolicyRepresentation expected) {
|
||||
createPolicyBtn.click();
|
||||
performOperationWithPageReload(() -> createPolicySelect.selectByValue(expected.getType()));
|
||||
|
||||
if ("role".equals(expected.getType())) {
|
||||
rolePolicy.form().populate((RolePolicyRepresentation) expected, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,6 @@ public class ClientPolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(ClientPolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,14 +56,16 @@ public class ClientPolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(ClientPolicyRepresentation expected) {
|
||||
public void populate(ClientPolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
||||
clientsInput.update(expected.getClients());
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.keycloak.testsuite.console.page.clients.authorization.policy;
|
|||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.representations.idm.authorization.GroupPolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.RolePolicyRepresentation;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
||||
|
@ -37,6 +36,6 @@ public class GroupPolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(GroupPolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class GroupPolicyForm extends Form {
|
|||
@Drone
|
||||
private WebDriver driver;
|
||||
|
||||
public void populate(GroupPolicyRepresentation expected) {
|
||||
public void populate(GroupPolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
setInputValue(groupsClaim, expected.getGroupsClaim());
|
||||
|
@ -109,7 +109,9 @@ public class GroupPolicyForm extends Form {
|
|||
});
|
||||
}
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private void unselect(String path) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.keycloak.testsuite.console.page.clients.authorization.policy;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.JSPolicyRepresentation;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +36,6 @@ public class JSPolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(JSPolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class JSPolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(JSPolicyRepresentation expected) {
|
||||
public void populate(JSPolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
@ -54,7 +54,9 @@ public class JSPolicyForm extends Form {
|
|||
|
||||
scriptExecutor.executeScript("angular.element(document.getElementById('code')).scope().policy.code = '" + expected.getCode() + "'");
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -79,40 +79,44 @@ public class Policies extends Form {
|
|||
return table;
|
||||
}
|
||||
|
||||
public <P extends PolicyTypeUI> P create(AbstractPolicyRepresentation expected) {
|
||||
public <P extends PolicyTypeUI> P create(AbstractPolicyRepresentation expected, boolean save) {
|
||||
String type = expected.getType();
|
||||
|
||||
performOperationWithPageReload(() -> createSelect.selectByValue(type));
|
||||
|
||||
if ("role".equals(type)) {
|
||||
rolePolicy.form().populate((RolePolicyRepresentation) expected);
|
||||
rolePolicy.form().populate((RolePolicyRepresentation) expected, save);
|
||||
return (P) rolePolicy;
|
||||
} else if ("user".equals(type)) {
|
||||
userPolicy.form().populate((UserPolicyRepresentation) expected);
|
||||
userPolicy.form().populate((UserPolicyRepresentation) expected, save);
|
||||
return (P) userPolicy;
|
||||
} else if ("aggregate".equals(type)) {
|
||||
aggregatePolicy.form().populate((AggregatePolicyRepresentation) expected);
|
||||
aggregatePolicy.form().populate((AggregatePolicyRepresentation) expected, save);
|
||||
return (P) aggregatePolicy;
|
||||
} else if ("js".equals(type)) {
|
||||
jsPolicy.form().populate((JSPolicyRepresentation) expected);
|
||||
jsPolicy.form().populate((JSPolicyRepresentation) expected, save);
|
||||
return (P) jsPolicy;
|
||||
} else if ("time".equals(type)) {
|
||||
timePolicy.form().populate((TimePolicyRepresentation) expected);
|
||||
timePolicy.form().populate((TimePolicyRepresentation) expected, save);
|
||||
return (P) timePolicy;
|
||||
} else if ("rules".equals(type)) {
|
||||
rulePolicy.form().populate((RulePolicyRepresentation) expected);
|
||||
rulePolicy.form().populate((RulePolicyRepresentation) expected, save);
|
||||
return (P) rulePolicy;
|
||||
} else if ("client".equals(type)) {
|
||||
clientPolicy.form().populate((ClientPolicyRepresentation) expected);
|
||||
clientPolicy.form().populate((ClientPolicyRepresentation) expected, save);
|
||||
return (P) clientPolicy;
|
||||
} else if ("group".equals(type)) {
|
||||
groupPolicy.form().populate((GroupPolicyRepresentation) expected);
|
||||
groupPolicy.form().populate((GroupPolicyRepresentation) expected, save);
|
||||
return (P) groupPolicy;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <P extends PolicyTypeUI> P create(AbstractPolicyRepresentation expected) {
|
||||
return create(expected, true);
|
||||
}
|
||||
|
||||
public void update(String name, AbstractPolicyRepresentation representation) {
|
||||
for (WebElement row : policies().rows()) {
|
||||
PolicyRepresentation actual = policies().toRepresentation(row);
|
||||
|
@ -121,21 +125,21 @@ public class Policies extends Form {
|
|||
String type = representation.getType();
|
||||
|
||||
if ("role".equals(type)) {
|
||||
rolePolicy.form().populate((RolePolicyRepresentation) representation);
|
||||
rolePolicy.form().populate((RolePolicyRepresentation) representation, true);
|
||||
} else if ("user".equals(type)) {
|
||||
userPolicy.form().populate((UserPolicyRepresentation) representation);
|
||||
userPolicy.form().populate((UserPolicyRepresentation) representation, true);
|
||||
} else if ("aggregate".equals(type)) {
|
||||
aggregatePolicy.form().populate((AggregatePolicyRepresentation) representation);
|
||||
aggregatePolicy.form().populate((AggregatePolicyRepresentation) representation, true);
|
||||
} else if ("js".equals(type)) {
|
||||
jsPolicy.form().populate((JSPolicyRepresentation) representation);
|
||||
jsPolicy.form().populate((JSPolicyRepresentation) representation, true);
|
||||
} else if ("time".equals(type)) {
|
||||
timePolicy.form().populate((TimePolicyRepresentation) representation);
|
||||
timePolicy.form().populate((TimePolicyRepresentation) representation, true);
|
||||
} else if ("rules".equals(type)) {
|
||||
rulePolicy.form().populate((RulePolicyRepresentation) representation);
|
||||
rulePolicy.form().populate((RulePolicyRepresentation) representation, true);
|
||||
} else if ("client".equals(type)) {
|
||||
clientPolicy.form().populate((ClientPolicyRepresentation) representation);
|
||||
clientPolicy.form().populate((ClientPolicyRepresentation) representation, true);
|
||||
} else if ("group".equals(type)) {
|
||||
groupPolicy.form().populate((GroupPolicyRepresentation) representation);
|
||||
groupPolicy.form().populate((GroupPolicyRepresentation) representation, true);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -36,6 +36,6 @@ public class RolePolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(RolePolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RolePolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(RolePolicyRepresentation expected) {
|
||||
public void populate(RolePolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
@ -88,7 +88,9 @@ public class RolePolicyForm extends Form {
|
|||
unSelect(roles, realmRoleSelect.getSelected());
|
||||
unSelect(roles, clientRoleSelect.getSelected());
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private void unSelect(Set<RolePolicyRepresentation.RoleDefinition> roles, Set<RolePolicyRepresentation.RoleDefinition> selection) {
|
||||
|
|
|
@ -36,6 +36,6 @@ public class RulePolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(RulePolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class RulePolicyForm extends Form {
|
|||
@FindBy(id = "resolveModule")
|
||||
private WebElement resolveModuleButton;
|
||||
|
||||
public void populate(RulePolicyRepresentation expected) {
|
||||
public void populate(RulePolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
setInputValue(artifactGroupId, expected.getArtifactGroupId());
|
||||
|
@ -94,7 +94,9 @@ public class RulePolicyForm extends Form {
|
|||
scannerPeriodUnit.selectByVisibleText(expected.getScannerPeriodUnit());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -36,6 +36,6 @@ public class TimePolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(TimePolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TimePolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(TimePolicyRepresentation expected) {
|
||||
public void populate(TimePolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
@ -98,7 +98,9 @@ public class TimePolicyForm extends Form {
|
|||
setInputValue(minute, expected.getMinute());
|
||||
setInputValue(minuteEnd, expected.getMinuteEnd());
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -36,6 +36,6 @@ public class UserPolicy implements PolicyTypeUI {
|
|||
}
|
||||
|
||||
public void update(UserPolicyRepresentation expected) {
|
||||
form().populate(expected);
|
||||
form().populate(expected, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,14 +56,16 @@ public class UserPolicyForm extends Form {
|
|||
@FindBy(xpath = "//div[@class='modal-dialog']")
|
||||
protected ModalDialog modalDialog;
|
||||
|
||||
public void populate(UserPolicyRepresentation expected) {
|
||||
public void populate(UserPolicyRepresentation expected, boolean save) {
|
||||
setInputValue(name, expected.getName());
|
||||
setInputValue(description, expected.getDescription());
|
||||
logic.selectByValue(expected.getLogic().name());
|
||||
|
||||
usersInput.update(expected.getUsers());
|
||||
|
||||
save();
|
||||
if (save) {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -138,6 +138,87 @@ public class AggregatePolicyManagementTest extends AbstractAuthorizationSettings
|
|||
assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithChild() {
|
||||
AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
|
||||
|
||||
expected.setName("Test Child Create Aggregate Policy");
|
||||
expected.setDescription("description");
|
||||
|
||||
AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected, false);
|
||||
|
||||
RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
|
||||
|
||||
childPolicy.setName("Child Role Policy");
|
||||
childPolicy.addRole("Role A");
|
||||
|
||||
policy.createPolicy(childPolicy);
|
||||
policy.form().save();
|
||||
|
||||
assertAlertSuccess();
|
||||
|
||||
expected.addPolicy(childPolicy.getName());
|
||||
|
||||
authorizationPage.navigateTo();
|
||||
AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
|
||||
assertPolicy(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithChildAndSelectedPolicy() {
|
||||
AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
|
||||
|
||||
expected.setName("Test Child Create Aggregate Policy");
|
||||
expected.setDescription("description");
|
||||
expected.addPolicy("Policy C");
|
||||
|
||||
AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected, false);
|
||||
|
||||
RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
|
||||
|
||||
childPolicy.setName("Child Role Policy");
|
||||
childPolicy.addRole("Role A");
|
||||
|
||||
policy.createPolicy(childPolicy);
|
||||
policy.form().save();
|
||||
|
||||
assertAlertSuccess();
|
||||
|
||||
expected.addPolicy(childPolicy.getName());
|
||||
|
||||
authorizationPage.navigateTo();
|
||||
AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
|
||||
assertPolicy(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithChild() {
|
||||
AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
|
||||
|
||||
expected.setName("Test Child Update Aggregate Policy");
|
||||
expected.setDescription("description");
|
||||
expected.addPolicy("Policy C");
|
||||
|
||||
AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected);
|
||||
assertAlertSuccess();
|
||||
assertPolicy(expected, policy);
|
||||
|
||||
RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
|
||||
|
||||
childPolicy.setName("Child Role Policy");
|
||||
childPolicy.addRole("Role A");
|
||||
|
||||
policy.createPolicy(childPolicy);
|
||||
|
||||
policy.form().save();
|
||||
|
||||
expected.addPolicy(childPolicy.getName());
|
||||
|
||||
authorizationPage.navigateTo();
|
||||
AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
|
||||
assertPolicy(expected, actual);
|
||||
}
|
||||
|
||||
private AggregatePolicyRepresentation createPolicy(AggregatePolicyRepresentation expected) {
|
||||
AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected);
|
||||
assertAlertSuccess();
|
||||
|
|
|
@ -1153,7 +1153,7 @@ authz-no-type-defined=No type defined.
|
|||
authz-no-uri-defined=No URI defined.
|
||||
authz-no-permission-assigned=No permission assigned.
|
||||
authz-no-policy-assigned=No policy assigned.
|
||||
authz-create-permission=Create permission
|
||||
authz-create-permission=Create Permission
|
||||
|
||||
# Authz Resource Detail
|
||||
authz-add-resource=Add Resource
|
||||
|
@ -1172,7 +1172,7 @@ authz-scope-name.tooltip=An unique name for this scope. The name can be used to
|
|||
|
||||
# Authz Policy List
|
||||
authz-all-types=All types
|
||||
authz-create-policy=Create policy
|
||||
authz-create-policy=Create Policy
|
||||
authz-no-policies-available=No policies available.
|
||||
|
||||
# Authz Policy Detail
|
||||
|
|
|
@ -1814,7 +1814,7 @@ module.controller('ResourceServerPolicyGroupDetailCtrl', function($scope, $route
|
|||
if (!angular.equals($scope.selectedGroups, selectedGroups)) {
|
||||
$scope.changed = true;
|
||||
} else {
|
||||
$scope.changed = false;
|
||||
$scope.changed = PolicyController.isNewAssociatedPolicy();
|
||||
}
|
||||
}, true);
|
||||
},
|
||||
|
@ -1956,7 +1956,7 @@ module.controller('ResourceServerPolicyTimeDetailCtrl', function($scope, $route,
|
|||
}
|
||||
});
|
||||
|
||||
module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $route, $location, realm, PolicyController, ResourceServerPolicy, client) {
|
||||
module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $route, $location, realm, PolicyController, ResourceServerPolicy, client, PolicyProvider, policyState) {
|
||||
PolicyController.onInit({
|
||||
getPolicyType : function() {
|
||||
return "aggregate";
|
||||
|
@ -1991,26 +1991,68 @@ module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $r
|
|||
return object.name;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.policyProviders = [];
|
||||
|
||||
PolicyProvider.query({
|
||||
realm : $route.current.params.realm,
|
||||
client : client.id
|
||||
}, function (data) {
|
||||
for (i = 0; i < data.length; i++) {
|
||||
if (data[i].type != 'resource' && data[i].type != 'scope') {
|
||||
$scope.policyProviders.push(data[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onInitUpdate : function(policy) {
|
||||
ResourceServerPolicy.associatedPolicies({
|
||||
realm : $route.current.params.realm,
|
||||
client : client.id,
|
||||
id : policy.id
|
||||
}, function(policies) {
|
||||
$scope.selectedPolicies = [];
|
||||
for (i = 0; i < policies.length; i++) {
|
||||
policies[i].text = policies[i].name;
|
||||
$scope.selectedPolicies.push(policies[i]);
|
||||
if (PolicyController.isBackNewAssociatedPolicy()) {
|
||||
policy.name = policyState.state.name;
|
||||
policy.description = policyState.state.description;
|
||||
policy.decisionStrategy = policyState.state.decisionStrategy;
|
||||
policy.logic = policyState.state.logic;
|
||||
$scope.selectedPolicies = policyState.state.selectedPolicies;
|
||||
|
||||
if (!$scope.selectedPolicies) {
|
||||
$scope.selectedPolicies = [];
|
||||
}
|
||||
var copy = angular.copy($scope.selectedPolicies);
|
||||
$scope.$watch('selectedPolicies', function() {
|
||||
if (!angular.equals($scope.selectedPolicies, copy)) {
|
||||
$scope.changed = true;
|
||||
|
||||
$scope.changed = true;
|
||||
ResourceServerPolicy.query({
|
||||
realm: realm.realm,
|
||||
client : client.id,
|
||||
permission: false,
|
||||
name: policyState.state.newPolicyName,
|
||||
max : 20,
|
||||
first : 0
|
||||
}, function(response) {
|
||||
for (i = 0; i < response.length; i++) {
|
||||
if (response[i].name == policyState.state.newPolicyName) {
|
||||
response[i].text = response[i].name;
|
||||
$scope.selectedPolicies.push(response[i]);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ResourceServerPolicy.associatedPolicies({
|
||||
realm : $route.current.params.realm,
|
||||
client : client.id,
|
||||
id : policy.id
|
||||
}, function(policies) {
|
||||
$scope.selectedPolicies = [];
|
||||
for (i = 0; i < policies.length; i++) {
|
||||
policies[i].text = policies[i].name;
|
||||
$scope.selectedPolicies.push(policies[i]);
|
||||
}
|
||||
var copy = angular.copy($scope.selectedPolicies);
|
||||
$scope.$watch('selectedPolicies', function() {
|
||||
if (!angular.equals($scope.selectedPolicies, copy)) {
|
||||
$scope.changed = true;
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onUpdate : function() {
|
||||
|
@ -2025,7 +2067,37 @@ module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $r
|
|||
},
|
||||
|
||||
onInitCreate : function(newPolicy) {
|
||||
newPolicy.decisionStrategy = 'UNANIMOUS';
|
||||
policyState.previousPage.name = 'authz-add-aggregated-policy';
|
||||
if (PolicyController.isBackNewAssociatedPolicy()) {
|
||||
newPolicy.name = policyState.state.name;
|
||||
newPolicy.description = policyState.state.description;
|
||||
newPolicy.decisionStrategy = policyState.state.decisionStrategy;
|
||||
newPolicy.logic = policyState.state.logic;
|
||||
$scope.selectedPolicies = policyState.state.selectedPolicies;
|
||||
|
||||
if (!$scope.selectedPolicies) {
|
||||
$scope.selectedPolicies = [];
|
||||
}
|
||||
|
||||
$scope.changed = true;
|
||||
ResourceServerPolicy.query({
|
||||
realm: realm.realm,
|
||||
client : client.id,
|
||||
permission: false,
|
||||
name: policyState.state.newPolicyName,
|
||||
max : 20,
|
||||
first : 0
|
||||
}, function(response) {
|
||||
for (i = 0; i < response.length; i++) {
|
||||
if (response[i].name == policyState.state.newPolicyName) {
|
||||
response[i].text = response[i].name;
|
||||
$scope.selectedPolicies.push(response[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
newPolicy.decisionStrategy = 'UNANIMOUS';
|
||||
}
|
||||
},
|
||||
|
||||
onCreate : function() {
|
||||
|
@ -2041,11 +2113,49 @@ module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $r
|
|||
}, realm, client, $scope);
|
||||
});
|
||||
|
||||
module.service("PolicyController", function($http, $route, $location, ResourceServer, ResourceServerPolicy, ResourceServerPermission, AuthzDialog, Notifications) {
|
||||
module.service("PolicyController", function($http, $route, $location, ResourceServer, ResourceServerPolicy, ResourceServerPermission, AuthzDialog, Notifications, policyState) {
|
||||
|
||||
var PolicyController = {};
|
||||
|
||||
PolicyController.isNewAssociatedPolicy = function() {
|
||||
return $route.current.params['new_policy'] != null;
|
||||
}
|
||||
|
||||
PolicyController.isBackNewAssociatedPolicy = function() {
|
||||
return $route.current.params['back'] != null;
|
||||
}
|
||||
|
||||
PolicyController.onInit = function(delegate, realm, client, $scope) {
|
||||
if (!policyState.previousPage) {
|
||||
policyState.previousPage = {};
|
||||
}
|
||||
|
||||
$scope.policyState = policyState;
|
||||
|
||||
$scope.addPolicy = function(policyType) {
|
||||
policyState.state = $scope.policy;
|
||||
if ($scope.selectedPolicies) {
|
||||
policyState.state.selectedPolicies = $scope.selectedPolicies;
|
||||
}
|
||||
var previousUrl = window.location.href.substring(window.location.href.indexOf('/realms'));
|
||||
|
||||
if (previousUrl.indexOf('back=true') == -1) {
|
||||
previousUrl = previousUrl + '?back=true';
|
||||
}
|
||||
policyState.state.previousUrl = previousUrl;
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + policyType.type + "/create?new_policy=true");
|
||||
}
|
||||
|
||||
$scope.createNewPolicy = function() {
|
||||
$scope.showNewPolicy = true;
|
||||
}
|
||||
|
||||
$scope.cancelCreateNewPolicy = function() {
|
||||
$scope.showNewPolicy = false;
|
||||
}
|
||||
|
||||
$scope.historyBackOnSaveOrCancel = PolicyController.isNewAssociatedPolicy();
|
||||
|
||||
if (!delegate.isPermission) {
|
||||
delegate.isPermission = function () {
|
||||
return false;
|
||||
|
@ -2078,7 +2188,6 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
|
||||
if (!policyId) {
|
||||
$scope.create = true;
|
||||
$scope.changed = false;
|
||||
|
||||
var policy = {};
|
||||
|
||||
|
@ -2090,6 +2199,8 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
delegate.onInitCreate(policy);
|
||||
}
|
||||
|
||||
$scope.changed = $scope.historyBackOnSaveOrCancel || PolicyController.isBackNewAssociatedPolicy();
|
||||
|
||||
$scope.policy = angular.copy(policy);
|
||||
|
||||
$scope.$watch('policy', function() {
|
||||
|
@ -2105,10 +2216,20 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
}
|
||||
service.save({realm : realm.realm, client : client.id, type: $scope.policy.type}, $scope.policy, function(data) {
|
||||
if (delegate.isPermission()) {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/" + $scope.policy.type + "/" + data.id);
|
||||
if ($scope.historyBackOnSaveOrCancel) {
|
||||
policyState.state.newPolicyName = $scope.policy.name;
|
||||
$location.url(policyState.state.previousUrl);
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/" + $scope.policy.type + "/" + data.id);
|
||||
}
|
||||
Notifications.success("The permission has been created.");
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + $scope.policy.type + "/" + data.id);
|
||||
if ($scope.historyBackOnSaveOrCancel) {
|
||||
policyState.state.newPolicyName = $scope.policy.name;
|
||||
$location.url(policyState.state.previousUrl);
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + $scope.policy.type + "/" + data.id);
|
||||
}
|
||||
Notifications.success("The policy has been created.");
|
||||
}
|
||||
});
|
||||
|
@ -2117,9 +2238,17 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
|
||||
$scope.reset = function() {
|
||||
if (delegate.isPermission()) {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/");
|
||||
if ($scope.historyBackOnSaveOrCancel) {
|
||||
$location.url(policyState.state.previousUrl);
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/");
|
||||
}
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/");
|
||||
if ($scope.historyBackOnSaveOrCancel) {
|
||||
$location.url(policyState.state.previousUrl);
|
||||
} else {
|
||||
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -2137,7 +2266,7 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
}
|
||||
|
||||
$scope.policy = angular.copy(policy);
|
||||
$scope.changed = false;
|
||||
$scope.changed = $scope.historyBackOnSaveOrCancel || PolicyController.isBackNewAssociatedPolicy();
|
||||
|
||||
$scope.$watch('policy', function() {
|
||||
if (!angular.equals($scope.policy, policy)) {
|
||||
|
@ -2162,14 +2291,18 @@ module.service("PolicyController", function($http, $route, $location, ResourceSe
|
|||
}
|
||||
|
||||
$scope.reset = function() {
|
||||
var freshPolicy = angular.copy(data);
|
||||
if ($scope.historyBackOnSaveOrCancel) {
|
||||
$location.url(policyState.state.previousUrl);
|
||||
} else {
|
||||
var freshPolicy = angular.copy(data);
|
||||
|
||||
if (delegate.onInitUpdate) {
|
||||
delegate.onInitUpdate(freshPolicy);
|
||||
if (delegate.onInitUpdate) {
|
||||
delegate.onInitUpdate(freshPolicy);
|
||||
}
|
||||
|
||||
$scope.policy = angular.copy(freshPolicy);
|
||||
$scope.changed = false;
|
||||
}
|
||||
|
||||
$scope.policy = angular.copy(freshPolicy);
|
||||
$scope.changed = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -200,5 +200,11 @@ module.factory('GroupManagementPermissions', function($resource) {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
module.factory('policyState', [function () {
|
||||
return {
|
||||
model: {
|
||||
state: {}
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-aggregated-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'authz-aggregated' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
@ -32,12 +34,30 @@
|
|||
</div>
|
||||
<div class="form-group clearfix">
|
||||
<label class="col-md-2 control-label" for="policies">{{:: 'authz-policy-apply-policy' | translate}} <span class="required">*</span></label>
|
||||
|
||||
<div class="col-md-6">
|
||||
<input type="hidden" ui-select2="policiesUiSelect" id="policies" data-ng-model="selectedPolicies" data-placeholder="{{:: 'authz-select-a-policy' | translate}}..." multiple required />
|
||||
<div class="col-sm-6">
|
||||
<input type="hidden" ui-select2="policiesUiSelect" id="policies" data-ng-model="selectedPolicies" data-placeholder="{{:: 'authz-select-a-policy' | translate}}..." multiple data-ng-required="!selectedPolicies || selectedPolicies.length == 0" />
|
||||
</div>
|
||||
<kc-tooltip>{{:: 'authz-policy-apply-policy.tooltip' | translate}}</kc-tooltip>
|
||||
</div>
|
||||
<div class="form-group clearfix" data-ng-hide="historyBackOnSaveOrCancel">
|
||||
<label class="col-md-2 control-label" for="policies"></label>
|
||||
<div class="col-sm-6">
|
||||
<div class="input-group">
|
||||
<div class="input-group-btn" data-ng-hide="showNewPolicy == true">
|
||||
<button data-ng-click="createNewPolicy()" id="create-policy-btn" class="btn btn-primary">{{:: 'authz-create-policy' | translate}}</button>
|
||||
</div>
|
||||
<select id="create-policy" ng-model="policyType" class="form-control"
|
||||
ng-options="p.name for p in policyProviders track by p.type"
|
||||
data-ng-change="addPolicy(policyType);"
|
||||
data-ng-show="showNewPolicy == true">
|
||||
<option value="" disabled selected>{{:: 'authz-create-policy' | translate}}...</option>
|
||||
</select>
|
||||
<div class="input-group-btn" data-ng-show="showNewPolicy == true">
|
||||
<button data-ng-click="cancelCreateNewPolicy()" id="cancel-create-policy-btn" class="btn btn-primary">{{:: 'cancel' | translate}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group clearfix">
|
||||
<label class="col-md-2 control-label" for="policy.decisionStrategy">{{:: 'authz-policy-decision-strategy' | translate}}</label>
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-client-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'client' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-drools-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">Rules</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-group-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'groups' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-js-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">JavaScript</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{:: policyState.previousPage.name | translate}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-role-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'roles' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-time-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'time' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">{{:: 'authz-authorization' | translate}}</a></li>
|
||||
<li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
|
||||
<li data-ng-show="create && policyState.state.name != null">{{policyState.state.name}}</li>
|
||||
<li data-ng-show="create && policyState.state.name == null">{{policyState.previousPage.name}}</li>
|
||||
<li data-ng-show="create">{{:: 'authz-add-user-policy' | translate}}</li>
|
||||
<li data-ng-hide="create">{{:: 'user' | translate}}</li>
|
||||
<li data-ng-hide="create">{{originalPolicy.name}}</li>
|
||||
|
|
Loading…
Reference in a new issue